Last active
August 5, 2022 23:13
-
-
Save Jesserc/647dd037e3311f7ae4d9c8869049aaab to your computer and use it in GitHub Desktop.
This file contains hidden or 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.0; | |
contract Staking { | |
mapping(address => uint256) balances; | |
uint256 public deadline = 0; | |
event Stake(address sender, uint256 amount); | |
function stake() public payable { | |
require(msg.value > 0, "Input value"); | |
require(block.timestamp > deadline, "Wait until 30sec"); | |
balances[msg.sender] += msg.value; | |
emit Stake(msg.sender, msg.value); | |
updateDeadline(block.timestamp + 30 seconds); | |
} | |
function withdraw() public payable { | |
require(block.timestamp > deadline, ""); | |
require(balances[msg.sender] > 0, "No amount staked"); | |
payable(msg.sender).transfer(balances[msg.sender]); | |
} | |
function updateDeadline(uint256 _deadline) private { | |
deadline = _deadline; | |
} | |
function timeLeft() public view returns (uint256) { | |
return deadline - block.timestamp; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment