@@ -203,6 +203,75 @@ pub enum WasmMsg {
203
203
ClearAdmin { contract_addr : String } ,
204
204
}
205
205
206
+ /// This message type allows the contract interact with the [x/gov] module in order
207
+ /// to cast votes.
208
+ ///
209
+ /// [x/gov]: https://github.com/cosmos/cosmos-sdk/tree/v0.45.12/x/gov
210
+ ///
211
+ /// ## Examples
212
+ ///
213
+ /// Cast a simple vote:
214
+ ///
215
+ /// ```
216
+ /// # use cosmwasm_std::{
217
+ /// # HexBinary,
218
+ /// # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo,
219
+ /// # Response, QueryResponse,
220
+ /// # };
221
+ /// # type ExecuteMsg = ();
222
+ /// use cosmwasm_std::{GovMsg, VoteOption};
223
+ ///
224
+ /// #[entry_point]
225
+ /// pub fn execute(
226
+ /// deps: DepsMut,
227
+ /// env: Env,
228
+ /// info: MessageInfo,
229
+ /// msg: ExecuteMsg,
230
+ /// ) -> Result<Response, StdError> {
231
+ /// // ...
232
+ /// Ok(Response::new().add_message(GovMsg::Vote {
233
+ /// proposal_id: 4,
234
+ /// vote: VoteOption::Yes,
235
+ /// }))
236
+ /// }
237
+ /// ```
238
+ ///
239
+ /// Cast a weighted vote:
240
+ ///
241
+ /// ```
242
+ /// # use cosmwasm_std::{
243
+ /// # HexBinary,
244
+ /// # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo,
245
+ /// # Response, QueryResponse,
246
+ /// # };
247
+ /// # type ExecuteMsg = ();
248
+ /// # #[cfg(feature = "cosmwasm_1_2")]
249
+ /// use cosmwasm_std::{Decimal, GovMsg, VoteOption, WeightedVoteOption};
250
+ ///
251
+ /// # #[cfg(feature = "cosmwasm_1_2")]
252
+ /// #[entry_point]
253
+ /// pub fn execute(
254
+ /// deps: DepsMut,
255
+ /// env: Env,
256
+ /// info: MessageInfo,
257
+ /// msg: ExecuteMsg,
258
+ /// ) -> Result<Response, StdError> {
259
+ /// // ...
260
+ /// Ok(Response::new().add_message(GovMsg::VoteWeighted {
261
+ /// proposal_id: 4,
262
+ /// options: vec![
263
+ /// WeightedVoteOption {
264
+ /// option: VoteOption::Yes,
265
+ /// weight: Decimal::percent(65),
266
+ /// },
267
+ /// WeightedVoteOption {
268
+ /// option: VoteOption::Abstain,
269
+ /// weight: Decimal::percent(35),
270
+ /// },
271
+ /// ],
272
+ /// }))
273
+ /// }
274
+ /// ```
206
275
#[ cfg( feature = "stargate" ) ]
207
276
#[ derive( Serialize , Deserialize , Clone , Debug , PartialEq , Eq , JsonSchema ) ]
208
277
#[ serde( rename_all = "snake_case" ) ]
@@ -237,8 +306,8 @@ pub enum VoteOption {
237
306
#[ cfg( all( feature = "stargate" , feature = "cosmwasm_1_2" ) ) ]
238
307
#[ derive( Serialize , Deserialize , Clone , Debug , PartialEq , Eq , JsonSchema ) ]
239
308
pub struct WeightedVoteOption {
240
- option : VoteOption ,
241
- weight : Decimal ,
309
+ pub option : VoteOption ,
310
+ pub weight : Decimal ,
242
311
}
243
312
244
313
/// Shortcut helper as the construction of WasmMsg::Instantiate can be quite verbose in contract code.
0 commit comments