-
Notifications
You must be signed in to change notification settings - Fork 5
/
lib.rs
executable file
·134 lines (115 loc) · 4.23 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#![cfg_attr(not(feature = "std"), no_std, no_main)]
// # ✒️ Challenge 2: Implement voter registration, proposal management, and voting in your Dao.
//
// - **Difficulty**: Mid
// - **Submission Criteria:** ink! contract must
// - Use a storage-optimized data-structure `Mapping` or `StorageVec`
// - Store registered members, member votes, and proposals to vote on.
// - Implement methods to register and de-register members.
// - Implement methods to create proposals and a method to vote on proposals.
// - Unit tests for adding members, votes, and proposals.
// - **Submission Guidelines:**
// - Verify with R0GUE DevRel, and post on X.
// - **Prize:** sub0 merch
#[ink::contract]
mod dao {
use ink::{
prelude::string::String,
storage::{Mapping, StorageVec},
};
use minidao_common::*;
#[derive(Clone)]
#[cfg_attr(
feature = "std",
derive(Debug, PartialEq, Eq, ink::storage::traits::StorageLayout)
)]
#[ink::scale_derive(Encode, Decode, TypeInfo)]
pub struct BasicProposal {
pub vote_count: u32,
}
#[ink(storage)]
pub struct Dao {
value: bool,
}
impl Dao {
// Constructor that initializes the values for the contract.
#[ink(constructor)]
pub fn new(init_value: bool) -> Self {
Self { value: init_value }
}
// Constructor that initializes the default values for the contract.
#[ink(constructor)]
pub fn default() -> Self {
Self::new(Default::default())
}
#[ink(message)]
pub fn get_name(&self) -> String {
// - Returns the name of the Dao
todo!()
}
#[ink(message)]
pub fn register_voter(&mut self) -> Result<(), DaoError> {
// - Error: Throw error `DaoError::VoterAlreadyRegistered` if the voter is registered
// - Success: Register a new `voter` to the Dao
Ok(())
}
#[ink(message)]
pub fn deregister_voter(&mut self) -> Result<(), DaoError> {
// - Error: Throw error `DaoError::VoterNotRegistered` if the voter is not registered
// - Success: Deregister a new `voter` from the Dao
Ok(())
}
#[ink(message)]
pub fn has_voter(&self, voter: AccountId) -> bool {
// - Success: Return if the voter is registered.
todo!();
}
#[ink(message)]
pub fn create_proposal(&mut self) -> Result<(), DaoError> {
// - Error: Throw error `DaoError::VoterNotRegistered` if the voter is not registered
// - Success: Create a new proposal that stores `votes` from `voters`
Ok(())
}
#[ink(message)]
pub fn remove_proposal(&mut self, proposal_id: u32) -> Result<(), DaoError> {
// - Error: Throw error `DaoError::VoterNotRegistered` if the voter is not registered
// - Error: Throw error `DaoError::ProposalDoesNotExist` if the proposal is not created
// - Success: Create a new proposal that stores `votes` from `voters`
Ok(())
}
#[ink(message)]
pub fn get_proposal(&self, proposal_id: u32) -> Option<BasicProposal> {
// - Success: Returns the proposal detail
todo!()
}
#[ink(message)]
pub fn vote(&mut self, proposal_id: u32) -> Result<(), DaoError> {
// - Error: Throw error `DaoError::VoterNotRegistered` if the voter is not registered
// - Error: Throw error `Error::ProposalDoesNotExist` if the proposal is not created
// - Success: Vote on the proposal
Ok(())
}
#[ink(message)]
pub fn vote_count(&self, voter: AccountId) -> u32 {
// - Returns the number of `votes` a Dao `voter` voted
todo!();
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::dao::Dao;
#[ink::test]
fn test_voter_registration() {
todo!("Challenge 2");
}
#[ink::test]
fn test_proposal_management() {
todo!("Challenge 2");
}
#[ink::test]
fn test_vote() {
todo!("Challenge 2");
}
}
}