Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save howardpen9/4aaf506b1856a56f9c99d55fddf0ba03 to your computer and use it in GitHub Desktop.
Save howardpen9/4aaf506b1856a56f9c99d55fddf0ba03 to your computer and use it in GitHub Desktop.
Ballot / Ticket
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