Skip to content

Commit

Permalink
Merge pull request #1878 from CosmWasm/1477-ibc-transfer-memo
Browse files Browse the repository at this point in the history
[2.0] Add memo field to `IbcMsg::Transfer`
  • Loading branch information
chipshort authored Oct 30, 2023
2 parents e7c4ed8 + eb2c9ce commit fde26bd
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ and this project adheres to
`Decimal256`. ([#1902])
- cosmwasm-std: Remove operand strings from `OverflowError`,
`ConversionOverflowError` and `DivideByZeroError`. ([#1896])
- cosmwasm-std: Add optional memo field to `IbcMsg::Transfer`. ([#1878])

[#1874]: https://github.com/CosmWasm/cosmwasm/pull/1874
[#1878]: https://github.com/CosmWasm/cosmwasm/pull/1878
[#1879]: https://github.com/CosmWasm/cosmwasm/pull/1879
[#1890]: https://github.com/CosmWasm/cosmwasm/pull/1890
[#1896]: https://github.com/CosmWasm/cosmwasm/pull/1896
Expand Down
7 changes: 7 additions & 0 deletions contracts/ibc-reflect-send/schema/ibc-reflect-send.json
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,13 @@
"description": "existing channel to send the tokens over",
"type": "string"
},
"memo": {
"description": "optional memo",
"type": [
"string",
"null"
]
},
"timeout": {
"description": "when packet times out, measured on remote chain",
"allOf": [
Expand Down
7 changes: 7 additions & 0 deletions contracts/ibc-reflect-send/schema/ibc/packet_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,13 @@
"description": "existing channel to send the tokens over",
"type": "string"
},
"memo": {
"description": "optional memo",
"type": [
"string",
"null"
]
},
"timeout": {
"description": "when packet times out, measured on remote chain",
"allOf": [
Expand Down
7 changes: 7 additions & 0 deletions contracts/ibc-reflect-send/schema/raw/execute.json
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,13 @@
"description": "existing channel to send the tokens over",
"type": "string"
},
"memo": {
"description": "optional memo",
"type": [
"string",
"null"
]
},
"timeout": {
"description": "when packet times out, measured on remote chain",
"allOf": [
Expand Down
1 change: 1 addition & 0 deletions contracts/ibc-reflect-send/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ pub fn handle_send_funds(
to_address: remote_addr,
amount,
timeout: env.block.time.plus_seconds(PACKET_LIFETIME).into(),
memo: None,
};

let res = Response::new()
Expand Down
2 changes: 2 additions & 0 deletions contracts/ibc-reflect-send/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,14 @@ mod tests {
to_address,
amount,
timeout,
memo,
}) => {
assert_eq!(transfer_channel_id, channel_id.as_str());
assert_eq!(remote_addr, to_address.as_str());
assert_eq!(&coin(12344, "utrgd"), amount);
assert!(timeout.block().is_none());
assert!(timeout.timestamp().is_some());
assert!(memo.is_none());
}
o => panic!("unexpected message: {o:?}"),
}
Expand Down
2 changes: 2 additions & 0 deletions contracts/ibc-reflect-send/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,14 @@ fn send_remote_funds() {
to_address,
amount,
timeout,
memo,
}) => {
assert_eq!(transfer_channel_id, channel_id.as_str());
assert_eq!(remote_addr, to_address.as_str());
assert_eq!(&coin(12344, "utrgd"), amount);
assert!(timeout.block().is_none());
assert!(timeout.timestamp().is_some());
assert!(memo.is_none());
}
o => panic!("unexpected message: {o:?}"),
}
Expand Down
7 changes: 7 additions & 0 deletions contracts/ibc-reflect/schema/ibc/packet_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,13 @@
"description": "existing channel to send the tokens over",
"type": "string"
},
"memo": {
"description": "optional memo",
"type": [
"string",
"null"
]
},
"timeout": {
"description": "when packet times out, measured on remote chain",
"allOf": [
Expand Down
7 changes: 7 additions & 0 deletions contracts/reflect/schema/raw/execute.json
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,13 @@
"description": "existing channel to send the tokens over",
"type": "string"
},
"memo": {
"description": "optional memo",
"type": [
"string",
"null"
]
},
"timeout": {
"description": "when packet times out, measured on remote chain",
"allOf": [
Expand Down
7 changes: 7 additions & 0 deletions contracts/reflect/schema/reflect.json
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,13 @@
"description": "existing channel to send the tokens over",
"type": "string"
},
"memo": {
"description": "optional memo",
"type": [
"string",
"null"
]
},
"timeout": {
"description": "when packet times out, measured on remote chain",
"allOf": [
Expand Down
5 changes: 4 additions & 1 deletion packages/std/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub enum IbcMsg {
amount: Coin,
/// when packet times out, measured on remote chain
timeout: IbcTimeout,
/// optional memo
memo: Option<String>,
},
/// Sends an IBC packet with given data over the existing channel.
/// Data should be encoded in a format defined by the channel version,
Expand Down Expand Up @@ -793,9 +795,10 @@ mod tests {
to_address: "my-special-addr".into(),
amount: Coin::new(12345678u128, "uatom"),
timeout: IbcTimeout::with_timestamp(Timestamp::from_nanos(1234567890)),
memo: None,
};
let encoded = to_string(&msg).unwrap();
let expected = r#"{"transfer":{"channel_id":"channel-123","to_address":"my-special-addr","amount":{"denom":"uatom","amount":"12345678"},"timeout":{"block":null,"timestamp":"1234567890"}}}"#;
let expected = r#"{"transfer":{"channel_id":"channel-123","to_address":"my-special-addr","amount":{"denom":"uatom","amount":"12345678"},"timeout":{"block":null,"timestamp":"1234567890"},"memo":null}}"#;
assert_eq!(encoded.as_str(), expected);
}

Expand Down

0 comments on commit fde26bd

Please sign in to comment.