Skip to content

Commit e161a76

Browse files
authored
Merge pull request #1481 from CosmWasm/vote-weighted
Add `GovMsg::VoteWeighted`
2 parents 5cbf5e0 + 7e117a3 commit e161a76

File tree

6 files changed

+35
-0
lines changed

6 files changed

+35
-0
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ and this project adheres to
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- cosmwasm-std: Add `GovMsg::VoteWeighted`. In order to use this in a contract,
12+
the `cosmwasm_1_2` feature needs to be enabled for the `cosmwasm_std`
13+
dependency. This makes the contract incompatible with chains running versions
14+
of CosmWasm earlier than 1.2.0 ([#1481]).
15+
16+
[#1481]: https://github.com/CosmWasm/cosmwasm/pull/1481
17+
918
### Changed
1019

1120
- cosmwasm-vm: Avoid exposing OS specific file system errors in order to test

packages/std/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ ibc3 = ["stargate"]
3636
# This feature makes `BankQuery::Supply` available for the contract to call, but requires
3737
# the host blockchain to run CosmWasm `1.1.0` or higher.
3838
cosmwasm_1_1 = []
39+
# This feature makes `GovMsg::VoteWeighted` available for the contract to call, but requires
40+
# the host blockchain to run CosmWasm `1.2.0` or higher.
41+
cosmwasm_1_2 = []
3942

4043
[dependencies]
4144
base64 = "0.13.0"

packages/std/src/exports.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ extern "C" fn requires_stargate() -> () {}
4545
#[no_mangle]
4646
extern "C" fn requires_cosmwasm_1_1() -> () {}
4747

48+
#[cfg(feature = "cosmwasm_1_2")]
49+
#[no_mangle]
50+
extern "C" fn requires_cosmwasm_1_2() -> () {}
51+
4852
/// interface_version_* exports mark which Wasm VM interface level this contract is compiled for.
4953
/// They can be checked by cosmwasm_vm.
5054
/// Update this whenever the Wasm VM interface breaks.

packages/std/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ pub use crate::query::{
6363
pub use crate::query::{ChannelResponse, IbcQuery, ListChannelsResponse, PortIdResponse};
6464
#[allow(deprecated)]
6565
pub use crate::results::SubMsgExecutionResponse;
66+
#[cfg(all(feature = "stargate", feature = "cosmwasm_1_2"))]
67+
pub use crate::results::WeightedVoteOption;
6668
pub use crate::results::{
6769
attr, wasm_execute, wasm_instantiate, Attribute, BankMsg, ContractResult, CosmosMsg, CustomMsg,
6870
Empty, Event, QueryResponse, Reply, ReplyOn, Response, SubMsg, SubMsgResponse, SubMsgResult,

packages/std/src/results/cosmos_msg.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use crate::errors::StdResult;
99
#[cfg(feature = "stargate")]
1010
use crate::ibc::IbcMsg;
1111
use crate::serde::to_binary;
12+
#[cfg(all(feature = "stargate", feature = "cosmwasm_1_2"))]
13+
use crate::Decimal;
1214

1315
use super::Empty;
1416

@@ -183,6 +185,12 @@ pub enum WasmMsg {
183185
pub enum GovMsg {
184186
/// 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.
185187
Vote { proposal_id: u64, vote: VoteOption },
188+
/// 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.
189+
#[cfg(feature = "cosmwasm_1_2")]
190+
VoteWeighted {
191+
proposal_id: u64,
192+
vote: WeightedVoteOption,
193+
},
186194
}
187195

188196
#[cfg(feature = "stargate")]
@@ -195,6 +203,13 @@ pub enum VoteOption {
195203
NoWithVeto,
196204
}
197205

206+
#[cfg(all(feature = "stargate", feature = "cosmwasm_1_2"))]
207+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
208+
pub struct WeightedVoteOption {
209+
option: VoteOption,
210+
weight: Decimal,
211+
}
212+
198213
/// Shortcut helper as the construction of WasmMsg::Instantiate can be quite verbose in contract code.
199214
///
200215
/// When using this, `admin` is always unset. If you need more flexibility, create the message directly.

packages/std/src/results/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ mod submessages;
1010
mod system_result;
1111

1212
pub use contract_result::ContractResult;
13+
#[cfg(all(feature = "stargate", feature = "cosmwasm_1_2"))]
14+
pub use cosmos_msg::WeightedVoteOption;
1315
pub use cosmos_msg::{wasm_execute, wasm_instantiate, BankMsg, CosmosMsg, CustomMsg, WasmMsg};
1416
#[cfg(feature = "staking")]
1517
pub use cosmos_msg::{DistributionMsg, StakingMsg};

0 commit comments

Comments
 (0)