Skip to content

Commit

Permalink
feat(ucs01-relay): support memo extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
PoisonPhang authored and aeryz committed Jun 5, 2024
1 parent 8d10452 commit 95cc231
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
15 changes: 12 additions & 3 deletions cosmwasm/ucs01-relay-api/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub struct Ucs01TransferPacket {
receiver: HexBinary,
/// the transferred tokens
tokens: Vec<TransferToken>,
pub memo: String,
}

impl Ucs01TransferPacket {
Expand All @@ -68,11 +69,17 @@ impl Ucs01TransferPacket {
&self.tokens
}

pub fn new(sender: HexBinary, receiver: HexBinary, tokens: Vec<TransferToken>) -> Self {
pub fn new(
sender: HexBinary,
receiver: HexBinary,
tokens: Vec<TransferToken>,
memo: String,
) -> Self {
Self {
sender,
receiver,
tokens,
memo,
}
}
}
Expand Down Expand Up @@ -143,6 +150,7 @@ impl TryFrom<Binary> for Ucs01TransferPacket {
}
})
.collect(),
memo: String::new(),
})
}
_ => unreachable!(),
Expand Down Expand Up @@ -206,7 +214,7 @@ impl From<NoExtension> for String {
}

impl TransferPacket for Ucs01TransferPacket {
type Extension = NoExtension;
type Extension = String;
type Addr = HexBinary;

fn tokens(&self) -> Vec<TransferToken> {
Expand All @@ -222,7 +230,7 @@ impl TransferPacket for Ucs01TransferPacket {
}

fn extension(&self) -> &Self::Extension {
&NoExtension
&self.memo
}
}

Expand Down Expand Up @@ -408,6 +416,7 @@ mod tests {
amount: Uint128::from(1337u32),
},
],
memo: String::new(),
};
assert_eq!(
packet,
Expand Down
4 changes: 2 additions & 2 deletions cosmwasm/ucs01-relay/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use cw2::set_contract_version;
use token_factory_api::TokenFactoryMsg;
use ucs01_relay_api::{
protocol::{TransferInput, TransferProtocol},
types::{NoExtension, TransferToken},
types::TransferToken,
};

use crate::{
Expand Down Expand Up @@ -154,7 +154,7 @@ pub fn execute_transfer(
channel: channel_info,
},
}
.send(input, NoExtension),
.send(input, msg.memo),
v => Err(ContractError::UnknownProtocol {
channel_id: msg.channel,
protocol_version: v.into(),
Expand Down
1 change: 1 addition & 0 deletions cosmwasm/ucs01-relay/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ impl<'a> TransferProtocol for Ucs01Protocol<'a> {
}
})?,
packet.tokens,
packet.extension,
))
}

Expand Down

0 comments on commit 95cc231

Please sign in to comment.