-
Notifications
You must be signed in to change notification settings - Fork 0
/
Time Lock.sol
33 lines (25 loc) · 1.12 KB
/
Time Lock.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
/*The time lock contract ensures that funds are
inaccessible until a specified release time.
Only the designated beneficiary can withdraw
funds after the release time has passed.
source: Bahloul Mubarik - LinkedIn */
contract TimeLock {
event Withdrawal(address indexed beneficiary, uint256 amount);
address public beneficiary;
uint256 public releaseTime;
constructor (address _beneficiary, uint256 _releaseTime) {
require(_releaseTime > block.timestamp, "Release time must be in the future");
beneficiary = _beneficiary;
releaseTime = _releaseTime;
}
function withdraw() external {
require(msg.sender == beneficiary, "only the beneficiary can withdraw");
require(block. timestamp >= releaseTime, "Release time has not arrived yet");
// Perform the withdrawal
// (In a real contract, you may want to transfer funds instead of using a simple bool flag)
payable(beneficiary).transfer(address(this).balance);
emit Withdrawal(msg.sender, address(this).balance);
}
}