Skip to content

Commit 3a0adb4

Browse files
fixup! Implement basic multisig example
1 parent cb04357 commit 3a0adb4

File tree

1 file changed

+21
-5
lines changed
  • x/contracts/examples/multisig/src

1 file changed

+21
-5
lines changed

x/contracts/examples/multisig/src/lib.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@ use wasmlanche::{
1111
pub type ProposalId = usize;
1212

1313
state_schema! {
14+
/// Number of total proposals, doubles as the next `ProposalId`
1415
ProposalCount => ProposalId,
16+
/// The proposal itself
1517
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
1722
Vote(ProposalId, Address) => bool,
1823
}
1924

25+
/// Create a proposal
2026
#[public]
2127
pub fn propose(
2228
ctx: &mut Context,
@@ -46,14 +52,15 @@ pub fn propose(
4652
ctx.store((
4753
(ProposalCount, id + 1),
4854
(ProposalItem(id), proposal),
49-
(ProposalVoteInfo(id), meta),
55+
(VoteInfo(id), meta),
5056
(Vote(id, actor), true),
5157
))
5258
.expect("failed to store proposal");
5359

5460
id
5561
}
5662

63+
/// Vote on a proposal
5764
#[public]
5865
pub fn vote(ctx: &mut Context, proposal_id: ProposalId, vote: bool) -> Option<Vec<u8>> {
5966
let actor = ctx.actor();
@@ -77,7 +84,7 @@ pub fn vote(ctx: &mut Context, proposal_id: ProposalId, vote: bool) -> Option<Ve
7784
voters,
7885
votes_remaining,
7986
} = ctx
80-
.get(ProposalVoteInfo(proposal_id))
87+
.get(VoteInfo(proposal_id))
8188
.expect("failed to deserialize")
8289
.expect("proposal not found");
8390

@@ -88,7 +95,7 @@ pub fn vote(ctx: &mut Context, proposal_id: ProposalId, vote: bool) -> Option<Ve
8895
let votes_remaining = votes_remaining - 1;
8996

9097
ctx.store_by_key(
91-
ProposalVoteInfo(proposal_id),
98+
VoteInfo(proposal_id),
9299
ProposalMeta {
93100
voters,
94101
votes_remaining,
@@ -121,14 +128,19 @@ pub fn vote(ctx: &mut Context, proposal_id: ProposalId, vote: bool) -> Option<Ve
121128
}
122129
}
123130

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
124134
#[derive(BorshSerialize, BorshDeserialize)]
135+
// TODO: re-derive these traits to automatically inject the crate
125136
#[borsh(crate = "wasmlanche::borsh")]
126137
pub struct Proposal {
127138
pub contract_address: Address,
128139
pub function_name: String,
129140
pub args: Vec<u8>,
130141
}
131142

143+
/// Contains a set of `Voters` as well as `votes_remaining` (until quorum is reached)
132144
#[derive(BorshSerialize, BorshDeserialize)]
133145
#[borsh(crate = "wasmlanche::borsh")]
134146
struct ProposalMeta {
@@ -137,6 +149,10 @@ struct ProposalMeta {
137149
// TODO: add expiry
138150
}
139151

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
140156
#[cfg_attr(test, derive(Debug))]
141157
pub enum Voters {
142158
Any,
@@ -322,7 +338,7 @@ mod tests {
322338
let ProposalMeta {
323339
votes_remaining, ..
324340
} = ctx
325-
.get(ProposalVoteInfo(id))
341+
.get(VoteInfo(id))
326342
.expect("failed to deserialize")
327343
.expect("proposal not found");
328344

0 commit comments

Comments
 (0)