@@ -11,12 +11,18 @@ use wasmlanche::{
11
11
pub type ProposalId = usize ;
12
12
13
13
state_schema ! {
14
+ /// Number of total proposals, doubles as the next `ProposalId`
14
15
ProposalCount => ProposalId ,
16
+ /// The proposal itself
15
17
ProposalItem ( ProposalId ) => Proposal ,
16
- ProposalVoteInfo ( ProposalId ) => ProposalMeta ,
18
+ /// Voting information include who can vote and how many yeas left until quorum is reached
19
+ VoteInfo ( ProposalId ) => ProposalMeta ,
20
+ /// Votes cast by a voter
21
+ /// Any address can vote for any proposal, but that doesn't mean that the proposal will count toward quorum
17
22
Vote ( ProposalId , Address ) => bool ,
18
23
}
19
24
25
+ /// Create a proposal
20
26
#[ public]
21
27
pub fn propose (
22
28
ctx : & mut Context ,
@@ -46,14 +52,15 @@ pub fn propose(
46
52
ctx. store ( (
47
53
( ProposalCount , id + 1 ) ,
48
54
( ProposalItem ( id) , proposal) ,
49
- ( ProposalVoteInfo ( id) , meta) ,
55
+ ( VoteInfo ( id) , meta) ,
50
56
( Vote ( id, actor) , true ) ,
51
57
) )
52
58
. expect ( "failed to store proposal" ) ;
53
59
54
60
id
55
61
}
56
62
63
+ /// Vote on a proposal
57
64
#[ public]
58
65
pub fn vote ( ctx : & mut Context , proposal_id : ProposalId , vote : bool ) -> Option < Vec < u8 > > {
59
66
let actor = ctx. actor ( ) ;
@@ -77,7 +84,7 @@ pub fn vote(ctx: &mut Context, proposal_id: ProposalId, vote: bool) -> Option<Ve
77
84
voters,
78
85
votes_remaining,
79
86
} = ctx
80
- . get ( ProposalVoteInfo ( proposal_id) )
87
+ . get ( VoteInfo ( proposal_id) )
81
88
. expect ( "failed to deserialize" )
82
89
. expect ( "proposal not found" ) ;
83
90
@@ -88,7 +95,7 @@ pub fn vote(ctx: &mut Context, proposal_id: ProposalId, vote: bool) -> Option<Ve
88
95
let votes_remaining = votes_remaining - 1 ;
89
96
90
97
ctx. store_by_key (
91
- ProposalVoteInfo ( proposal_id) ,
98
+ VoteInfo ( proposal_id) ,
92
99
ProposalMeta {
93
100
voters,
94
101
votes_remaining,
@@ -121,14 +128,19 @@ pub fn vote(ctx: &mut Context, proposal_id: ProposalId, vote: bool) -> Option<Ve
121
128
}
122
129
}
123
130
131
+ /// A proposal consists of an address of a contract to call
132
+ /// a function name to call on that contract
133
+ /// and a set of serialized arguments to pass to that function
124
134
#[ derive( BorshSerialize , BorshDeserialize ) ]
135
+ // TODO: re-derive these traits to automatically inject the crate
125
136
#[ borsh( crate = "wasmlanche::borsh" ) ]
126
137
pub struct Proposal {
127
138
pub contract_address : Address ,
128
139
pub function_name : String ,
129
140
pub args : Vec < u8 > ,
130
141
}
131
142
143
+ /// Contains a set of `Voters` as well as `votes_remaining` (until quorum is reached)
132
144
#[ derive( BorshSerialize , BorshDeserialize ) ]
133
145
#[ borsh( crate = "wasmlanche::borsh" ) ]
134
146
struct ProposalMeta {
@@ -137,6 +149,10 @@ struct ProposalMeta {
137
149
// TODO: add expiry
138
150
}
139
151
152
+ /// Either a specific set of addresses OR an open vote in which the quorum voter will actually have to pay
153
+ /// for the final execution
154
+ // TODO:
155
+ // reward the final voter with to refund their fuel contributions
140
156
#[ cfg_attr( test, derive( Debug ) ) ]
141
157
pub enum Voters {
142
158
Any ,
@@ -322,7 +338,7 @@ mod tests {
322
338
let ProposalMeta {
323
339
votes_remaining, ..
324
340
} = ctx
325
- . get ( ProposalVoteInfo ( id) )
341
+ . get ( VoteInfo ( id) )
326
342
. expect ( "failed to deserialize" )
327
343
. expect ( "proposal not found" ) ;
328
344
0 commit comments