// Simple Crowdfunding Contract pragma solidity ^0.4.19; contract Crowdfunding { event Contributed(address _sender, uint amount); uint crowdSaleDuration; uint crowdSaleStart; uint crowdSaleTarget; address owner; bool crowdSaleOver; mapping (address => uint) contributions; function Crowdfunding(uint256 _crowdsaleDuration, uint _crowdSaleTarget) public { crowdSaleDuration = _crowdsaleDuration; crowdSaleStart = now; crowdSaleTarget = _crowdSaleTarget; owner = msg.sender; } function ownerWithdraw() targetReached external { owner.transfer(this.balance); crowdSaleOver = true; } // Make sure sender does not withdraw more than they have contributed function withdrawContribution(uint _amount) timeLimitReached targetNotReached { require(contributions[msg.sender] - _amount >= 0); contributions[msg.sender] -= _amount; msg.sender.transfer(_amount); } function contribute() payable public{ contributions[msg.sender] += msg.value; Contributed(msg.sender, msg.value); } function() payable public { contribute(); } modifier timeLimitReached() { require(now >= crowdSaleStart + crowdSaleDuration); _; } modifier targetReached() { require(this.balance >= crowdSaleTarget); _; } modifier targetNotReached() { require(this.balance < crowdSaleTarget); _; } }
0.4.19