Last active
July 28, 2020 05:38
-
-
Save daenamkim/fa28e16bc9d59f9b73a16920163fb5e5 to your computer and use it in GitHub Desktop.
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
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