Last active
August 25, 2018 21:45
-
-
Save MicrowaveDev/40e9ad904f263233434f325c835fe4ec to your computer and use it in GitHub Desktop.
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.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