Skip to content

Commit

Permalink
Merge branch 'yuji/ibc-masp-recv' (#2631)
Browse files Browse the repository at this point in the history
* origin/yuji/ibc-masp-recv:
  remove ibc-gen-shielded command
  remove duplicated masp tx
  add assert
  not to use memo
  fix e2e test after rebase
  add changelog
  fix for transfer back
  fix e2e test
  fix after rebasing
  fix gen-ibc-shielded
  WIP: add refund_target
  add MsgAcknowledgement and MsgTimeout
  fix store_trace
  add Namada MsgRecvPacket
  • Loading branch information
tzemanovic committed Mar 19, 2024
2 parents c0c9f99 + e00b0b0 commit 23456ba
Show file tree
Hide file tree
Showing 21 changed files with 857 additions and 707 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- IBC shielded transfer with Hermes support
([\#2449](https://github.com/anoma/namada/issues/2449))
2 changes: 1 addition & 1 deletion crates/apps/src/lib/bench_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ impl BenchShell {

let msg = MsgTransfer {
message,
shielded_transfer: None,
transfer: None,
};

self.generate_ibc_tx(TX_IBC_WASM, msg.serialize_to_vec())
Expand Down
46 changes: 18 additions & 28 deletions crates/apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ pub mod cmds {
// Actions
.subcommand(SignTx::def().display_order(6))
.subcommand(ShieldedSync::def().display_order(6))
.subcommand(GenIbcShieldedTransfer::def().display_order(6))
// Utils
.subcommand(Utils::def().display_order(7))
}
Expand Down Expand Up @@ -353,8 +352,6 @@ pub mod cmds {
Self::parse_with_ctx(matches, AddToEthBridgePool);
let sign_tx = Self::parse_with_ctx(matches, SignTx);
let shielded_sync = Self::parse_with_ctx(matches, ShieldedSync);
let gen_ibc_shielded =
Self::parse_with_ctx(matches, GenIbcShieldedTransfer);
let utils = SubCmd::parse(matches).map(Self::WithoutContext);
tx_custom
.or(tx_transfer)
Expand Down Expand Up @@ -407,7 +404,6 @@ pub mod cmds {
.or(query_account)
.or(sign_tx)
.or(shielded_sync)
.or(gen_ibc_shielded)
.or(utils)
}
}
Expand Down Expand Up @@ -496,7 +492,6 @@ pub mod cmds {
QueryRewards(QueryRewards),
SignTx(SignTx),
ShieldedSync(ShieldedSync),
GenIbcShieldedTransfer(GenIbcShieldedTransfer),
}

#[allow(clippy::large_enum_variant)]
Expand Down Expand Up @@ -2167,29 +2162,6 @@ pub mod cmds {
}
}

#[derive(Clone, Debug)]
pub struct GenIbcShieldedTransfer(
pub args::GenIbcShieldedTransfer<args::CliTypes>,
);

impl SubCmd for GenIbcShieldedTransfer {
const CMD: &'static str = "ibc-gen-shielded";

fn parse(matches: &ArgMatches) -> Option<Self> {
matches.subcommand_matches(Self::CMD).map(|matches| {
GenIbcShieldedTransfer(args::GenIbcShieldedTransfer::parse(
matches,
))
})
}

fn def() -> App {
App::new(Self::CMD)
.about("Generate shielded transfer for IBC.")
.add_args::<args::GenIbcShieldedTransfer<args::CliTypes>>()
}
}

#[derive(Clone, Debug)]
pub struct EpochSleep(pub args::Query<args::CliTypes>);

Expand Down Expand Up @@ -3237,6 +3209,9 @@ pub mod args {
pub const RAW_PUBLIC_KEY_HASH_OPT: ArgOpt<String> =
RAW_PUBLIC_KEY_HASH.opt();
pub const RECEIVER: Arg<String> = arg("receiver");
pub const REFUND: ArgFlag = flag("refund");
pub const REFUND_TARGET: ArgOpt<WalletTransferTarget> =
arg_opt("refund-target");
pub const RELAYER: Arg<Address> = arg("relayer");
pub const SAFE_MODE: ArgFlag = flag("safe-mode");
pub const SCHEME: ArgDefault<SchemeType> =
Expand Down Expand Up @@ -4208,6 +4183,7 @@ pub mod args {
channel_id: self.channel_id,
timeout_height: self.timeout_height,
timeout_sec_offset: self.timeout_sec_offset,
refund_target: chain_ctx.get_opt(&self.refund_target),
memo: self.memo,
tx_code_path: self.tx_code_path.to_path_buf(),
}
Expand All @@ -4225,6 +4201,7 @@ pub mod args {
let channel_id = CHANNEL_ID.parse(matches);
let timeout_height = TIMEOUT_HEIGHT.parse(matches);
let timeout_sec_offset = TIMEOUT_SEC_OFFSET.parse(matches);
let refund_target = REFUND_TARGET.parse(matches);
let memo = IBC_TRANSFER_MEMO_PATH.parse(matches).map(|path| {
std::fs::read_to_string(path)
.expect("Expected a file at given path")
Expand All @@ -4240,6 +4217,7 @@ pub mod args {
channel_id,
timeout_height,
timeout_sec_offset,
refund_target,
memo,
tx_code_path,
}
Expand All @@ -4264,6 +4242,10 @@ pub mod args {
.help("The timeout height of the destination chain."),
)
.arg(TIMEOUT_SEC_OFFSET.def().help("The timeout as seconds."))
.arg(REFUND_TARGET.def().help(
"The refund target address when IBC shielded transfer \
failure.",
))
.arg(
IBC_TRANSFER_MEMO_PATH
.def()
Expand Down Expand Up @@ -5941,6 +5923,7 @@ pub mod args {
amount: self.amount,
port_id: self.port_id,
channel_id: self.channel_id,
refund: self.refund,
}
}
}
Expand All @@ -5954,6 +5937,7 @@ pub mod args {
let amount = InputAmount::Unvalidated(AMOUNT.parse(matches));
let port_id = PORT_ID.parse(matches);
let channel_id = CHANNEL_ID.parse(matches);
let refund = REFUND.parse(matches);
Self {
query,
output_folder,
Expand All @@ -5962,6 +5946,7 @@ pub mod args {
amount,
port_id,
channel_id,
refund,
}
}

Expand All @@ -5983,6 +5968,11 @@ pub mod args {
"The channel ID via which the token is received.",
),
)
.arg(
REFUND
.def()
.help("Generate the shielded transfer for refunding."),
)
}
}

Expand Down
14 changes: 0 additions & 14 deletions crates/apps/src/lib/cli/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,20 +742,6 @@ impl CliApi {
let namada = ctx.to_sdk(client, io);
tx::sign_tx(&namada, args).await?;
}
Sub::GenIbcShieldedTransfer(GenIbcShieldedTransfer(
args,
)) => {
let chain_ctx = ctx.borrow_mut_chain_or_exit();
let ledger_address =
chain_ctx.get(&args.query.ledger_address);
let client = client.unwrap_or_else(|| {
C::from_tendermint_address(&ledger_address)
});
client.wait_until_node_is_synced(&io).await?;
let args = args.to_sdk(&mut ctx);
let namada = ctx.to_sdk(client, io);
tx::gen_ibc_shielded_transfer(&namada, args).await?;
}
}
}
cli::NamadaClient::WithoutContext(cmd, global_args) => match cmd {
Expand Down
29 changes: 0 additions & 29 deletions crates/apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::collections::HashSet;
use std::fs::File;
use std::io::Write;

use borsh::BorshDeserialize;
use borsh_ext::BorshSerializeExt;
Expand All @@ -17,7 +16,6 @@ use namada::governance::cli::onchain::{
DefaultProposal, PgfFundingProposal, PgfStewardProposal,
};
use namada::governance::ProposalVote;
use namada::ibc::apps::transfer::types::Memo;
use namada::io::Io;
use namada::state::EPOCH_SWITCH_BLOCKS_DELAY;
use namada::tx::data::pos::{BecomeValidator, ConsensusKeyChange};
Expand Down Expand Up @@ -1612,30 +1610,3 @@ pub async fn submit_tx(
) -> Result<TxResponse, error::Error> {
tx::submit_tx(namada, to_broadcast).await
}

pub async fn gen_ibc_shielded_transfer(
context: &impl Namada,
args: args::GenIbcShieldedTransfer,
) -> Result<(), error::Error> {
if let Some(shielded_transfer) =
tx::gen_ibc_shielded_transfer(context, args.clone()).await?
{
let tx_id = shielded_transfer.masp_tx.txid().to_string();
let filename = format!("ibc_shielded_transfer_{}.memo", tx_id);
let output_path = match &args.output_folder {
Some(path) => path.join(filename),
None => filename.into(),
};
let mut out = File::create(&output_path)
.expect("Should be able to create the out file.");
out.write_all(Memo::from(shielded_transfer).as_ref().as_bytes())
.expect("IBC memo should be deserializable.");
println!(
"Output IBC shielded transfer for {tx_id} to {}",
output_path.to_string_lossy()
);
} else {
eprintln!("No shielded transfer for this IBC transfer.")
}
Ok(())
}
Loading

0 comments on commit 23456ba

Please sign in to comment.