Created
December 20, 2016 22:15
-
-
Save RFV/5f78849045de72ea75c14e43c783d76d to your computer and use it in GitHub Desktop.
Crowdfunding Smart Contract
This file contains hidden or 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
contract Crowdfunding { | |
address recipient; uint goal; uint deadline; | |
struct Contribution { address contributor; uint amount; } | |
Contribution[] contributions; | |
uint contributed; | |
function Crowdfunding(address _recipient, uint256 _goal, uint256 _deadline) { | |
recipient = _recipient; | |
goal = _goal; | |
deadline = _deadline; | |
} | |
function () { | |
contributions[contributions.length++] = Contribution(msg.sender, msg.value); | |
contributed += msg.value; | |
} | |
modifier afterDeadline() { if (now >= deadline) _ } | |
function checkGoalReached() afterDeadline { | |
if (contributed < goal) | |
for (uint i = 0; i < contributions.length; ++i) | |
contributions[i].contributor.send(contributions[i].amount); | |
suicide(recipient); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment