Created
July 7, 2015 14:20
-
-
Save chriseth/f89ecc1f4a01be0c9a3a to your computer and use it in GitHub Desktop.
Mini-Crowdfunding
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
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