diff --git a/packages/cosmos/src/messages.rs b/packages/cosmos/src/messages.rs index c2d3d9b..27f812a 100644 --- a/packages/cosmos/src/messages.rs +++ b/packages/cosmos/src/messages.rs @@ -199,16 +199,56 @@ impl From for TxMessage { impl From for TxMessage { fn from(msg: MsgSend) -> Self { - TxMessage::new( - "/cosmos.bank.v1beta1.MsgSend", - msg.encode_to_vec(), - format!( - "{} sending {} to {}", + // Very hacky approach to sending the alternative MsgSend + // on THORChain. For simplicity, we simply look for an appropriate + // HRP prefix on the destination address. + if msg.to_address.starts_with("sthor1") { + #[derive(::prost::Message)] + struct ThorMsgSend { + /// Source of funds + #[prost(bytes, tag = "1")] + from_address: Vec, + /// Destination of funds + #[prost(bytes, tag = "2")] + to_address: Vec, + /// Funds to be sent + #[prost(message, repeated, tag = "3")] + amount: ::prost::alloc::vec::Vec, + } + let description = format!( + "{} sending (via THORChain message) {} to {}", msg.from_address, PrettyCoins(msg.amount.as_slice()), msg.to_address, - ), - ) + ); + fn get_acc_address(s: &str) -> Vec { + // This code will panic if an invalid address is provided. + // We could fix that, but given how corner a case this is, + // I'm not interested in changing the overall API to accommodate + // it. + bech32::decode(s) + .expect("Invalid THORChain address provided for MsgSend") + .1 + } + let thormsg = ThorMsgSend { + from_address: get_acc_address(&msg.from_address), + to_address: get_acc_address(&msg.to_address), + amount: msg.amount, + }; + + TxMessage::new("/types.MsgSend", thormsg.encode_to_vec(), description) + } else { + TxMessage::new( + "/cosmos.bank.v1beta1.MsgSend", + msg.encode_to_vec(), + format!( + "{} sending {} to {}", + msg.from_address, + PrettyCoins(msg.amount.as_slice()), + msg.to_address, + ), + ) + } } }