Skip to content

Instantly share code, notes, and snippets.

@partylikeits1983
Created May 22, 2021 21:39
Show Gist options
  • Save partylikeits1983/3df8a86034d67f22055b54c8b20bf3c0 to your computer and use it in GitHub Desktop.
Save partylikeits1983/3df8a86034d67f22055b54c8b20bf3c0 to your computer and use it in GitHub Desktop.
function vote(uint proposal) public {
Voter storage sender = voters[msg.sender];
require(sender.weight != 0, "Has no right to vote");
require(!sender.voted, "Already voted.");
sender.voted = true;
sender.vote = proposal;
proposals[proposal].voteCount += sender.weight;
}
// winningProposal must be executed before EndVote
function countVote() public
returns (uint winningProposal_)
{
require(
block.timestamp > voteEndTime,
"Vote not yet ended.");
uint winningVoteCount = 0;
for (uint p = 0; p < proposals.length; p++) {
if (proposals[p].voteCount > winningVoteCount) {
winningVoteCount = proposals[p].voteCount;
winningProposal_ = p;
decision = winningProposal_;
ended = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment