Created
July 21, 2018 18:26
-
-
Save vasa-develop/2919d46a194bb086d2cc46176b7d8f32 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
library SafeMath { | |
function mul(uint256 a, uint256 b) internal pure returns (uint256) { | |
if (a == 0) { | |
return 0; | |
} | |
uint256 c = a * b; | |
assert(c / a == b); | |
return c; | |
} | |
function div(uint256 a, uint256 b) internal pure returns (uint256) { | |
// assert(b > 0); // Solidity automatically throws when dividing by 0 | |
uint256 c = a / b; | |
// assert(a == b * c + a % b); // There is no case in which this doesn't hold | |
return c; | |
} | |
function sub(uint256 a, uint256 b) internal pure returns (uint256) { | |
assert(b <= a); | |
return a - b; | |
} | |
function add(uint256 a, uint256 b) internal pure returns (uint256) { | |
uint256 c = a + b; | |
assert(c >= a); | |
return c; | |
} | |
} | |
contract TimeLock { | |
using SafeMath for uint; // use the library for uint type | |
mapping(address => uint256) public balances; | |
mapping(address => uint256) public lockTime; | |
function deposit() public payable { | |
balances[msg.sender] = balances[msg.sender].add(msg.value); | |
lockTime[msg.sender] = now.add(1 weeks); | |
} | |
function increaseLockTime(uint256 _secondsToIncrease) public { | |
lockTime[msg.sender] = lockTime[msg.sender].add(_secondsToIncrease); | |
} | |
function withdraw() public { | |
require(balances[msg.sender] > 0); | |
require(now > lockTime[msg.sender]); | |
balances[msg.sender] = 0; | |
msg.sender.transfer(balances[msg.sender]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment