diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c6ad45371..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 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" 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. 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};