-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move withdrawal functionality into a mixin contract
- Loading branch information
1 parent
942c440
commit 6379be6
Showing
2 changed files
with
37 additions
and
22 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
pragma solidity ^0.5.4; | ||
|
||
import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; | ||
import "openzeppelin-solidity/contracts/math/SafeMath.sol"; | ||
|
||
|
||
/** | ||
* @title Delayed Withdrawal | ||
* @dev A base contract to allow delayed funds withdrawal from the contract. | ||
*/ | ||
contract DelayedWithdrawal is Ownable { | ||
using SafeMath for uint256; | ||
|
||
uint256 internal _withdrawalDelay; | ||
uint256 internal _pendingWithdrawal; | ||
|
||
/** | ||
* @dev Initiate withdrawal of this contract balance to the owner. | ||
*/ | ||
function initiateWithdrawal() public onlyOwner { | ||
_pendingWithdrawal = block.timestamp + _withdrawalDelay; | ||
} | ||
|
||
/** | ||
* @dev Finish withdrawal of this contract balance to the owner. | ||
*/ | ||
function finishWithdrawal(address payable payee) public onlyOwner { | ||
require(_pendingWithdrawal > 0, "Pending withdrawal timestamp must be set and be greater than zero."); | ||
require(block.timestamp >= _pendingWithdrawal, "The current time must pass the pending withdrawal timestamp."); | ||
|
||
// Reset pending withdrawal before sending to prevent re-entrancy attacks | ||
_pendingWithdrawal = 0; | ||
payee.transfer(address(this).balance); | ||
} | ||
} |
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