Last active
February 26, 2017 19:09
-
-
Save AlwaysBCoding/2259ff68147b7fef1a5887cb7bb2cb17 to your computer and use it in GitHub Desktop.
Ethereum Ðapp Development - Video 17 | Contract Events
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 CrowdFund { | |
address public beneficiary; | |
uint256 public goal; | |
uint256 public deadline; | |
mapping (address => uint256) funders; | |
address[] funderAddresses; | |
event NewContribution(address indexed _from, uint256 _value); | |
function CrowdFund(address _beneficiary, uint256 _goal, uint256 _duration) { | |
beneficiary = _beneficiary; | |
goal = _goal; | |
deadline = now + _duration; | |
} | |
function getFunderContribution(address _addr) constant returns (uint) { | |
return funders[_addr]; | |
} | |
function getFunderAddress(uint _index) constant returns (address) { | |
return funderAddresses[_index]; | |
} | |
function funderAddressLength() constant returns (uint) { | |
return funderAddresses.length; | |
} | |
function contribute() payable { | |
if(funders[msg.sender] == 0) funderAddresses.push(msg.sender); | |
funders[msg.sender] += msg.value; | |
NewContribution(msg.sender, msg.value); | |
} | |
function payout() { | |
if(this.balance >= goal && now > deadline) beneficiary.send(this.balance); | |
} | |
function refund() { | |
if(now > deadline && this.balance < goal) { | |
msg.sender.send(funders[msg.sender]); | |
funders[msg.sender] = 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment