abstract_cw3/
msg.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use std::fmt;
4
5use cosmwasm_schema::cw_serde;
6use cosmwasm_std::{CosmosMsg, Empty};
7use cw_utils::Expiration;
8
9#[cw_serde]
10
11pub enum Cw3ExecuteMsg<T = Empty>
12where
13    T: Clone + fmt::Debug + PartialEq + JsonSchema,
14{
15    Propose {
16        title: String,
17        description: String,
18        msgs: Vec<CosmosMsg<T>>,
19        earliest: Option<Expiration>,
20        latest: Option<Expiration>,
21    },
22    Vote {
23        proposal_id: u64,
24        vote: Vote,
25    },
26    Execute {
27        proposal_id: u64,
28    },
29    Close {
30        proposal_id: u64,
31    },
32}
33
34#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, JsonSchema, Debug)]
35#[serde(rename_all = "lowercase")]
36pub enum Vote {
37    /// Marks support for the proposal.
38    Yes,
39    /// Marks opposition to the proposal.
40    No,
41    /// Marks participation but does not count towards the ratio of support / opposed
42    Abstain,
43    /// Veto is generally to be treated as a No vote. Some implementations may allow certain
44    /// voters to be able to Veto, or them to be counted stronger than No in some way.
45    Veto,
46}
47
48#[cfg(test)]
49mod test {
50    use super::*;
51    use cosmwasm_std::to_json_vec;
52
53    #[test]
54    fn vote_encoding() {
55        let a = Vote::Yes;
56        let encoded = to_json_vec(&a).unwrap();
57        let json = String::from_utf8_lossy(&encoded).to_string();
58        assert_eq!(r#""yes""#, json.as_str());
59    }
60
61    #[test]
62    fn vote_encoding_embedded() {
63        let msg = Cw3ExecuteMsg::Vote::<Empty> {
64            proposal_id: 17,
65            vote: Vote::No,
66        };
67        let encoded = to_json_vec(&msg).unwrap();
68        let json = String::from_utf8_lossy(&encoded).to_string();
69        assert_eq!(r#"{"vote":{"proposal_id":17,"vote":"no"}}"#, json.as_str());
70    }
71}