Created
March 3, 2022 06:41
-
-
Save howardpen9/4aaf506b1856a56f9c99d55fddf0ba03 to your computer and use it in GitHub Desktop.
Ballot / Ticket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity >=0.4.2 <0.6.0; | |
contract Ballot { | |
struct Voter { | |
uint weight; | |
bool voted; | |
uint vote; | |
} | |
mapping(address => Voter) voters; | |
struct Proposal { | |
uint voteCount; | |
} | |
Proposal[] proposals; | |
address chairperson; | |
enum Phase {Init, Regs, Vote, Done} | |
Phase public state = Phase.Init; | |
constructor (uint numProposals) public { | |
chairperson = msg.sender; | |
voters[chairperson].weight = 2; | |
for (uint prop = 0; prop < numProposals; prop++){ | |
proposals.push(Proposal(0)); | |
} | |
} | |
function changeState(Phase x) public { | |
if (msg.sender != chairperson) { | |
revert(); | |
} | |
if ( x < state ) revert(); | |
state = x; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment