From 3c26a3d77c4f5e717f9cb33f191af3f1a2031f1a Mon Sep 17 00:00:00 2001 From: Tomasz Kurcz Date: Tue, 8 Nov 2022 16:10:14 +0100 Subject: [PATCH 1/5] Add `cosmwasm_1_2 feature` --- packages/std/Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/std/Cargo.toml b/packages/std/Cargo.toml index 0c792c491e..ee6d84597a 100644 --- a/packages/std/Cargo.toml +++ b/packages/std/Cargo.toml @@ -36,6 +36,9 @@ ibc3 = ["stargate"] # This feature makes `BankQuery::Supply` available for the contract to call, but requires # the host blockchain to run CosmWasm `1.1.0` or higher. cosmwasm_1_1 = [] +# This feature makes `GovMsg::VoteWeighted` available for the contract to call, but requires +# the host blockchain to run CosmWasm `1.2.0` or higher. +cosmwasm_1_2 = [] [dependencies] base64 = "0.13.0" From 869072e6e8f8fdd277c7d5708d68ed626457da37 Mon Sep 17 00:00:00 2001 From: Tomasz Kurcz Date: Tue, 8 Nov 2022 16:41:27 +0100 Subject: [PATCH 2/5] Add `GovMsg::VoteWeighted` --- packages/std/src/lib.rs | 2 ++ packages/std/src/results/cosmos_msg.rs | 15 +++++++++++++++ packages/std/src/results/mod.rs | 2 ++ 3 files changed, 19 insertions(+) diff --git a/packages/std/src/lib.rs b/packages/std/src/lib.rs index 1f37bed1d6..26445f4b55 100644 --- a/packages/std/src/lib.rs +++ b/packages/std/src/lib.rs @@ -63,6 +63,8 @@ pub use crate::query::{ pub use crate::query::{ChannelResponse, IbcQuery, ListChannelsResponse, PortIdResponse}; #[allow(deprecated)] pub use crate::results::SubMsgExecutionResponse; +#[cfg(all(feature = "stargate", feature = "cosmwasm_1_2"))] +pub use crate::results::WeightedVoteOption; pub use crate::results::{ attr, wasm_execute, wasm_instantiate, Attribute, BankMsg, ContractResult, CosmosMsg, CustomMsg, Empty, Event, QueryResponse, Reply, ReplyOn, Response, SubMsg, SubMsgResponse, SubMsgResult, diff --git a/packages/std/src/results/cosmos_msg.rs b/packages/std/src/results/cosmos_msg.rs index d72f98ddda..2761ac280b 100644 --- a/packages/std/src/results/cosmos_msg.rs +++ b/packages/std/src/results/cosmos_msg.rs @@ -9,6 +9,8 @@ use crate::errors::StdResult; #[cfg(feature = "stargate")] use crate::ibc::IbcMsg; use crate::serde::to_binary; +#[cfg(all(feature = "stargate", feature = "cosmwasm_1_2"))] +use crate::Decimal; use super::Empty; @@ -183,6 +185,12 @@ pub enum WasmMsg { pub enum GovMsg { /// This maps directly to [MsgVote](https://github.com/cosmos/cosmos-sdk/blob/v0.42.5/proto/cosmos/gov/v1beta1/tx.proto#L46-L56) in the Cosmos SDK with voter set to the contract address. Vote { proposal_id: u64, vote: VoteOption }, + /// This maps directly to [MsgVoteWeighted](https://github.com/cosmos/cosmos-sdk/blob/v0.45.8/proto/cosmos/gov/v1beta1/tx.proto#L66-L78) in the Cosmos SDK with voter set to the contract address. + #[cfg(feature = "cosmwasm_1_2")] + VoteWeighted { + proposal_id: u64, + vote: WeightedVoteOption, + }, } #[cfg(feature = "stargate")] @@ -195,6 +203,13 @@ pub enum VoteOption { NoWithVeto, } +#[cfg(all(feature = "stargate", feature = "cosmwasm_1_2"))] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +pub struct WeightedVoteOption { + option: VoteOption, + weight: Decimal, +} + /// Shortcut helper as the construction of WasmMsg::Instantiate can be quite verbose in contract code. /// /// When using this, `admin` is always unset. If you need more flexibility, create the message directly. diff --git a/packages/std/src/results/mod.rs b/packages/std/src/results/mod.rs index 95dd1dd8ef..90b8879746 100644 --- a/packages/std/src/results/mod.rs +++ b/packages/std/src/results/mod.rs @@ -10,6 +10,8 @@ mod submessages; mod system_result; pub use contract_result::ContractResult; +#[cfg(all(feature = "stargate", feature = "cosmwasm_1_2"))] +pub use cosmos_msg::WeightedVoteOption; pub use cosmos_msg::{wasm_execute, wasm_instantiate, BankMsg, CosmosMsg, CustomMsg, WasmMsg}; #[cfg(feature = "staking")] pub use cosmos_msg::{DistributionMsg, StakingMsg}; From 9a46fe97576cb38a6ba77103f2afb861eef2858b Mon Sep 17 00:00:00 2001 From: Tomasz Kurcz Date: Tue, 8 Nov 2022 16:47:43 +0100 Subject: [PATCH 3/5] Update CHANGELOG --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c6ad45371..e106965a72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,8 +25,13 @@ and this project adheres to `CanonicalAddr` ([#1463]). - cosmwasm-std: Implement `PartialEq` between `CanonicalAddr` and `HexBinary`/`Binary` ([#1463]). +- cosmwasm-std: Add `GovMsg::VoteWeighted`. In order to use this in a contract, + the `cosmwasm_1_2` feature needs to be enabled for the `cosmwasm_std` + dependency. This makes the contract incompatible with chains running versions + of CosmWasm earlier than 1.2.0 ([#1481]). [#1463]: https://github.com/CosmWasm/cosmwasm/pull/1463 +[#1481]: https://github.com/CosmWasm/cosmwasm/pull/1481 ### Changed From e59234e6b27aef17441bfe849293ecb4924a04ef Mon Sep 17 00:00:00 2001 From: Tomasz Kurcz Date: Mon, 21 Nov 2022 18:01:33 +0100 Subject: [PATCH 4/5] update CHANGELOG --- CHANGELOG.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e106965a72..47cc8557eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,15 @@ and this project adheres to ## [Unreleased] +### Added + +- cosmwasm-std: Add `GovMsg::VoteWeighted`. In order to use this in a contract, + the `cosmwasm_1_2` feature needs to be enabled for the `cosmwasm_std` + dependency. This makes the contract incompatible with chains running versions + of CosmWasm earlier than 1.2.0 ([#1481]). + +[#1481]: https://github.com/CosmWasm/cosmwasm/pull/1481 + ### Changed - cosmwasm-vm: Avoid exposing OS specific file system errors in order to test @@ -25,13 +34,8 @@ and this project adheres to `CanonicalAddr` ([#1463]). - cosmwasm-std: Implement `PartialEq` between `CanonicalAddr` and `HexBinary`/`Binary` ([#1463]). -- cosmwasm-std: Add `GovMsg::VoteWeighted`. In order to use this in a contract, - the `cosmwasm_1_2` feature needs to be enabled for the `cosmwasm_std` - dependency. This makes the contract incompatible with chains running versions - of CosmWasm earlier than 1.2.0 ([#1481]). [#1463]: https://github.com/CosmWasm/cosmwasm/pull/1463 -[#1481]: https://github.com/CosmWasm/cosmwasm/pull/1481 ### Changed From 7e117a38fc3bc7084fb7162945b2666d342354b0 Mon Sep 17 00:00:00 2001 From: Tomasz Kurcz Date: Mon, 21 Nov 2022 18:58:56 +0100 Subject: [PATCH 5/5] Add the `cosmwasm_1_2` export --- packages/std/src/exports.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/std/src/exports.rs b/packages/std/src/exports.rs index a2c986806f..5b4b30925c 100644 --- a/packages/std/src/exports.rs +++ b/packages/std/src/exports.rs @@ -45,6 +45,10 @@ extern "C" fn requires_stargate() -> () {} #[no_mangle] extern "C" fn requires_cosmwasm_1_1() -> () {} +#[cfg(feature = "cosmwasm_1_2")] +#[no_mangle] +extern "C" fn requires_cosmwasm_1_2() -> () {} + /// interface_version_* exports mark which Wasm VM interface level this contract is compiled for. /// They can be checked by cosmwasm_vm. /// Update this whenever the Wasm VM interface breaks.