From b1fdf5819684414049951719d83357de72c7d43f Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Mon, 18 Sep 2023 11:51:38 +0200 Subject: [PATCH 1/6] Add memo field to IbcMsg::Transfer --- contracts/ibc-reflect-send/src/contract.rs | 1 + contracts/ibc-reflect-send/src/ibc.rs | 2 ++ contracts/ibc-reflect-send/tests/integration.rs | 2 ++ packages/std/src/ibc.rs | 5 ++++- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/contracts/ibc-reflect-send/src/contract.rs b/contracts/ibc-reflect-send/src/contract.rs index 23adc82b89..05170533bf 100644 --- a/contracts/ibc-reflect-send/src/contract.rs +++ b/contracts/ibc-reflect-send/src/contract.rs @@ -157,6 +157,7 @@ pub fn handle_send_funds( to_address: remote_addr, amount, timeout: env.block.time.plus_seconds(PACKET_LIFETIME).into(), + memo: String::new(), }; let res = Response::new() diff --git a/contracts/ibc-reflect-send/src/ibc.rs b/contracts/ibc-reflect-send/src/ibc.rs index 6faabd5c10..c9f16a4f06 100644 --- a/contracts/ibc-reflect-send/src/ibc.rs +++ b/contracts/ibc-reflect-send/src/ibc.rs @@ -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_eq!(memo, ""); } o => panic!("unexpected message: {o:?}"), } diff --git a/contracts/ibc-reflect-send/tests/integration.rs b/contracts/ibc-reflect-send/tests/integration.rs index 21d5c95352..2b608c13a2 100644 --- a/contracts/ibc-reflect-send/tests/integration.rs +++ b/contracts/ibc-reflect-send/tests/integration.rs @@ -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_eq!(memo, ""); } o => panic!("unexpected message: {o:?}"), } diff --git a/packages/std/src/ibc.rs b/packages/std/src/ibc.rs index 1a732f3e55..9bf4773cc9 100644 --- a/packages/std/src/ibc.rs +++ b/packages/std/src/ibc.rs @@ -35,6 +35,8 @@ pub enum IbcMsg { amount: Coin, /// when packet times out, measured on remote chain timeout: IbcTimeout, + /// optional memo + memo: String, }, /// Sends an IBC packet with given data over the existing channel. /// Data should be encoded in a format defined by the channel version, @@ -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: String::new(), }; 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":""}}"#; assert_eq!(encoded.as_str(), expected); } From a89ba94ebbd12779372110769d0b7fc28ad8ef31 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Mon, 18 Sep 2023 12:23:23 +0200 Subject: [PATCH 2/6] Fix schema --- contracts/ibc-reflect-send/schema/ibc-reflect-send.json | 5 +++++ contracts/ibc-reflect-send/schema/ibc/packet_msg.json | 5 +++++ contracts/ibc-reflect-send/schema/raw/execute.json | 5 +++++ contracts/ibc-reflect/schema/ibc/packet_msg.json | 5 +++++ contracts/reflect/schema/raw/execute.json | 5 +++++ contracts/reflect/schema/reflect.json | 5 +++++ 6 files changed, 30 insertions(+) diff --git a/contracts/ibc-reflect-send/schema/ibc-reflect-send.json b/contracts/ibc-reflect-send/schema/ibc-reflect-send.json index cf36088129..f6a6288237 100644 --- a/contracts/ibc-reflect-send/schema/ibc-reflect-send.json +++ b/contracts/ibc-reflect-send/schema/ibc-reflect-send.json @@ -408,6 +408,7 @@ "required": [ "amount", "channel_id", + "memo", "timeout", "to_address" ], @@ -424,6 +425,10 @@ "description": "existing channel to send the tokens over", "type": "string" }, + "memo": { + "description": "optional memo", + "type": "string" + }, "timeout": { "description": "when packet times out, measured on remote chain", "allOf": [ diff --git a/contracts/ibc-reflect-send/schema/ibc/packet_msg.json b/contracts/ibc-reflect-send/schema/ibc/packet_msg.json index 00bcd35219..0fa40b1575 100644 --- a/contracts/ibc-reflect-send/schema/ibc/packet_msg.json +++ b/contracts/ibc-reflect-send/schema/ibc/packet_msg.json @@ -346,6 +346,7 @@ "required": [ "amount", "channel_id", + "memo", "timeout", "to_address" ], @@ -362,6 +363,10 @@ "description": "existing channel to send the tokens over", "type": "string" }, + "memo": { + "description": "optional memo", + "type": "string" + }, "timeout": { "description": "when packet times out, measured on remote chain", "allOf": [ diff --git a/contracts/ibc-reflect-send/schema/raw/execute.json b/contracts/ibc-reflect-send/schema/raw/execute.json index 5fee9b17a4..e1174c25d4 100644 --- a/contracts/ibc-reflect-send/schema/raw/execute.json +++ b/contracts/ibc-reflect-send/schema/raw/execute.json @@ -397,6 +397,7 @@ "required": [ "amount", "channel_id", + "memo", "timeout", "to_address" ], @@ -413,6 +414,10 @@ "description": "existing channel to send the tokens over", "type": "string" }, + "memo": { + "description": "optional memo", + "type": "string" + }, "timeout": { "description": "when packet times out, measured on remote chain", "allOf": [ diff --git a/contracts/ibc-reflect/schema/ibc/packet_msg.json b/contracts/ibc-reflect/schema/ibc/packet_msg.json index 3b9ebaef68..2de97e0651 100644 --- a/contracts/ibc-reflect/schema/ibc/packet_msg.json +++ b/contracts/ibc-reflect/schema/ibc/packet_msg.json @@ -333,6 +333,7 @@ "required": [ "amount", "channel_id", + "memo", "timeout", "to_address" ], @@ -349,6 +350,10 @@ "description": "existing channel to send the tokens over", "type": "string" }, + "memo": { + "description": "optional memo", + "type": "string" + }, "timeout": { "description": "when packet times out, measured on remote chain", "allOf": [ diff --git a/contracts/reflect/schema/raw/execute.json b/contracts/reflect/schema/raw/execute.json index 4180145986..550cf03f6e 100644 --- a/contracts/reflect/schema/raw/execute.json +++ b/contracts/reflect/schema/raw/execute.json @@ -451,6 +451,7 @@ "required": [ "amount", "channel_id", + "memo", "timeout", "to_address" ], @@ -467,6 +468,10 @@ "description": "existing channel to send the tokens over", "type": "string" }, + "memo": { + "description": "optional memo", + "type": "string" + }, "timeout": { "description": "when packet times out, measured on remote chain", "allOf": [ diff --git a/contracts/reflect/schema/reflect.json b/contracts/reflect/schema/reflect.json index 641d7498d7..59a960801d 100644 --- a/contracts/reflect/schema/reflect.json +++ b/contracts/reflect/schema/reflect.json @@ -461,6 +461,7 @@ "required": [ "amount", "channel_id", + "memo", "timeout", "to_address" ], @@ -477,6 +478,10 @@ "description": "existing channel to send the tokens over", "type": "string" }, + "memo": { + "description": "optional memo", + "type": "string" + }, "timeout": { "description": "when packet times out, measured on remote chain", "allOf": [ From 94544859bcbb444526f2c2727e1600eda0c80c76 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Tue, 17 Oct 2023 12:27:40 +0200 Subject: [PATCH 3/6] Use Option for memo field --- contracts/ibc-reflect-send/schema/ibc-reflect-send.json | 6 ++++-- contracts/ibc-reflect-send/schema/ibc/packet_msg.json | 6 ++++-- contracts/ibc-reflect-send/schema/raw/execute.json | 6 ++++-- contracts/ibc-reflect-send/src/contract.rs | 2 +- contracts/ibc-reflect-send/src/ibc.rs | 2 +- contracts/ibc-reflect-send/tests/integration.rs | 2 +- contracts/ibc-reflect/schema/ibc/packet_msg.json | 6 ++++-- contracts/reflect/schema/raw/execute.json | 6 ++++-- contracts/reflect/schema/reflect.json | 6 ++++-- packages/std/src/ibc.rs | 7 ++++--- 10 files changed, 31 insertions(+), 18 deletions(-) diff --git a/contracts/ibc-reflect-send/schema/ibc-reflect-send.json b/contracts/ibc-reflect-send/schema/ibc-reflect-send.json index f6a6288237..f863c79d43 100644 --- a/contracts/ibc-reflect-send/schema/ibc-reflect-send.json +++ b/contracts/ibc-reflect-send/schema/ibc-reflect-send.json @@ -408,7 +408,6 @@ "required": [ "amount", "channel_id", - "memo", "timeout", "to_address" ], @@ -427,7 +426,10 @@ }, "memo": { "description": "optional memo", - "type": "string" + "type": [ + "string", + "null" + ] }, "timeout": { "description": "when packet times out, measured on remote chain", diff --git a/contracts/ibc-reflect-send/schema/ibc/packet_msg.json b/contracts/ibc-reflect-send/schema/ibc/packet_msg.json index 0fa40b1575..f8f8640a5c 100644 --- a/contracts/ibc-reflect-send/schema/ibc/packet_msg.json +++ b/contracts/ibc-reflect-send/schema/ibc/packet_msg.json @@ -346,7 +346,6 @@ "required": [ "amount", "channel_id", - "memo", "timeout", "to_address" ], @@ -365,7 +364,10 @@ }, "memo": { "description": "optional memo", - "type": "string" + "type": [ + "string", + "null" + ] }, "timeout": { "description": "when packet times out, measured on remote chain", diff --git a/contracts/ibc-reflect-send/schema/raw/execute.json b/contracts/ibc-reflect-send/schema/raw/execute.json index e1174c25d4..1765e73a74 100644 --- a/contracts/ibc-reflect-send/schema/raw/execute.json +++ b/contracts/ibc-reflect-send/schema/raw/execute.json @@ -397,7 +397,6 @@ "required": [ "amount", "channel_id", - "memo", "timeout", "to_address" ], @@ -416,7 +415,10 @@ }, "memo": { "description": "optional memo", - "type": "string" + "type": [ + "string", + "null" + ] }, "timeout": { "description": "when packet times out, measured on remote chain", diff --git a/contracts/ibc-reflect-send/src/contract.rs b/contracts/ibc-reflect-send/src/contract.rs index 05170533bf..d3a2bfe441 100644 --- a/contracts/ibc-reflect-send/src/contract.rs +++ b/contracts/ibc-reflect-send/src/contract.rs @@ -157,7 +157,7 @@ pub fn handle_send_funds( to_address: remote_addr, amount, timeout: env.block.time.plus_seconds(PACKET_LIFETIME).into(), - memo: String::new(), + memo: None, }; let res = Response::new() diff --git a/contracts/ibc-reflect-send/src/ibc.rs b/contracts/ibc-reflect-send/src/ibc.rs index c9f16a4f06..511a7b1518 100644 --- a/contracts/ibc-reflect-send/src/ibc.rs +++ b/contracts/ibc-reflect-send/src/ibc.rs @@ -417,7 +417,7 @@ mod tests { assert_eq!(&coin(12344, "utrgd"), amount); assert!(timeout.block().is_none()); assert!(timeout.timestamp().is_some()); - assert_eq!(memo, ""); + assert!(memo.is_none()); } o => panic!("unexpected message: {o:?}"), } diff --git a/contracts/ibc-reflect-send/tests/integration.rs b/contracts/ibc-reflect-send/tests/integration.rs index 2b608c13a2..ea8a70f8d2 100644 --- a/contracts/ibc-reflect-send/tests/integration.rs +++ b/contracts/ibc-reflect-send/tests/integration.rs @@ -241,7 +241,7 @@ fn send_remote_funds() { assert_eq!(&coin(12344, "utrgd"), amount); assert!(timeout.block().is_none()); assert!(timeout.timestamp().is_some()); - assert_eq!(memo, ""); + assert!(memo.is_none()); } o => panic!("unexpected message: {o:?}"), } diff --git a/contracts/ibc-reflect/schema/ibc/packet_msg.json b/contracts/ibc-reflect/schema/ibc/packet_msg.json index 2de97e0651..6856f57368 100644 --- a/contracts/ibc-reflect/schema/ibc/packet_msg.json +++ b/contracts/ibc-reflect/schema/ibc/packet_msg.json @@ -333,7 +333,6 @@ "required": [ "amount", "channel_id", - "memo", "timeout", "to_address" ], @@ -352,7 +351,10 @@ }, "memo": { "description": "optional memo", - "type": "string" + "type": [ + "string", + "null" + ] }, "timeout": { "description": "when packet times out, measured on remote chain", diff --git a/contracts/reflect/schema/raw/execute.json b/contracts/reflect/schema/raw/execute.json index 550cf03f6e..abd024e972 100644 --- a/contracts/reflect/schema/raw/execute.json +++ b/contracts/reflect/schema/raw/execute.json @@ -451,7 +451,6 @@ "required": [ "amount", "channel_id", - "memo", "timeout", "to_address" ], @@ -470,7 +469,10 @@ }, "memo": { "description": "optional memo", - "type": "string" + "type": [ + "string", + "null" + ] }, "timeout": { "description": "when packet times out, measured on remote chain", diff --git a/contracts/reflect/schema/reflect.json b/contracts/reflect/schema/reflect.json index 59a960801d..21b899f174 100644 --- a/contracts/reflect/schema/reflect.json +++ b/contracts/reflect/schema/reflect.json @@ -461,7 +461,6 @@ "required": [ "amount", "channel_id", - "memo", "timeout", "to_address" ], @@ -480,7 +479,10 @@ }, "memo": { "description": "optional memo", - "type": "string" + "type": [ + "string", + "null" + ] }, "timeout": { "description": "when packet times out, measured on remote chain", diff --git a/packages/std/src/ibc.rs b/packages/std/src/ibc.rs index 9bf4773cc9..1c3eb16454 100644 --- a/packages/std/src/ibc.rs +++ b/packages/std/src/ibc.rs @@ -36,7 +36,8 @@ pub enum IbcMsg { /// when packet times out, measured on remote chain timeout: IbcTimeout, /// optional memo - memo: String, + #[serde(skip_serializing_if = "Option::is_none")] + memo: Option, }, /// Sends an IBC packet with given data over the existing channel. /// Data should be encoded in a format defined by the channel version, @@ -795,10 +796,10 @@ mod tests { to_address: "my-special-addr".into(), amount: Coin::new(12345678u128, "uatom"), timeout: IbcTimeout::with_timestamp(Timestamp::from_nanos(1234567890)), - memo: String::new(), + 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"},"memo":""}}"#; + let expected = r#"{"transfer":{"channel_id":"channel-123","to_address":"my-special-addr","amount":{"denom":"uatom","amount":"12345678"},"timeout":{"block":null,"timestamp":"1234567890"}}}"#; assert_eq!(encoded.as_str(), expected); } From dfdba5b3c020c18573aad5e4c7f9be69491ad121 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Tue, 17 Oct 2023 16:10:08 +0200 Subject: [PATCH 4/6] Remove serde skip annotation --- packages/std/src/ibc.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/std/src/ibc.rs b/packages/std/src/ibc.rs index 1c3eb16454..70b9f91da0 100644 --- a/packages/std/src/ibc.rs +++ b/packages/std/src/ibc.rs @@ -36,7 +36,6 @@ pub enum IbcMsg { /// when packet times out, measured on remote chain timeout: IbcTimeout, /// optional memo - #[serde(skip_serializing_if = "Option::is_none")] memo: Option, }, /// Sends an IBC packet with given data over the existing channel. From a7b9bbaa47beeee1c5b47c98babe5154273de3a0 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Tue, 17 Oct 2023 16:25:43 +0200 Subject: [PATCH 5/6] Fix test --- packages/std/src/ibc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/std/src/ibc.rs b/packages/std/src/ibc.rs index 70b9f91da0..17c60ae87f 100644 --- a/packages/std/src/ibc.rs +++ b/packages/std/src/ibc.rs @@ -798,7 +798,7 @@ mod tests { 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); } From eb2c9cefbd6dbbf38f6c36c17da8cde239cada77 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Mon, 30 Oct 2023 10:35:17 +0100 Subject: [PATCH 6/6] Add changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70d3b93570..b03f1a2c07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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