Created
February 6, 2022 08:30
-
-
Save YashKarthik/baae772dbb19ac20682e39e65470a8c7 to your computer and use it in GitHub Desktop.
Piggy bank that locks in funds for the given time and allows withdrawal by owner.
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
//SPDX-License-Identifier: MIT | |
pragma solidity ^0.8; | |
contract Piggy { | |
address payable owner; | |
uint public releaseTimestamp; | |
constructor() payable { | |
owner = payable(msg.sender); | |
} | |
event Locked(uint _releaseTimestamp, uint _lockAmt); | |
function lockIn(uint _lockPeriod) public payable { | |
releaseTimestamp = block.timestamp + (_lockPeriod * 60); | |
emit Locked(releaseTimestamp, msg.value); | |
} | |
event Withdraw(uint _releaseTimestamp, uint _actualReleaseTimestamp, uint _amount); | |
function breakPiggy() public { | |
require(msg.sender == owner, "msg.sender not owner"); | |
require(block.timestamp >= releaseTimestamp, "Lock in period not complete"); | |
uint value = address(this).balance; | |
emit Withdraw(releaseTimestamp, block.timestamp, value); | |
selfdestruct(payable(msg.sender)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment