-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvoting.sol
More file actions
61 lines (50 loc) · 1.66 KB
/
Copy pathvoting.sol
File metadata and controls
61 lines (50 loc) · 1.66 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
54
55
56
57
58
59
60
61
// This is a simple proof of concept for voting backend for https://mitwirkung.dbjr.de/mitmachen/
// Unfortunately it uses too much gas to be usable :(
pragma solidity ^0.4.18;
contract Voting {
struct Vote {
int8 points;
bool isConfirmed;
uint timeCreated;
}
address creator;
bool isClosed;
mapping (bytes32 => int8) contribVotes;
mapping (bytes32 => Vote) voterVotes;
function Voting() public
{
creator = msg.sender;
}
function vote(bytes32 contribHash, bytes32 voterHash, int8 points) public
{
require(!isClosed);
bytes32 voteHash = sha256(contribHash, voterHash);
voterVotes[voteHash] = Vote(points, false, now);
}
function getContribVotes(bytes32 contribHash) public view returns (int8)
{
return contribVotes[contribHash];
}
function getVote(bytes32 contribHash, bytes32 voterHash) public view returns (int8, bool, uint)
{
bytes32 voteHash = sha256(contribHash, voterHash);
require(voterVotes[voteHash].timeCreated > 0);
return (
voterVotes[voteHash].points,
voterVotes[voteHash].isConfirmed,
voterVotes[voteHash].timeCreated
);
}
function confirmVoteVoter(bytes32 contribHash, bytes32 voterHash) public
{
require(!isClosed);
bytes32 voteHash = sha256(contribHash, voterHash);
voterVotes[voteHash].isConfirmed = true;
contribVotes[contribHash] = contribVotes[contribHash] + voterVotes[voteHash].points;
}
function closeVoting() public returns (bool)
{
require(msg.sender == creator);
isClosed = true;
}
}