Skip to content

Commit

Permalink
Add optional memo to ibc transfer (#5)
Browse files Browse the repository at this point in the history
* add option to add memo to ibc transfer

* add with_memo function
  • Loading branch information
keyleu authored Jul 12, 2024
1 parent 3082374 commit 3213555
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/utils/setup/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct TransferTxBuilder<'a> {
recipient: Option<&'a str>,
denom: Option<&'a str>,
amount: Option<u128>,
memo: Option<&'a str>,
port: &'a str,
test_ctx: &'a mut TestContext,
}
Expand Down Expand Up @@ -50,6 +51,12 @@ impl<'a> TransferTxBuilder<'a> {
self
}

pub fn with_memo(&mut self, memo: &'a str) -> &mut Self {
self.memo = Some(memo);

self
}

/// Sends the built IBC transfer tx.
pub fn send(&mut self) -> Result<(), Error> {
self.test_ctx.tx_transfer(
Expand All @@ -62,6 +69,7 @@ impl<'a> TransferTxBuilder<'a> {
self.amount
.ok_or(Error::MissingBuilderParam(String::from("amount")))?,
self.port,
self.memo,
)
}
}
Expand All @@ -75,11 +83,13 @@ impl TestContext {
recipient: Default::default(),
denom: Default::default(),
amount: Default::default(),
memo: None,
port: DEFAULT_TRANSFER_PORT,
test_ctx: self,
}
}

#[allow(clippy::too_many_arguments)]
fn tx_transfer(
&mut self,
key: &str,
Expand All @@ -88,6 +98,7 @@ impl TestContext {
denom: &str,
amount: u128,
port: &str,
memo: Option<&str>,
) -> Result<(), Error> {
let dest_chain: &LocalChain = self
.chains
Expand All @@ -106,7 +117,12 @@ impl TestContext {
chain.chain_name, dest_chain.chain_name
)))?;

let receipt = chain.rb.tx(&format!("tx ibc-transfer transfer {port} {channel} {recipient} {amount}{denom} --fees=100000{fee_denom} --from={key}"), true)?;
let memo_part = memo.map(|m| format!(" --memo={}", m)).unwrap_or_default();

let receipt = chain.rb.tx(&format!(
"tx ibc-transfer transfer {port} {channel} {recipient} {amount}{denom} --fees=100000{fee_denom} --from={key}{}",
memo_part
), true)?;

self.guard_tx_errors(
src_chain_name,
Expand Down

0 comments on commit 3213555

Please sign in to comment.