Skip to content

Instantly share code, notes, and snippets.

@MicrowaveDev
Last active August 25, 2018 21:45
Show Gist options
  • Save MicrowaveDev/40e9ad904f263233434f325c835fe4ec to your computer and use it in GitHub Desktop.
Save MicrowaveDev/40e9ad904f263233434f325c835fe4ec to your computer and use it in GitHub Desktop.
pragma solidity 0.4.24;
contract SimpleVoting {
string public votingReason;
uint256 public votesToEnd;
mapping (address => bool) public alreadyVoted;
uint256 public votesForTrue;
uint256 public votesForFalse;
bool public isEnded;
constructor(string _votingReason, uint256 _votesToEnd) public {
votingReason = _votingReason;
votesToEnd = _votesToEnd;
}
function vote(bool _choice) public {
require(alreadyVoted[msg.sender] != true, "Already voted");
require(isEnded != true, "Voting ended");
if(_choice == true) {
votesForTrue += 1;
} else {
votesForFalse += 1;
}
if(votesForTrue >= votesToEnd || votesForFalse >= votesToEnd) {
isEnded = true;
}
alreadyVoted[msg.sender] = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment