Created
February 25, 2017 03:51
-
-
Save AlwaysBCoding/b9ab207d2afb3adfd60f9df1003bc951 to your computer and use it in GitHub Desktop.
Ethereum Ðapp Development - Video 15 | The Block Gas Limit
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 CrowdFund { | |
address public beneficiary; | |
uint256 public goal; | |
uint256 public deadline; | |
struct Funder { | |
address addr; | |
uint256 contribution; | |
} | |
Funder[] funders; | |
function CrowdFund(address _beneficiary, uint256 _goal, uint256 _duration) { | |
beneficiary = _beneficiary; | |
goal = _goal; | |
deadline = now + _duration; | |
} | |
function contribute() payable { | |
funders.push(Funder(msg.sender, msg.value)); | |
} | |
function payout() { | |
if(this.balance >= goal && now > deadline) beneficiary.send(this.balance); | |
} | |
function refund() { | |
if(msg.sender != beneficiary) throw; | |
uint256 index = 0; | |
while(index < funders.length) { | |
funders[index].addr.send(funders[index].contribution); | |
index++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment