Skip to content

Instantly share code, notes, and snippets.

@tim-cotten
Last active June 13, 2019 01:51
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 tim-cotten/dc2d587f9817ed830ef1ad15c528266d to your computer and use it in GitHub Desktop.
Save tim-cotten/dc2d587f9817ed830ef1ad15c528266d to your computer and use it in GitHub Desktop.
Simple Deposit Account (v1.0.0)
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