-
Notifications
You must be signed in to change notification settings - Fork 0
/
election.sol
65 lines (56 loc) · 1.56 KB
/
election.sol
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
pragma solidity ^0.4.18;
contract Election
{
address owner;
uint totalvotes;
uint countcandidates = 0;
struct candidate{string name; uint256 votes;}
struct voter{bool voted;bool authorized;}
mapping(address => voter) Voters;
candidate[] candidates;
address[5] users = [0xbBEa9A07208A6AD3d44FbB0fb7E71D515aF0e887,0x7dC6186397B7A997187Aa871Ac7b99EB46a44cc8,0x42910673e4F1d6E579bB3F4405399199B37AD686,0x42910673e4F1d6E579bB3F4405399199B37AD686,0x60E117731057a9C02Db1b2dF8cf0ea1e4908D534];
constructor() public
{
owner = msg.sender;
}
modifier isowner()
{
require(msg.sender==owner);
_;
}
function addcandidate(string _name) isowner public
{
candidates.push(candidate(_name, 0));
countcandidates++;
}
modifier isauthorized()
{
for(uint i = 0; i < 5; i++ )
{
if(users[i]==msg.sender)
{
Voters[msg.sender].authorized=true;
_;
}
}
}
function vote(uint _index) isauthorized public
{
require(!Voters[msg.sender].voted);
candidates[_index].votes++;
Voters[msg.sender].voted=true;
totalvotes++;
}
function getvotes(uint _index) public view returns(uint256)
{
return candidates[_index].votes;
}
function gettotalcandidates() public view returns(uint)
{
return candidates.length;
}
function getfullvotes() public view returns(uint256)
{
return totalvotes;
}
}