git ssb

0+

dangerousbeans / Entropy_contracts



Commit 0288fd21356a15c8f3f95a9f431bc370405ac46c

Beginnings of voting

Joran committed on 1/12/2017, 12:44:32 AM
Parent: 8c8b7da9dc43699fc6a0d49a9c8ba2ccf4075672

Files changed

contracts/Entropy.solchanged
migrations/2_deploy_contracts.jschanged
test/Entropy_actions.jschanged
contracts/Entropy.solView
@@ -108,9 +108,8 @@
108108 safety_limit = _new_limit;
109109 SafetyLimitChange(msg.sender, _new_limit);
110110 }
111111
112-
113112 /**
114113 * Actions
115114 *
116115 * Trusted citizens can create an action, which then can be voted on for 5 days
@@ -135,8 +134,30 @@
135134 actions_count = actionID + 1;
136135 }
137136
138137
138 +
139 +
140 + /**
141 + * Voting
142 + */
143 + function vote(uint actionId, bool in_favour)
144 + onlyTrusted
145 + returns (uint voteID)
146 + {
147 + Action action = actions[actionId];
148 +
149 + // Check to make sure this person has not already voted
150 + if (action.voted[msg.sender] == true) throw;
151 +
152 + voteID = action.votes.length++;
153 + action.votes[voteID] = Vote({inSupport: in_favour, citizen: msg.sender});
154 + action.voted[msg.sender] = true;
155 + action.numberOfVotes = voteID + 1;
156 + Voted(actionId, in_favour, msg.sender);
157 + }
158 +
159 +
139160 /**
140161 * Guardians 💂
141162 */
142163
@@ -211,8 +232,11 @@
211232 */
212233
213234 event ActionAdded(uint actionID, uint amount, string description);
214235
236 + // Vote
237 + event Voted(uint actionId, bool in_favour, address citizen);
238 +
215239 // A new guardian has been elected
216240 event NewGuardian(address indexed _guardian, address indexed _creator);
217241
218242 // A new person has been trusted
migrations/2_deploy_contracts.jsView
@@ -3,7 +3,7 @@
33 deployer.deploy(Owned);
44 deployer.autolink();
55
66 // Deploy main contracts
7- deployer.deploy(StandardToken);
7 + // deployer.deploy(StandardToken);
88 deployer.deploy(Entropy);
99 };
test/Entropy_actions.jsView
@@ -38,16 +38,20 @@
3838 describe("Voting", () =>{
3939 it("lets trusted citizens vote", (done) => {
4040 helpers.deployEntropyContract()
4141 .then((entropy) => {
42- entropy.newAction(1e18, "Rigging refit").then((tx) => {
43- entropy.actions_count().then((actions_count) => {
44- assert.equal(actions_count, 1);
45- })
46- .then(()=>{ done() })
42 + entropy.newAction(1e18, "Rigging refit")
43 + .then((tx) => {
44 + // Vote in favour!
45 + entropy.vote(0, true).then((tx) => {
46 + done();
47 + // TODO: Check it has a vote!
48 + // entropy.actions[0].numberOfVotes().then((count) => {
49 + // assert.equal(count, 1);
50 + // done();
51 + // })
52 + })
4753 })
4854 })
4955 });
50-
5156 })
52-
5357 })

Built with git-ssb-web