-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathelection.sol
More file actions
53 lines (44 loc) · 1.27 KB
/
election.sol
File metadata and controls
53 lines (44 loc) · 1.27 KB
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
pragma solidity >=0.3.0;
contract Election{
struct Proposal { // This is a type for a single proposal.
bytes32 name;
uint voteCount; // number of total votes
}
struct Voter {
bool voted;
uint vote;
bytes32 aadhar_id;
}
mapping(address => Voter) public voters;
address public curator;
Proposal[] public proposals;
mapping(address =>bytes32) voter; // wallet address mapped to aadhar-id
function Election( bytes32[] proposalNames){
curator = msg.sender;
for(uint i = 0; i < proposalNames.length; i++){
proposals.push(
Proposal({
name: proposalNames[i],
voteCount: 0
})
);
}
}
function addVoter(address wallet_address, bytes32 aadhar_id){
if (wallet_address == msg.sender){
Voter sender = voters[msg.sender];
sender.aadhar_id = aadhar_id;
}
}
function addVote(uint proposal_index){
Voter sender = voters[msg.sender];
if (sender.voted)
throw;
sender.voted = true;
sender.vote = proposal_index;
proposals[proposal_index].voteCount += 1;
}
function show_count(uint proposal_index) returns(uint count){
return proposals[proposal_index].voteCount;
}
}