-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathregaVoting.sol
76 lines (62 loc) · 1.92 KB
/
regaVoting.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
66
67
68
69
70
71
72
73
74
75
76
pragma solidity ^0.4.10;
import "./rstBase.sol";
contract RegaVoting is VotingControllerBase {
enum votingResult {
NotVoted,
VotedFor,
VotedAgainst
}
function voteFor() public {
require( balanceOf[msg.sender] > 0 );
getVotingData().registerVoting( msg.sender, votingResult.VotedFor, balanceOf[msg.sender] );
}
function voteAgainst() public {
require( balanceOf[msg.sender] > 0 );
getVotingData().registerVoting( msg.sender, votingResult.VotedAgainst, balanceOf[msg.sender] );
}
function startVoting( bytes32 description ) public {
votingData = new RegaVotingData( description );
}
function stopVoting() public {
getVotingData().stop();
processVotingResult();
}
function getCurrentVotingDescription() public constant returns (bytes32 description) {
return getVotingData().description();
}
function getVotingData() internal constant returns (RegaVotingData vd) {
require( votingData != address(0x0) );
return RegaVotingData(votingData);
}
function processVotingResult() internal {
}
}
contract RegaVotingData {
mapping (address => RegaVoting.votingResult) public votingResults;
uint256 public votedFor;
uint256 public votedAgainst;
address public owner;
bytes32 public description;
bool public isOpen;
function RegaVotingData( bytes32 descr ) {
description = descr;
owner = msg.sender;
isOpen = true;
}
function stop( ) {
require( msg.sender == owner );
isOpen = false;
}
function registerVoting( address voter, RegaVoting.votingResult vote, uint256 weight ) {
require( msg.sender == owner && isOpen );
if( votingResults[voter] == RegaVoting.votingResult.NotVoted &&
vote != RegaVoting.votingResult.NotVoted &&
weight > 0 ) {
votingResults[voter] = vote;
if( vote == RegaVoting.votingResult.VotedFor )
votedFor += weight;
else
votedAgainst += weight;
}
}
}