diff --git a/packages/sdk/src/tx/tx.ts b/packages/sdk/src/tx/tx.ts index 1e613cc86..afbb4b6c9 100644 --- a/packages/sdk/src/tx/tx.ts +++ b/packages/sdk/src/tx/tx.ts @@ -455,6 +455,8 @@ export class Tx { return deserialize(data, TransferMsgValue); case TxType.RevealPK: return deserialize(data, RevealPkMsgValue); + case TxType.IBCTransfer: + return deserialize(data, IbcTransferMsgValue); default: throw "Unsupported Tx type!"; } diff --git a/packages/shared/lib/src/query.rs b/packages/shared/lib/src/query.rs index ffdfad379..8fa1e4625 100644 --- a/packages/shared/lib/src/query.rs +++ b/packages/shared/lib/src/query.rs @@ -33,7 +33,7 @@ use namada_sdk::state::Key; use namada_sdk::token; use namada_sdk::tx::{ TX_BOND_WASM, TX_CLAIM_REWARDS_WASM, TX_REDELEGATE_WASM, TX_REVEAL_PK, TX_TRANSFER_WASM, - TX_UNBOND_WASM, TX_VOTE_PROPOSAL, TX_WITHDRAW_WASM, + TX_UNBOND_WASM, TX_VOTE_PROPOSAL, TX_WITHDRAW_WASM, TX_IBC_WASM, }; use namada_sdk::uint::I256; use namada_sdk::wallet::DatedKeypair; @@ -720,6 +720,7 @@ impl Query { TX_CLAIM_REWARDS_WASM.to_string(), TX_REVEAL_PK.to_string(), TX_VOTE_PROPOSAL.to_string(), + TX_IBC_WASM.to_string(), ] } diff --git a/packages/shared/lib/src/sdk/args.rs b/packages/shared/lib/src/sdk/args.rs index 306770ea7..a30d4757b 100644 --- a/packages/shared/lib/src/sdk/args.rs +++ b/packages/shared/lib/src/sdk/args.rs @@ -716,6 +716,34 @@ pub struct IbcTransferMsg { shielding_data: Option>, } +impl IbcTransferMsg { + pub fn new( + source: String, + receiver: String, + token: String, + amount: String, + port_id: String, + channel_id: String, + timeout_height: Option, + timeout_sec_offset: Option, + memo: Option, + shielding_data: Option>, + ) -> IbcTransferMsg { + IbcTransferMsg { + source, + receiver, + token, + amount, + port_id, + channel_id, + timeout_height, + timeout_sec_offset, + memo, + shielding_data, + } + } +} + /// Maps serialized tx_msg into IbcTransferTx args. /// /// # Arguments diff --git a/packages/shared/lib/src/sdk/transaction.rs b/packages/shared/lib/src/sdk/transaction.rs index 6036bf158..e233dc893 100644 --- a/packages/shared/lib/src/sdk/transaction.rs +++ b/packages/shared/lib/src/sdk/transaction.rs @@ -1,6 +1,5 @@ use namada_sdk::borsh::BorshSerializeExt; use namada_sdk::token::Transfer; -use serde::Serialize; use namada_sdk::governance::VoteProposalData; use namada_sdk::tx::data::pos::{Bond, ClaimRewards, Redelegation, Unbond, Withdraw}; @@ -8,18 +7,19 @@ use namada_sdk::{ borsh::{self, BorshDeserialize}, key::common::PublicKey, }; +use namada_sdk::ibc::MsgTransfer; +use namada_sdk::ibc::core::channel::types::timeout::TimeoutHeight; use wasm_bindgen::JsError; use crate::sdk::{ args::{ BondMsg, ClaimRewardsMsg, RedelegateMsg, RevealPkMsg, TransferDataMsg, TransferMsg, - UnbondMsg, VoteProposalMsg, WithdrawMsg, + UnbondMsg, VoteProposalMsg, WithdrawMsg, IbcTransferMsg }, tx::TxType, }; -#[derive(Serialize, Debug, Clone)] -#[serde(untagged)] +#[derive(Debug, Clone)] pub enum TransactionKind { Transfer(Transfer), Bond(Bond), @@ -29,6 +29,7 @@ pub enum TransactionKind { ProposalVote(VoteProposalData), ClaimRewards(ClaimRewards), RevealPk(PublicKey), + IbcTransfer(MsgTransfer), Unknown, } @@ -59,6 +60,9 @@ impl TransactionKind { TxType::RevealPK => TransactionKind::RevealPk( PublicKey::try_from_slice(data).expect("Cannot deserialize PublicKey"), ), + TxType::IBCTransfer => TransactionKind::IbcTransfer( + MsgTransfer::try_from_slice(data).expect("Cannot deserialize MsgTransfer"), + ), _ => TransactionKind::Unknown, } } @@ -181,6 +185,28 @@ impl TransactionKind { ); borsh::to_vec(&claim_rewards)? } + TransactionKind::IbcTransfer(msg_transfer) => { + let MsgTransfer { message, .. } = msg_transfer; + + let timeout_height = match message.timeout_height_on_b { + TimeoutHeight::At(height) => Some(height.revision_height()), + TimeoutHeight::Never => None + }; + + let ibc_transfer_msg = IbcTransferMsg::new( + message.packet_data.sender.to_string(), + message.packet_data.receiver.to_string(), + message.packet_data.token.denom.base_denom.to_string(), + message.packet_data.token.amount.to_string(), + message.port_id_on_a.to_string(), + message.chan_id_on_a.to_string(), + timeout_height, + None, + Some(message.packet_data.memo.to_string()), + None + ); + borsh::to_vec(&ibc_transfer_msg)? + }, _ => panic!("Unsupported Tx provided, cannot serialize"), }; diff --git a/packages/shared/lib/src/sdk/tx.rs b/packages/shared/lib/src/sdk/tx.rs index c83f2c0d8..ed4da8508 100644 --- a/packages/shared/lib/src/sdk/tx.rs +++ b/packages/shared/lib/src/sdk/tx.rs @@ -8,7 +8,7 @@ use namada_sdk::tx::data::compute_inner_tx_hash; use namada_sdk::tx::either::Either; use namada_sdk::tx::{ self, TX_BOND_WASM, TX_CLAIM_REWARDS_WASM, TX_REDELEGATE_WASM, TX_REVEAL_PK, TX_TRANSFER_WASM, - TX_UNBOND_WASM, TX_VOTE_PROPOSAL, TX_WITHDRAW_WASM, + TX_UNBOND_WASM, TX_VOTE_PROPOSAL, TX_WITHDRAW_WASM, TX_IBC_WASM, }; use namada_sdk::uint::Uint; use namada_sdk::{address::Address, key::common::PublicKey}; @@ -183,6 +183,7 @@ pub fn wasm_hash_to_tx_type(wasm_hash: &str, wasm_hashes: &Vec) -> Opt (TX_CLAIM_REWARDS_WASM.to_string(), TxType::ClaimRewards), (TX_REVEAL_PK.to_string(), TxType::RevealPK), (TX_VOTE_PROPOSAL.to_string(), TxType::VoteProposal), + (TX_IBC_WASM.to_string(), TxType::IBCTransfer), ]); for wh in wasm_hashes {