From e9347993d76c479861f7f12d0bce10b500432ac7 Mon Sep 17 00:00:00 2001 From: Tomasz Kulik Date: Wed, 29 Jan 2025 17:14:48 +0100 Subject: [PATCH] feat: Use Coin instead of Token and remove memo from Frowarding --- .../schema/ibc-reflect-send.json | 53 ++---------- .../schema/ibc/packet_msg.json | 53 ++---------- .../ibc-reflect-send/schema/raw/execute.json | 53 ++---------- .../ibc-reflect/schema/ibc/packet_msg.json | 53 ++---------- contracts/reflect/schema/raw/execute.json | 53 ++---------- contracts/reflect/schema/reflect.json | 53 ++---------- packages/go-gen/tests/cosmwasm_std__IbcMsg.go | 17 +--- packages/std/src/ibc.rs | 41 ++-------- .../std/src/ibc/transfer_msg_builder_v2.rs | 80 ++++++++++++++----- packages/std/src/lib.rs | 12 +-- 10 files changed, 108 insertions(+), 360 deletions(-) diff --git a/contracts/ibc-reflect-send/schema/ibc-reflect-send.json b/contracts/ibc-reflect-send/schema/ibc-reflect-send.json index dc73e8c6c..a8225ac4a 100644 --- a/contracts/ibc-reflect-send/schema/ibc-reflect-send.json +++ b/contracts/ibc-reflect-send/schema/ibc-reflect-send.json @@ -364,25 +364,6 @@ "type": "object", "additionalProperties": false }, - "Forwarding": { - "type": "object", - "required": [ - "hops", - "memo" - ], - "properties": { - "hops": { - "type": "array", - "items": { - "$ref": "#/definitions/Hop" - } - }, - "memo": { - "type": "string" - } - }, - "additionalProperties": false - }, "GovMsg": { "description": "This message type allows the contract interact with the [x/gov] module in order to cast votes.\n\n[x/gov]: https://github.com/cosmos/cosmos-sdk/tree/v0.45.12/x/gov\n\n## Examples\n\nCast a simple vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); use cosmwasm_std::{GovMsg, VoteOption};\n\n#[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { // ... Ok(Response::new().add_message(GovMsg::Vote { proposal_id: 4, option: VoteOption::Yes, })) } ```\n\nCast a weighted vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); # #[cfg(feature = \"cosmwasm_1_2\")] use cosmwasm_std::{Decimal, GovMsg, VoteOption, WeightedVoteOption};\n\n# #[cfg(feature = \"cosmwasm_1_2\")] #[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { // ... Ok(Response::new().add_message(GovMsg::VoteWeighted { proposal_id: 4, options: vec![ WeightedVoteOption { option: VoteOption::Yes, weight: Decimal::percent(65), }, WeightedVoteOption { option: VoteOption::Abstain, weight: Decimal::percent(35), }, ], })) } ```", "oneOf": [ @@ -515,7 +496,10 @@ "type": "string" }, "forwarding": { - "$ref": "#/definitions/Forwarding" + "type": "array", + "items": { + "$ref": "#/definitions/Hop" + } }, "memo": { "description": "An optional memo. See the blog post [\"Moving Beyond Simple Token Transfers\"](https://medium.com/the-interchain-foundation/moving-beyond-simple-token-transfers-d42b2b1dc29b) for more information.\n\nThere is no difference between setting this to `None` or an empty string.\n\nThis field is only supported on chains with CosmWasm >= 2.0 and silently ignored on older chains. If you need support for both 1.x and 2.x chain with the same codebase, it is recommended to use `CosmosMsg::Stargate` with a custom MsgTransfer protobuf encoder instead.", @@ -540,7 +524,7 @@ "description": "packet data only supports one coin https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/ibc/applications/transfer/v1/transfer.proto#L11-L20", "type": "array", "items": { - "$ref": "#/definitions/Token" + "$ref": "#/definitions/Coin" } } }, @@ -753,37 +737,10 @@ } ] }, - "Token": { - "type": "object", - "required": [ - "amount", - "base", - "trace" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint256" - }, - "base": { - "type": "string" - }, - "trace": { - "type": "array", - "items": { - "$ref": "#/definitions/Hop" - } - } - }, - "additionalProperties": false - }, "Uint128": { "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", "type": "string" }, - "Uint256": { - "description": "An implementation of u256 that is using strings for JSON encoding/decoding, such that the full u256 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances out of primitive uint types or `new` to provide big endian bytes:\n\n``` # use cosmwasm_std::Uint256; let a = Uint256::from(258u128); let b = Uint256::new([ 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 2u8, ]); assert_eq!(a, b); ```", - "type": "string" - }, "Uint64": { "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", "type": "string" diff --git a/contracts/ibc-reflect-send/schema/ibc/packet_msg.json b/contracts/ibc-reflect-send/schema/ibc/packet_msg.json index b15aac1e5..94e6dc9af 100644 --- a/contracts/ibc-reflect-send/schema/ibc/packet_msg.json +++ b/contracts/ibc-reflect-send/schema/ibc/packet_msg.json @@ -305,25 +305,6 @@ "type": "object", "additionalProperties": false }, - "Forwarding": { - "type": "object", - "required": [ - "hops", - "memo" - ], - "properties": { - "hops": { - "type": "array", - "items": { - "$ref": "#/definitions/Hop" - } - }, - "memo": { - "type": "string" - } - }, - "additionalProperties": false - }, "GovMsg": { "description": "This message type allows the contract interact with the [x/gov] module in order to cast votes.\n\n[x/gov]: https://github.com/cosmos/cosmos-sdk/tree/v0.45.12/x/gov\n\n## Examples\n\nCast a simple vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); use cosmwasm_std::{GovMsg, VoteOption};\n\n#[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { // ... Ok(Response::new().add_message(GovMsg::Vote { proposal_id: 4, option: VoteOption::Yes, })) } ```\n\nCast a weighted vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); # #[cfg(feature = \"cosmwasm_1_2\")] use cosmwasm_std::{Decimal, GovMsg, VoteOption, WeightedVoteOption};\n\n# #[cfg(feature = \"cosmwasm_1_2\")] #[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { // ... Ok(Response::new().add_message(GovMsg::VoteWeighted { proposal_id: 4, options: vec![ WeightedVoteOption { option: VoteOption::Yes, weight: Decimal::percent(65), }, WeightedVoteOption { option: VoteOption::Abstain, weight: Decimal::percent(35), }, ], })) } ```", "oneOf": [ @@ -456,7 +437,10 @@ "type": "string" }, "forwarding": { - "$ref": "#/definitions/Forwarding" + "type": "array", + "items": { + "$ref": "#/definitions/Hop" + } }, "memo": { "description": "An optional memo. See the blog post [\"Moving Beyond Simple Token Transfers\"](https://medium.com/the-interchain-foundation/moving-beyond-simple-token-transfers-d42b2b1dc29b) for more information.\n\nThere is no difference between setting this to `None` or an empty string.\n\nThis field is only supported on chains with CosmWasm >= 2.0 and silently ignored on older chains. If you need support for both 1.x and 2.x chain with the same codebase, it is recommended to use `CosmosMsg::Stargate` with a custom MsgTransfer protobuf encoder instead.", @@ -481,7 +465,7 @@ "description": "packet data only supports one coin https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/ibc/applications/transfer/v1/transfer.proto#L11-L20", "type": "array", "items": { - "$ref": "#/definitions/Token" + "$ref": "#/definitions/Coin" } } }, @@ -694,37 +678,10 @@ } ] }, - "Token": { - "type": "object", - "required": [ - "amount", - "base", - "trace" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint256" - }, - "base": { - "type": "string" - }, - "trace": { - "type": "array", - "items": { - "$ref": "#/definitions/Hop" - } - } - }, - "additionalProperties": false - }, "Uint128": { "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", "type": "string" }, - "Uint256": { - "description": "An implementation of u256 that is using strings for JSON encoding/decoding, such that the full u256 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances out of primitive uint types or `new` to provide big endian bytes:\n\n``` # use cosmwasm_std::Uint256; let a = Uint256::from(258u128); let b = Uint256::new([ 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 2u8, ]); assert_eq!(a, b); ```", - "type": "string" - }, "Uint64": { "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", "type": "string" diff --git a/contracts/ibc-reflect-send/schema/raw/execute.json b/contracts/ibc-reflect-send/schema/raw/execute.json index 6ab2b5dca..2a3229e83 100644 --- a/contracts/ibc-reflect-send/schema/raw/execute.json +++ b/contracts/ibc-reflect-send/schema/raw/execute.json @@ -353,25 +353,6 @@ "type": "object", "additionalProperties": false }, - "Forwarding": { - "type": "object", - "required": [ - "hops", - "memo" - ], - "properties": { - "hops": { - "type": "array", - "items": { - "$ref": "#/definitions/Hop" - } - }, - "memo": { - "type": "string" - } - }, - "additionalProperties": false - }, "GovMsg": { "description": "This message type allows the contract interact with the [x/gov] module in order to cast votes.\n\n[x/gov]: https://github.com/cosmos/cosmos-sdk/tree/v0.45.12/x/gov\n\n## Examples\n\nCast a simple vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); use cosmwasm_std::{GovMsg, VoteOption};\n\n#[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { // ... Ok(Response::new().add_message(GovMsg::Vote { proposal_id: 4, option: VoteOption::Yes, })) } ```\n\nCast a weighted vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); # #[cfg(feature = \"cosmwasm_1_2\")] use cosmwasm_std::{Decimal, GovMsg, VoteOption, WeightedVoteOption};\n\n# #[cfg(feature = \"cosmwasm_1_2\")] #[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { // ... Ok(Response::new().add_message(GovMsg::VoteWeighted { proposal_id: 4, options: vec![ WeightedVoteOption { option: VoteOption::Yes, weight: Decimal::percent(65), }, WeightedVoteOption { option: VoteOption::Abstain, weight: Decimal::percent(35), }, ], })) } ```", "oneOf": [ @@ -504,7 +485,10 @@ "type": "string" }, "forwarding": { - "$ref": "#/definitions/Forwarding" + "type": "array", + "items": { + "$ref": "#/definitions/Hop" + } }, "memo": { "description": "An optional memo. See the blog post [\"Moving Beyond Simple Token Transfers\"](https://medium.com/the-interchain-foundation/moving-beyond-simple-token-transfers-d42b2b1dc29b) for more information.\n\nThere is no difference between setting this to `None` or an empty string.\n\nThis field is only supported on chains with CosmWasm >= 2.0 and silently ignored on older chains. If you need support for both 1.x and 2.x chain with the same codebase, it is recommended to use `CosmosMsg::Stargate` with a custom MsgTransfer protobuf encoder instead.", @@ -529,7 +513,7 @@ "description": "packet data only supports one coin https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/ibc/applications/transfer/v1/transfer.proto#L11-L20", "type": "array", "items": { - "$ref": "#/definitions/Token" + "$ref": "#/definitions/Coin" } } }, @@ -742,37 +726,10 @@ } ] }, - "Token": { - "type": "object", - "required": [ - "amount", - "base", - "trace" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint256" - }, - "base": { - "type": "string" - }, - "trace": { - "type": "array", - "items": { - "$ref": "#/definitions/Hop" - } - } - }, - "additionalProperties": false - }, "Uint128": { "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", "type": "string" }, - "Uint256": { - "description": "An implementation of u256 that is using strings for JSON encoding/decoding, such that the full u256 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances out of primitive uint types or `new` to provide big endian bytes:\n\n``` # use cosmwasm_std::Uint256; let a = Uint256::from(258u128); let b = Uint256::new([ 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 2u8, ]); assert_eq!(a, b); ```", - "type": "string" - }, "Uint64": { "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", "type": "string" diff --git a/contracts/ibc-reflect/schema/ibc/packet_msg.json b/contracts/ibc-reflect/schema/ibc/packet_msg.json index 4904853bc..30d897889 100644 --- a/contracts/ibc-reflect/schema/ibc/packet_msg.json +++ b/contracts/ibc-reflect/schema/ibc/packet_msg.json @@ -334,25 +334,6 @@ "type": "object", "additionalProperties": false }, - "Forwarding": { - "type": "object", - "required": [ - "hops", - "memo" - ], - "properties": { - "hops": { - "type": "array", - "items": { - "$ref": "#/definitions/Hop" - } - }, - "memo": { - "type": "string" - } - }, - "additionalProperties": false - }, "GovMsg": { "description": "This message type allows the contract interact with the [x/gov] module in order to cast votes.\n\n[x/gov]: https://github.com/cosmos/cosmos-sdk/tree/v0.45.12/x/gov\n\n## Examples\n\nCast a simple vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); use cosmwasm_std::{GovMsg, VoteOption};\n\n#[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { // ... Ok(Response::new().add_message(GovMsg::Vote { proposal_id: 4, option: VoteOption::Yes, })) } ```\n\nCast a weighted vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); # #[cfg(feature = \"cosmwasm_1_2\")] use cosmwasm_std::{Decimal, GovMsg, VoteOption, WeightedVoteOption};\n\n# #[cfg(feature = \"cosmwasm_1_2\")] #[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { // ... Ok(Response::new().add_message(GovMsg::VoteWeighted { proposal_id: 4, options: vec![ WeightedVoteOption { option: VoteOption::Yes, weight: Decimal::percent(65), }, WeightedVoteOption { option: VoteOption::Abstain, weight: Decimal::percent(35), }, ], })) } ```", "oneOf": [ @@ -557,7 +538,10 @@ "type": "string" }, "forwarding": { - "$ref": "#/definitions/Forwarding" + "type": "array", + "items": { + "$ref": "#/definitions/Hop" + } }, "memo": { "description": "An optional memo. See the blog post [\"Moving Beyond Simple Token Transfers\"](https://medium.com/the-interchain-foundation/moving-beyond-simple-token-transfers-d42b2b1dc29b) for more information.\n\nThere is no difference between setting this to `None` or an empty string.\n\nThis field is only supported on chains with CosmWasm >= 2.0 and silently ignored on older chains. If you need support for both 1.x and 2.x chain with the same codebase, it is recommended to use `CosmosMsg::Stargate` with a custom MsgTransfer protobuf encoder instead.", @@ -582,7 +566,7 @@ "description": "packet data only supports one coin https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/ibc/applications/transfer/v1/transfer.proto#L11-L20", "type": "array", "items": { - "$ref": "#/definitions/Token" + "$ref": "#/definitions/Coin" } } }, @@ -834,37 +818,10 @@ } ] }, - "Token": { - "type": "object", - "required": [ - "amount", - "base", - "trace" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint256" - }, - "base": { - "type": "string" - }, - "trace": { - "type": "array", - "items": { - "$ref": "#/definitions/Hop" - } - } - }, - "additionalProperties": false - }, "Uint128": { "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", "type": "string" }, - "Uint256": { - "description": "An implementation of u256 that is using strings for JSON encoding/decoding, such that the full u256 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances out of primitive uint types or `new` to provide big endian bytes:\n\n``` # use cosmwasm_std::Uint256; let a = Uint256::from(258u128); let b = Uint256::new([ 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 2u8, ]); assert_eq!(a, b); ```", - "type": "string" - }, "Uint64": { "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", "type": "string" diff --git a/contracts/reflect/schema/raw/execute.json b/contracts/reflect/schema/raw/execute.json index 6ae73952c..115bb8fea 100644 --- a/contracts/reflect/schema/raw/execute.json +++ b/contracts/reflect/schema/raw/execute.json @@ -407,25 +407,6 @@ } ] }, - "Forwarding": { - "type": "object", - "required": [ - "hops", - "memo" - ], - "properties": { - "hops": { - "type": "array", - "items": { - "$ref": "#/definitions/Hop" - } - }, - "memo": { - "type": "string" - } - }, - "additionalProperties": false - }, "GovMsg": { "description": "This message type allows the contract interact with the [x/gov] module in order to cast votes.\n\n[x/gov]: https://github.com/cosmos/cosmos-sdk/tree/v0.45.12/x/gov\n\n## Examples\n\nCast a simple vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); use cosmwasm_std::{GovMsg, VoteOption};\n\n#[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { // ... Ok(Response::new().add_message(GovMsg::Vote { proposal_id: 4, option: VoteOption::Yes, })) } ```\n\nCast a weighted vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); # #[cfg(feature = \"cosmwasm_1_2\")] use cosmwasm_std::{Decimal, GovMsg, VoteOption, WeightedVoteOption};\n\n# #[cfg(feature = \"cosmwasm_1_2\")] #[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { // ... Ok(Response::new().add_message(GovMsg::VoteWeighted { proposal_id: 4, options: vec![ WeightedVoteOption { option: VoteOption::Yes, weight: Decimal::percent(65), }, WeightedVoteOption { option: VoteOption::Abstain, weight: Decimal::percent(35), }, ], })) } ```", "oneOf": [ @@ -630,7 +611,10 @@ "type": "string" }, "forwarding": { - "$ref": "#/definitions/Forwarding" + "type": "array", + "items": { + "$ref": "#/definitions/Hop" + } }, "memo": { "description": "An optional memo. See the blog post [\"Moving Beyond Simple Token Transfers\"](https://medium.com/the-interchain-foundation/moving-beyond-simple-token-transfers-d42b2b1dc29b) for more information.\n\nThere is no difference between setting this to `None` or an empty string.\n\nThis field is only supported on chains with CosmWasm >= 2.0 and silently ignored on older chains. If you need support for both 1.x and 2.x chain with the same codebase, it is recommended to use `CosmosMsg::Stargate` with a custom MsgTransfer protobuf encoder instead.", @@ -655,7 +639,7 @@ "description": "packet data only supports one coin https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/ibc/applications/transfer/v1/transfer.proto#L11-L20", "type": "array", "items": { - "$ref": "#/definitions/Token" + "$ref": "#/definitions/Coin" } } }, @@ -1069,37 +1053,10 @@ } ] }, - "Token": { - "type": "object", - "required": [ - "amount", - "base", - "trace" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint256" - }, - "base": { - "type": "string" - }, - "trace": { - "type": "array", - "items": { - "$ref": "#/definitions/Hop" - } - } - }, - "additionalProperties": false - }, "Uint128": { "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", "type": "string" }, - "Uint256": { - "description": "An implementation of u256 that is using strings for JSON encoding/decoding, such that the full u256 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances out of primitive uint types or `new` to provide big endian bytes:\n\n``` # use cosmwasm_std::Uint256; let a = Uint256::from(258u128); let b = Uint256::new([ 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 2u8, ]); assert_eq!(a, b); ```", - "type": "string" - }, "Uint64": { "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", "type": "string" diff --git a/contracts/reflect/schema/reflect.json b/contracts/reflect/schema/reflect.json index 7757de875..d61ce0c14 100644 --- a/contracts/reflect/schema/reflect.json +++ b/contracts/reflect/schema/reflect.json @@ -417,25 +417,6 @@ } ] }, - "Forwarding": { - "type": "object", - "required": [ - "hops", - "memo" - ], - "properties": { - "hops": { - "type": "array", - "items": { - "$ref": "#/definitions/Hop" - } - }, - "memo": { - "type": "string" - } - }, - "additionalProperties": false - }, "GovMsg": { "description": "This message type allows the contract interact with the [x/gov] module in order to cast votes.\n\n[x/gov]: https://github.com/cosmos/cosmos-sdk/tree/v0.45.12/x/gov\n\n## Examples\n\nCast a simple vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); use cosmwasm_std::{GovMsg, VoteOption};\n\n#[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { // ... Ok(Response::new().add_message(GovMsg::Vote { proposal_id: 4, option: VoteOption::Yes, })) } ```\n\nCast a weighted vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); # #[cfg(feature = \"cosmwasm_1_2\")] use cosmwasm_std::{Decimal, GovMsg, VoteOption, WeightedVoteOption};\n\n# #[cfg(feature = \"cosmwasm_1_2\")] #[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { // ... Ok(Response::new().add_message(GovMsg::VoteWeighted { proposal_id: 4, options: vec![ WeightedVoteOption { option: VoteOption::Yes, weight: Decimal::percent(65), }, WeightedVoteOption { option: VoteOption::Abstain, weight: Decimal::percent(35), }, ], })) } ```", "oneOf": [ @@ -640,7 +621,10 @@ "type": "string" }, "forwarding": { - "$ref": "#/definitions/Forwarding" + "type": "array", + "items": { + "$ref": "#/definitions/Hop" + } }, "memo": { "description": "An optional memo. See the blog post [\"Moving Beyond Simple Token Transfers\"](https://medium.com/the-interchain-foundation/moving-beyond-simple-token-transfers-d42b2b1dc29b) for more information.\n\nThere is no difference between setting this to `None` or an empty string.\n\nThis field is only supported on chains with CosmWasm >= 2.0 and silently ignored on older chains. If you need support for both 1.x and 2.x chain with the same codebase, it is recommended to use `CosmosMsg::Stargate` with a custom MsgTransfer protobuf encoder instead.", @@ -665,7 +649,7 @@ "description": "packet data only supports one coin https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/ibc/applications/transfer/v1/transfer.proto#L11-L20", "type": "array", "items": { - "$ref": "#/definitions/Token" + "$ref": "#/definitions/Coin" } } }, @@ -1079,37 +1063,10 @@ } ] }, - "Token": { - "type": "object", - "required": [ - "amount", - "base", - "trace" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint256" - }, - "base": { - "type": "string" - }, - "trace": { - "type": "array", - "items": { - "$ref": "#/definitions/Hop" - } - } - }, - "additionalProperties": false - }, "Uint128": { "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", "type": "string" }, - "Uint256": { - "description": "An implementation of u256 that is using strings for JSON encoding/decoding, such that the full u256 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances out of primitive uint types or `new` to provide big endian bytes:\n\n``` # use cosmwasm_std::Uint256; let a = Uint256::from(258u128); let b = Uint256::new([ 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 2u8, ]); assert_eq!(a, b); ```", - "type": "string" - }, "Uint64": { "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", "type": "string" diff --git a/packages/go-gen/tests/cosmwasm_std__IbcMsg.go b/packages/go-gen/tests/cosmwasm_std__IbcMsg.go index 798517071..61078f79a 100644 --- a/packages/go-gen/tests/cosmwasm_std__IbcMsg.go +++ b/packages/go-gen/tests/cosmwasm_std__IbcMsg.go @@ -17,7 +17,7 @@ type TransferMsg struct { type TransferV2Msg struct { // existing channel to send the tokens over ChannelID string `json:"channel_id"` - Forwarding Forwarding `json:"forwarding"` + Forwarding Array[Hop] `json:"forwarding"` // An optional memo. See the blog post ["Moving Beyond Simple Token Transfers"](https://medium.com/the-interchain-foundation/moving-beyond-simple-token-transfers-d42b2b1dc29b) for more information. // // There is no difference between setting this to `None` or an empty string. @@ -29,7 +29,7 @@ type TransferV2Msg struct { // address on the remote chain to receive these tokens ToAddress string `json:"to_address"` // packet data only supports one coin https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/ibc/applications/transfer/v1/transfer.proto#L11-L20 - Tokens Array[Token] `json:"tokens"` + Tokens Array[Coin] `json:"tokens"` } type SendPacketMsg struct { ChannelID string `json:"channel_id"` @@ -73,7 +73,7 @@ type PayPacketFeeAsyncMsg struct { Sequence uint64 `json:"sequence"` } -// These are messages in the IBC lifecycle. Only usable by IBC-enabled contracts (contracts that directly speak the IBC protocol via 7 entry points) +// These are messages in the IBC lifecycle. Only usable by IBC-enabled contracts (contracts that directly speak the IBC protocol via 6 entry points) type IBCMsg struct { // Sends bank tokens owned by the contract to the given address on another chain. The channel must already be established between the ibctransfer module on this chain and a matching module on the remote chain. We cannot select the port_id, this is whatever the local chain has bound the ibctransfer module to. Transfer *TransferMsg `json:"transfer,omitempty"` @@ -104,10 +104,6 @@ type Coin struct { Amount string `json:"amount"` Denom string `json:"denom"` } -type Forwarding struct { - Hops Array[Hop] `json:"hops"` - Memo string `json:"memo"` -} type Hop struct { ChannelID string `json:"channel_id"` PortID string `json:"port_id"` @@ -133,9 +129,4 @@ type IBCTimeoutBlock struct { Height uint64 `json:"height"` // the version that the client is currently on (e.g. after resetting the chain this could increment 1 as height drops to 0) Revision uint64 `json:"revision"` -} -type Token struct { - Amount string `json:"amount"` - Base string `json:"base"` - Trace Array[Hop] `json:"trace"` -} +} \ No newline at end of file diff --git a/packages/std/src/ibc.rs b/packages/std/src/ibc.rs index bac2caca5..2c6ff1575 100644 --- a/packages/std/src/ibc.rs +++ b/packages/std/src/ibc.rs @@ -7,9 +7,9 @@ use serde::{Deserialize, Serialize}; use std::vec; use crate::coin::Coin; +use crate::prelude::*; use crate::results::{Attribute, CosmosMsg, Empty, Event, SubMsg}; use crate::StdResult; -use crate::{prelude::*, Uint256}; use crate::{to_json_binary, Binary}; use crate::{Addr, Timestamp}; @@ -21,39 +21,12 @@ pub use callbacks::*; pub use transfer_msg_builder::*; pub use transfer_msg_builder_v2::*; -#[non_exhaustive] -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub struct Token { - base: String, - trace: Vec, - amount: Uint256, -} - -impl From for Token { - fn from(w: Coin) -> Token { - Token { - base: w.denom, - trace: vec![], - amount: w.amount.into(), - } - } -} - -#[non_exhaustive] -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, Default)] -#[serde(rename_all = "snake_case")] -pub struct Forwarding { - hops: Vec, - memo: String, -} - #[non_exhaustive] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] #[serde(rename_all = "snake_case")] pub struct Hop { - port_id: String, - channel_id: String, + pub port_id: String, + pub channel_id: String, } /// These are messages in the IBC lifecycle. Only usable by IBC-enabled contracts @@ -100,9 +73,8 @@ pub enum IbcMsg { channel_id: String, /// address on the remote chain to receive these tokens to_address: String, - /// packet data only supports one coin - /// https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/ibc/applications/transfer/v1/transfer.proto#L11-L20 - tokens: Vec, + /// MsgTransfer in v2 version supports multiple coins + tokens: Vec, /// when packet times out, measured on remote chain timeout: IbcTimeout, /// An optional memo. See the blog post @@ -119,8 +91,7 @@ pub enum IbcMsg { memo: Option, // a struct containing the list of next hops, // determining where the tokens must be forwarded next, - // and the memo for the final hop - forwarding: Forwarding, + forwarding: Vec, }, /// Sends an IBC packet with given data over the existing channel. /// Data should be encoded in a format defined by the channel version, diff --git a/packages/std/src/ibc/transfer_msg_builder_v2.rs b/packages/std/src/ibc/transfer_msg_builder_v2.rs index 0202ab2db..9a1a2888b 100644 --- a/packages/std/src/ibc/transfer_msg_builder_v2.rs +++ b/packages/std/src/ibc/transfer_msg_builder_v2.rs @@ -1,8 +1,7 @@ -use crate::{IbcDstCallback, IbcMsg, IbcSrcCallback, IbcTimeout}; +use crate::{Coin, IbcDstCallback, IbcMsg, IbcSrcCallback, IbcTimeout}; use super::{ - EmptyMemo, Forwarding, MemoSource, Token, WithCallbacks, WithDstCallback, WithMemo, - WithSrcCallback, + EmptyMemo, Hop, MemoSource, WithCallbacks, WithDstCallback, WithMemo, WithSrcCallback, }; impl TransferMsgBuilderV2 { @@ -22,10 +21,20 @@ impl TransferMsgBuilderV2 { pub struct TransferMsgBuilderV2 { channel_id: String, to_address: String, - tokens: Vec, + tokens: Vec, timeout: IbcTimeout, memo: MemoData, - forwarding: Forwarding, + forwarding: Vec, +} + +#[derive(Clone, Debug, PartialEq, Eq)] +#[non_exhaustive] +pub struct WithForwarding; + +impl MemoSource for WithForwarding { + fn into_memo(self) -> Option { + None + } } impl TransferMsgBuilderV2 { @@ -33,7 +42,7 @@ impl TransferMsgBuilderV2 { pub fn new( channel_id: impl Into, to_address: impl Into, - tokens: Vec, + tokens: Vec, timeout: impl Into, ) -> Self { Self { @@ -42,7 +51,7 @@ impl TransferMsgBuilderV2 { tokens, timeout: timeout.into(), memo: EmptyMemo, - forwarding: Forwarding::default(), + forwarding: vec![], } } @@ -93,6 +102,21 @@ impl TransferMsgBuilderV2 { forwarding: self.forwarding, } } + + /// Adds forwarding data. + /// It is worth to notice that the builder does not allow to add forwarding data along with + /// callbacks. It is discouraged in the IBC docs: + /// https://github.com/cosmos/ibc-go/blob/main/docs/docs/04-middleware/02-callbacks/01-overview.md#known-limitations + pub fn with_forwarding(self, forwarding: Vec) -> TransferMsgBuilderV2 { + TransferMsgBuilderV2 { + channel_id: self.channel_id, + to_address: self.to_address, + tokens: self.tokens, + timeout: self.timeout, + memo: WithForwarding, + forwarding, + } + } } impl TransferMsgBuilderV2 { @@ -161,10 +185,16 @@ mod tests { let empty_memo_builder = TransferMsgBuilderV2::new( "channel-0", "cosmos1example", - vec![coin(10, "ucoin").into()], + vec![coin(10, "ucoin")], Timestamp::from_seconds(12345), ); + let forwarding = empty_memo_builder.clone().with_forwarding(vec![Hop { + port_id: "portid".to_owned(), + channel_id: "chnid".to_owned(), + }]); + let forwarding = forwarding.build(); + let empty = empty_memo_builder.clone().build(); let with_memo = empty_memo_builder.clone().with_memo("memo").build(); @@ -191,10 +221,24 @@ mod tests { IbcMsg::TransferV2 { channel_id: "channel-0".to_string(), to_address: "cosmos1example".to_string(), - tokens: vec![coin(10, "ucoin").into()], + tokens: vec![coin(10, "ucoin")], + timeout: Timestamp::from_seconds(12345).into(), + memo: None, + forwarding: vec![] + } + ); + assert_eq!( + forwarding, + IbcMsg::TransferV2 { + channel_id: "channel-0".to_string(), + to_address: "cosmos1example".to_string(), + tokens: vec![coin(10, "ucoin")], timeout: Timestamp::from_seconds(12345).into(), memo: None, - forwarding: Forwarding::default() + forwarding: vec![Hop { + port_id: "portid".to_owned(), + channel_id: "chnid".to_owned() + }] } ); assert_eq!( @@ -202,10 +246,10 @@ mod tests { IbcMsg::TransferV2 { channel_id: "channel-0".to_string(), to_address: "cosmos1example".to_string(), - tokens: vec![coin(10, "ucoin").into()], + tokens: vec![coin(10, "ucoin")], timeout: Timestamp::from_seconds(12345).into(), memo: Some("memo".to_string()), - forwarding: Forwarding::default() + forwarding: vec![] } ); assert_eq!( @@ -213,12 +257,12 @@ mod tests { IbcMsg::TransferV2 { channel_id: "channel-0".to_string(), to_address: "cosmos1example".to_string(), - tokens: vec![coin(10, "ucoin").into()], + tokens: vec![coin(10, "ucoin")], timeout: Timestamp::from_seconds(12345).into(), memo: Some( to_json_string(&IbcCallbackRequest::source(src_callback.clone())).unwrap() ), - forwarding: Forwarding::default() + forwarding: vec![] } ); assert_eq!( @@ -226,12 +270,12 @@ mod tests { IbcMsg::TransferV2 { channel_id: "channel-0".to_string(), to_address: "cosmos1example".to_string(), - tokens: vec![coin(10, "ucoin").into()], + tokens: vec![coin(10, "ucoin")], timeout: Timestamp::from_seconds(12345).into(), memo: Some( to_json_string(&IbcCallbackRequest::destination(dst_callback.clone())).unwrap() ), - forwarding: Forwarding::default() + forwarding: vec![] } ); assert_eq!( @@ -239,12 +283,12 @@ mod tests { IbcMsg::TransferV2 { channel_id: "channel-0".to_string(), to_address: "cosmos1example".to_string(), - tokens: vec![coin(10, "ucoin").into()], + tokens: vec![coin(10, "ucoin")], timeout: Timestamp::from_seconds(12345).into(), memo: Some( to_json_string(&IbcCallbackRequest::both(src_callback, dst_callback)).unwrap() ), - forwarding: Forwarding::default(), + forwarding: vec![], } ); assert_eq!(with_both_callbacks1, with_both_callbacks2); diff --git a/packages/std/src/lib.rs b/packages/std/src/lib.rs index 6c96b4acd..fbb2566dc 100644 --- a/packages/std/src/lib.rs +++ b/packages/std/src/lib.rs @@ -70,12 +70,12 @@ pub use crate::eureka::{EurekaMsg, EurekaPayload}; pub use crate::hex_binary::HexBinary; pub use crate::ibc::IbcChannelOpenResponse; pub use crate::ibc::{ - Forwarding, Hop, Ibc3ChannelOpenResponse, IbcAckCallbackMsg, IbcAcknowledgement, - IbcBasicResponse, IbcCallbackRequest, IbcChannel, IbcChannelCloseMsg, IbcChannelConnectMsg, - IbcChannelOpenMsg, IbcDestinationCallbackMsg, IbcDstCallback, IbcEndpoint, IbcFee, IbcMsg, - IbcOrder, IbcPacket, IbcPacketAckMsg, IbcPacketReceiveMsg, IbcPacketTimeoutMsg, - IbcReceiveResponse, IbcSourceCallbackMsg, IbcSrcCallback, IbcTimeout, IbcTimeoutBlock, - IbcTimeoutCallbackMsg, Token, TransferMsgBuilder, TransferMsgBuilderV2, + Hop, Ibc3ChannelOpenResponse, IbcAckCallbackMsg, IbcAcknowledgement, IbcBasicResponse, + IbcCallbackRequest, IbcChannel, IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg, + IbcDestinationCallbackMsg, IbcDstCallback, IbcEndpoint, IbcFee, IbcMsg, IbcOrder, IbcPacket, + IbcPacketAckMsg, IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse, + IbcSourceCallbackMsg, IbcSrcCallback, IbcTimeout, IbcTimeoutBlock, IbcTimeoutCallbackMsg, + TransferMsgBuilder, TransferMsgBuilderV2, }; #[cfg(feature = "iterator")] pub use crate::iterator::{Order, Record};