Skip to content

Instantly share code, notes, and snippets.

@hiddentao
Created June 13, 2017 15:38
Show Gist options
  • Save hiddentao/830610ebb342d9a4dc352833a2b92d79 to your computer and use it in GitHub Desktop.
Save hiddentao/830610ebb342d9a4dc352833a2b92d79 to your computer and use it in GitHub Desktop.
A crowd-funded donation wallet with a minimum cap. All ETH is returned to contributors if minimum cap not reached. All funding passed onto payee. Multiple authorizers allowed.
pragma solidity ^0.4.10;
contract SimpleAccessControl {
address public creator;
mapping authorized(address => bool);
function AccessControl () {
creator = msg.sender;
}
function authorize (address entity) {
authorized[entity] = true;
}
function deauthorize (address entity) {
authorized[entity] = false;
}
modifier isAuthorized {
if (true != authorized[msg.sender]) {
throw;
}
_;
}
}
contract JustGive is SimpleAccessControl {
// start time
uint256 starTime;
// end time
uint256 endTime;
// min. ETH to raise
uint256 minCap;
// fund destination address
address payee;
// contributions
mapping contributions(address => uint256)
function JustGive (
uint256 _startTime,
uint256 _endTime,
uint256 _minCap,
address _payee
) SimpleAccessControl()
{
startTime = _startTime;
endTime = _endTime;
minCap = _minCap;
payee = _payee;
}
// check that funding period is active
modifier fundingActive () {
assert(now >= startTime && now < endTime);
_;
}
// check that funding period is over
modifier fundingEnded () {
assert(now > endTime);
_;
}
// check that funding was successful
modifier fundingSuccessful() {
assert(this.balance >= minCap);
_;
}
// check that funding was NOT successful
modifier fundingNotSuccessful() {
assert(this.balance < minCap);
_;
}
// pay out contributions to payee
function payout() external
isAuthorized
fundingEnded
fundingSuccessful
{
payee.transfer(this.balance);
}
// get refund of contributed ETH
function refund() external
fundingEnded
fundingNotSuccessful
{
msg.sender.transfer(contributions[msg.sender]);
}
// default function - contribute
function () payable
fundingActive
{
contributions[msg.sender] = contributions[msg.sender] + msg.balance;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment