abstract_cw3/query.rs
1use cosmwasm_schema::cw_serde;
2use cosmwasm_std::{Addr, CosmosMsg, Empty};
3use cw_utils::{Expiration, ThresholdResponse};
4
5use crate::{msg::Vote, DepositInfo};
6
7#[cw_serde]
8pub enum Cw3QueryMsg {
9 /// Returns the threshold rules that would be used for a new proposal that was
10 /// opened right now. The threshold rules do not change often, but the `total_weight`
11 /// in the response may easily differ from that used in previously opened proposals.
12 /// Returns ThresholdResponse.
13 Threshold {},
14 /// Returns details of the proposal state. Returns ProposalResponse.
15 Proposal { proposal_id: u64 },
16 /// Iterate over details of all proposals from oldest to newest. Returns ProposalListResponse
17 ListProposals {
18 start_after: Option<u64>,
19 limit: Option<u32>,
20 },
21 /// Iterate reverse over details of all proposals, this is useful to easily query
22 /// only the most recent proposals (to get updates). Returns ProposalListResponse
23 ReverseProposals {
24 start_before: Option<u64>,
25 limit: Option<u32>,
26 },
27 /// Query the vote made by the given voter on `proposal_id`. This should
28 /// return an error if there is no such proposal. It will return a None value
29 /// if the proposal exists but the voter did not vote. Returns VoteResponse
30 Vote { proposal_id: u64, voter: String },
31 /// Iterate (with pagination) over all votes for this proposal. The ordering is arbitrary,
32 /// unlikely to be sorted by address. But ordering is consistent and pagination from the end
33 /// of each page will cover all votes for the proposal. Returns VoteListResponse
34 ListVotes {
35 proposal_id: u64,
36 start_after: Option<String>,
37 limit: Option<u32>,
38 },
39 /// Voter extension: Returns VoterResponse
40 Voter { address: String },
41 /// ListVoters extension: Returns VoterListResponse
42 ListVoters {
43 start_after: Option<String>,
44 limit: Option<u32>,
45 },
46}
47
48/// Note, if you are storing custom messages in the proposal,
49/// the querier needs to know what possible custom message types
50/// those are in order to parse the response
51#[cw_serde]
52pub struct ProposalResponse<T = Empty> {
53 pub id: u64,
54 pub title: String,
55 pub description: String,
56 pub msgs: Vec<CosmosMsg<T>>,
57 pub status: Status,
58 pub expires: Expiration,
59 /// This is the threshold that is applied to this proposal. Both
60 /// the rules of the voting contract, as well as the total_weight
61 /// of the voting group may have changed since this time. That
62 /// means that the generic `Threshold{}` query does not provide
63 /// valid information for existing proposals.
64 pub threshold: ThresholdResponse,
65 pub proposer: Addr,
66 pub deposit: Option<DepositInfo>,
67}
68
69#[cw_serde]
70#[derive(Copy)]
71#[repr(u8)]
72pub enum Status {
73 /// proposal was created, but voting has not yet begun for whatever reason
74 Pending = 1,
75 /// you can vote on this
76 Open = 2,
77 /// voting is over and it did not pass
78 Rejected = 3,
79 /// voting is over and it did pass, but has not yet executed
80 Passed = 4,
81 /// voting is over it passed, and the proposal was executed
82 Executed = 5,
83}
84
85#[cw_serde]
86pub struct ProposalListResponse<T = Empty> {
87 pub proposals: Vec<ProposalResponse<T>>,
88}
89
90#[cw_serde]
91pub struct VoteListResponse {
92 pub votes: Vec<VoteInfo>,
93}
94
95/// Returns the vote (opinion as well as weight counted) as well as
96/// the address of the voter who submitted it
97#[cw_serde]
98pub struct VoteInfo {
99 pub proposal_id: u64,
100 pub voter: String,
101 pub vote: Vote,
102 pub weight: u64,
103}
104
105#[cw_serde]
106pub struct VoteResponse {
107 pub vote: Option<VoteInfo>,
108}
109
110#[cw_serde]
111pub struct VoterResponse {
112 pub weight: Option<u64>,
113}
114
115#[cw_serde]
116pub struct VoterListResponse {
117 pub voters: Vec<VoterDetail>,
118}
119
120#[cw_serde]
121pub struct VoterDetail {
122 pub addr: String,
123 pub weight: u64,
124}