Skip to content

Commit

Permalink
Set MsgTransfer as an enum for ICS20 v1 and v2
Browse files Browse the repository at this point in the history
  • Loading branch information
ljoss17 committed Aug 22, 2024
1 parent f68c5e8 commit 8ac128e
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 61 deletions.
28 changes: 26 additions & 2 deletions crates/relayer-cli/src/commands/fee/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use eyre::eyre;

use ibc_relayer::{
chain::handle::ChainHandle,
channel::version::Version,
config::Config,
transfer::{build_transfer_messages, send_messages, TransferOptions},
};
Expand Down Expand Up @@ -61,6 +62,14 @@ pub struct FeeTransferCmd {
)]
src_channel_id: ChannelId,

#[clap(
long = "ics20-version",
default_value = "1",
value_name = "ICS20_VERSION",
help = "ICS20 version of the channel. Defaults to 1"
)]
ics20_version: u64,

#[clap(
long = "amount",
required = true,
Expand Down Expand Up @@ -192,6 +201,7 @@ impl FeeTransferCmd {
dst_chain_id: self.dst_chain_id.clone(),
src_port_id: self.src_port_id.clone(),
src_channel_id: self.src_channel_id.clone(),
ics20_version: self.ics20_version,
amount: self.amount,
denom,
receiver: self.recipient.clone(),
Expand Down Expand Up @@ -230,6 +240,7 @@ pub struct FeeTransferOptions {
pub dst_chain_id: ChainId,
pub src_port_id: PortId,
pub src_channel_id: ChannelId,
pub ics20_version: u64,
pub amount: Amount,
pub denom: String,
pub receiver: Option<String>,
Expand All @@ -244,11 +255,12 @@ pub struct FeeTransferOptions {

impl From<FeeTransferOptions> for TransferOptions {
fn from(f: FeeTransferOptions) -> Self {
let tokens = vec![(f.amount, f.denom)];
TransferOptions {
src_port_id: f.src_port_id,
src_channel_id: f.src_channel_id,
amount: f.amount,
denom: f.denom,
channel_version: Version::ics20(f.ics20_version), // TODO: Can only create transfer on ICS20 channel
tokens,
receiver: f.receiver,
timeout_height_offset: f.timeout_height_offset,
timeout_duration: f.timeout_duration,
Expand Down Expand Up @@ -321,6 +333,7 @@ mod tests {
src_chain_id: ChainId::from_string("chain_a"),
src_port_id: PortId::from_str("port_a").unwrap(),
src_channel_id: ChannelId::from_str("channel_a").unwrap(),
ics20_version: 1,
amount: Amount::from(1000u64),
denom: "samoleans".to_owned(),
recipient: None,
Expand Down Expand Up @@ -357,6 +370,7 @@ mod tests {
src_chain_id: ChainId::from_string("chain_a"),
src_port_id: PortId::from_str("port_a").unwrap(),
src_channel_id: ChannelId::from_str("channel_a").unwrap(),
ics20_version: 1,
amount: Amount::from(1000u64),
denom: "samoleans".to_owned(),
recipient: None,
Expand Down Expand Up @@ -393,6 +407,7 @@ mod tests {
src_chain_id: ChainId::from_string("chain_a"),
src_port_id: PortId::from_str("port_a").unwrap(),
src_channel_id: ChannelId::from_str("channel_a").unwrap(),
ics20_version: 1,
amount: Amount::from(1000u64),
denom: "stake".to_owned(),
recipient: None,
Expand Down Expand Up @@ -431,6 +446,7 @@ mod tests {
src_chain_id: ChainId::from_string("chain_a"),
src_port_id: PortId::from_str("port_a").unwrap(),
src_channel_id: ChannelId::from_str("channel_a").unwrap(),
ics20_version: 1,
amount: Amount::from(1000u64),
denom: "samoleans".to_owned(),
recipient: Some("other_recipient".to_owned()),
Expand Down Expand Up @@ -469,6 +485,7 @@ mod tests {
src_chain_id: ChainId::from_string("chain_a"),
src_port_id: PortId::from_str("port_a").unwrap(),
src_channel_id: ChannelId::from_str("channel_a").unwrap(),
ics20_version: 1,
amount: Amount::from(1000u64),
denom: "samoleans".to_owned(),
recipient: None,
Expand Down Expand Up @@ -507,6 +524,7 @@ mod tests {
src_chain_id: ChainId::from_string("chain_a"),
src_port_id: PortId::from_str("port_a").unwrap(),
src_channel_id: ChannelId::from_str("channel_a").unwrap(),
ics20_version: 1,
amount: Amount::from(1000u64),
denom: "samoleans".to_owned(),
recipient: None,
Expand Down Expand Up @@ -545,6 +563,7 @@ mod tests {
src_chain_id: ChainId::from_string("chain_a"),
src_port_id: PortId::from_str("port_a").unwrap(),
src_channel_id: ChannelId::from_str("channel_a").unwrap(),
ics20_version: 1,
amount: Amount::from(1000u64),
denom: "samoleans".to_owned(),
recipient: None,
Expand Down Expand Up @@ -583,6 +602,7 @@ mod tests {
src_chain_id: ChainId::from_string("chain_a"),
src_port_id: PortId::from_str("port_a").unwrap(),
src_channel_id: ChannelId::from_str("channel_a").unwrap(),
ics20_version: 1,
amount: Amount::from(1000u64),
denom: "samoleans".to_owned(),
recipient: None,
Expand Down Expand Up @@ -621,6 +641,7 @@ mod tests {
src_chain_id: ChainId::from_string("chain_a"),
src_port_id: PortId::from_str("port_a").unwrap(),
src_channel_id: ChannelId::from_str("channel_a").unwrap(),
ics20_version: 1,
amount: Amount::from(1000u64),
denom: "samoleans".to_owned(),
recipient: None,
Expand Down Expand Up @@ -658,6 +679,7 @@ mod tests {
src_chain_id: ChainId::from_string("chain_a"),
src_port_id: PortId::from_str("port_a").unwrap(),
src_channel_id: ChannelId::from_str("channel_a").unwrap(),
ics20_version: 1,
amount: Amount::from(1000u64),
denom: "samoleans".to_owned(),
recipient: None,
Expand Down Expand Up @@ -696,6 +718,7 @@ mod tests {
src_chain_id: ChainId::from_string("chain_a"),
src_port_id: PortId::from_str("port_a").unwrap(),
src_channel_id: ChannelId::from_str("channel_a").unwrap(),
ics20_version: 1,
amount: Amount::from(1000u64),
denom: "samoleans".to_owned(),
recipient: None,
Expand Down Expand Up @@ -734,6 +757,7 @@ mod tests {
src_chain_id: ChainId::from_string("chain_a"),
src_port_id: PortId::from_str("port_a").unwrap(),
src_channel_id: ChannelId::from_str("channel_a").unwrap(),
ics20_version: 1,
amount: Amount::from(1000u64),
denom: "samoleans".to_owned(),
recipient: None,
Expand Down
23 changes: 21 additions & 2 deletions crates/relayer-cli/src/commands/tx/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use abscissa_core::clap::Parser;
use abscissa_core::{config::Override, FrameworkErrorKind};
use eyre::eyre;

use ibc_relayer::channel::version::Version;
use ibc_relayer::{
chain::handle::ChainHandle,
config::Config,
Expand Down Expand Up @@ -59,6 +60,14 @@ pub struct TxIcs20MsgTransferCmd {
)]
src_channel_id: ChannelId,

#[clap(
long = "ics20-version",
default_value = "1",
value_name = "ICS20_VERSION",
help = "ICS20 version of the channel. Defaults to 1"
)]
ics20_version: u64,

#[clap(
long = "amount",
required = true,
Expand Down Expand Up @@ -161,11 +170,12 @@ impl TxIcs20MsgTransferCmd {
return Err(eyre!("number of messages should be greater than zero"));
}

let tokens = vec![(self.amount, denom)];
let opts = TransferOptions {
src_port_id: self.src_port_id.clone(),
src_channel_id: self.src_channel_id.clone(),
amount: self.amount,
denom,
channel_version: Version::ics20(self.ics20_version), // TODO: Can only create transfer on ICS20 channel
tokens,
receiver: self.receiver.clone(),
timeout_height_offset: self.timeout_height_offset,
timeout_duration: Duration::from_secs(self.timeout_seconds),
Expand Down Expand Up @@ -229,6 +239,7 @@ mod tests {
src_chain_id: ChainId::from_string("chain_sender"),
src_port_id: PortId::from_str("port_sender").unwrap(),
src_channel_id: ChannelId::from_str("channel_sender").unwrap(),
ics20_version: 1,
amount: Amount::from(42u64),
timeout_height_offset: 0,
timeout_seconds: 0,
Expand Down Expand Up @@ -262,6 +273,7 @@ mod tests {
src_chain_id: ChainId::from_string("chain_sender"),
src_port_id: PortId::from_str("port_sender").unwrap(),
src_channel_id: ChannelId::from_str("channel_sender").unwrap(),
ics20_version: 1,
amount: Amount::from(42u64),
timeout_height_offset: 0,
timeout_seconds: 0,
Expand Down Expand Up @@ -295,6 +307,7 @@ mod tests {
src_chain_id: ChainId::from_string("chain_sender"),
src_port_id: PortId::from_str("port_sender").unwrap(),
src_channel_id: ChannelId::from_str("channel_sender").unwrap(),
ics20_version: 1,
amount: Amount::from(42u64),
timeout_height_offset: 0,
timeout_seconds: 0,
Expand Down Expand Up @@ -330,6 +343,7 @@ mod tests {
src_chain_id: ChainId::from_string("chain_sender"),
src_port_id: PortId::from_str("port_sender").unwrap(),
src_channel_id: ChannelId::from_str("channel_sender").unwrap(),
ics20_version: 1,
amount: Amount::from(42u64),
timeout_height_offset: 0,
timeout_seconds: 0,
Expand Down Expand Up @@ -365,6 +379,7 @@ mod tests {
src_chain_id: ChainId::from_string("chain_sender"),
src_port_id: PortId::from_str("port_sender").unwrap(),
src_channel_id: ChannelId::from_str("channel_sender").unwrap(),
ics20_version: 1,
amount: Amount::from(42u64),
timeout_height_offset: 0,
timeout_seconds: 0,
Expand Down Expand Up @@ -400,6 +415,7 @@ mod tests {
src_chain_id: ChainId::from_string("chain_sender"),
src_port_id: PortId::from_str("port_sender").unwrap(),
src_channel_id: ChannelId::from_str("channel_sender").unwrap(),
ics20_version: 1,
amount: Amount::from(42u64),
timeout_height_offset: 0,
timeout_seconds: 0,
Expand Down Expand Up @@ -435,6 +451,7 @@ mod tests {
src_chain_id: ChainId::from_string("chain_sender"),
src_port_id: PortId::from_str("port_sender").unwrap(),
src_channel_id: ChannelId::from_str("channel_sender").unwrap(),
ics20_version: 1,
amount: Amount::from(42u64),
timeout_height_offset: 21,
timeout_seconds: 0,
Expand Down Expand Up @@ -470,6 +487,7 @@ mod tests {
src_chain_id: ChainId::from_string("chain_sender"),
src_port_id: PortId::from_str("port_sender").unwrap(),
src_channel_id: ChannelId::from_str("channel_sender").unwrap(),
ics20_version: 1,
amount: Amount::from(42u64),
timeout_height_offset: 0,
timeout_seconds: 21,
Expand Down Expand Up @@ -505,6 +523,7 @@ mod tests {
src_chain_id: ChainId::from_string("chain_sender"),
src_port_id: PortId::from_str("port_sender").unwrap(),
src_channel_id: ChannelId::from_str("channel_sender").unwrap(),
ics20_version: 1,
amount: Amount::from(42u64),
timeout_height_offset: 0,
timeout_seconds: 0,
Expand Down
Loading

0 comments on commit 8ac128e

Please sign in to comment.