Skip to content

Instantly share code, notes, and snippets.

@josh-richardson
Created January 13, 2020 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josh-richardson/cd170c7fac47a2d4eb38fb2f6db6a37f to your computer and use it in GitHub Desktop.
Save josh-richardson/cd170c7fac47a2d4eb38fb2f6db6a37f to your computer and use it in GitHub Desktop.
function vote() external inState(State.Funded) {
if (now > successBy) {
state = State.Failed;
revert();
}
require(msg.sender != creator);
require(contributions[msg.sender] > 0);
require(votes[msg.sender] != currentStage);
votes[msg.sender] = currentStage;
agrees += 1;
if (agrees >= totalContributions / 2) {
agrees = 0;
payStage();
if (currentStage == stages) {
state = State.Successful;
} else {
currentStage += 1;
}
}
}
function payStage() internal inState(State.Funded) returns (bool) {
uint256 totalRaised = currentBalance;
currentBalance = currentBalance.sub(balancePerStage);
if (creator.send(balancePerStage)) {
emit CreatorPaidStage(creator);
return true;
} else {
currentBalance = totalRaised;
state = State.Successful;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment