forked from magonicolas/Ethereum-Solidity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmartVote.sol
More file actions
40 lines (32 loc) · 873 Bytes
/
SmartVote.sol
File metadata and controls
40 lines (32 loc) · 873 Bytes
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
pragma solidity ^0.4.18;
contract SmartVote {
struct Election {
mapping (address => bool) ableToVote;
uint yesVotes;
uint noVotes;
uint totalVotes;
}
mapping (uint => Election) elections;
event Results(uint _yes, uint _no, uint total);
function createElection(mapping (address => bool) _ableToVote, uint _id) {
Election memory _election = Election({
id: _id,
ableToVote: _ableToVote
});
elections[_id] = _elections;
}
function Vote(uint _id, bool _vote) {
Election storage _election = elections[_id];
require (_election.ableToVote[msg.sender]);
if (_vote == true) {
_election.yesVotes++;
} else {
_election.noVotes++;
}
_election.totalVotes++;
_election.ableToVote[msg.sender] = false;
}
function ElectionResult(uint _id) {
Results(elections[_id].yesVotes, elections[_id].noVotes, elections[_id].total);
}
}