Skip to content

Instantly share code, notes, and snippets.

@daenamkim
Last active July 28, 2020 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daenamkim/fa28e16bc9d59f9b73a16920163fb5e5 to your computer and use it in GitHub Desktop.
Save daenamkim/fa28e16bc9d59f9b73a16920163fb5e5 to your computer and use it in GitHub Desktop.
pragma solidity >=0.5.1 <0.6.0;
contract Donation {
address[] public givers;
uint[] public values;
address owner;
constructor() public {
owner = msg.sender;
}
modifier onlyowner {
require(msg.sender == owner, 'sender should be owner');
_;
}
event fundMoved(address _to, uint _amount);
function donate() payable public {
require(msg.value > 5, 'donation should be more than 5');
addGiver(msg.value);
}
function moveFund(address payable _to, uint _amount) onlyowner public {
uint balance = address(this).balance;
if (_amount <= balance) {
if (_to.send(balance)) {
emit fundMoved(_to, _amount);
} else {
revert();
}
} else {
revert();
}
}
function addGiver(uint _amount) internal {
givers.push(msg.sender);
values.push(_amount);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment