-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCounterWithTimer.sol
43 lines (32 loc) · 909 Bytes
/
CounterWithTimer.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
34
35
36
37
38
39
40
41
42
43
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
contract Counter {
uint256 count;
uint256 time;
uint256 deadline = block.timestamp + 30 seconds;
error timeUp(string);
modifier checkTime{
if (block.timestamp > deadline) {
revert timeUp("Please wait for 30 seconds");
}
if (deadline - block.timestamp == 0 ){
revert timeUp("Time up, wait for 30 minutes");
}
_;
}
function Increase() public checkTime {
count++;
}
function Decrease() public checkTime {
count--;
}
function ViewCounter() public view returns(uint256) {
return count;
}
function returnRemainingTime() public view returns(uint256){
return deadline - block.timestamp;
}
function BlockTimeStamp() public view returns(uint256){
return block.timestamp;
}
}