Last active
June 13, 2019 01:51
-
-
Save tim-cotten/dc2d587f9817ed830ef1ad15c528266d to your computer and use it in GitHub Desktop.
Simple Deposit Account (v1.0.0)
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.22 <0.6.0; | |
/** | |
* @title DepositAccount - simple contract that stores ether and allows full or | |
* partial withdrawals by the account owner. | |
* @author Tim Cotten <tim@cotten.io> | |
*/ | |
contract DepositAccount { | |
address private owner; | |
/// @notice Only the owner can withdraw from this contract | |
modifier onlyOwner() { | |
require(msg.sender == owner); | |
_; | |
} | |
/// @notice The requested withdrawal amount must be available in the contract balance | |
modifier withMinBalance(uint256 amount) { | |
require(address(this).balance >= amount); | |
_; | |
} | |
constructor() public { | |
owner = msg.sender; | |
} | |
/// @notice Allow deposits from anyone | |
function() external payable {} | |
/// @notice Full withdrawal | |
function withdraw() public onlyOwner { | |
msg.sender.transfer(address(this).balance); | |
} | |
/// @notice Partial withdrawal | |
/// @param amount Amount requested for withdrawal | |
function withdraw(uint256 amount) public onlyOwner withMinBalance(amount) { | |
msg.sender.transfer(amount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment