Last active
January 6, 2023 20:40
-
-
Save luckyyang/3a8c210203955b64c07fb8275d7366a9 to your computer and use it in GitHub Desktop.
donation example of solidity
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.4.25; | |
contract Donation { | |
uint fundLimit = 1 ether; | |
address owner; | |
event fundMoved(address _to, uint _amount); | |
modifier onlyowner { if (msg.sender == owner) _; } | |
address[] _giver; | |
uint[] _values; | |
constructor () public { | |
owner = msg.sender; | |
} | |
function donate() public payable { | |
addGiver(msg.value); | |
} | |
function getFundLimit() public view returns (uint) { | |
return fundLimit; | |
} | |
function moveFund(address _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 { | |
_giver.push(msg.sender); | |
_values.push(_amount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment