2023-03-25 15:28:38 +01:00
|
|
|
pragma solidity >=0.8.0;
|
2023-02-03 08:21:38 +01:00
|
|
|
|
2023-03-25 15:28:38 +01:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
2023-02-03 08:21:38 +01:00
|
|
|
|
|
|
|
contract PeriodSimple {
|
|
|
|
|
|
|
|
address public owner;
|
|
|
|
address public poker;
|
|
|
|
uint256 public period;
|
2023-02-04 07:13:20 +01:00
|
|
|
uint256 public balanceThreshold;
|
2023-02-03 08:21:38 +01:00
|
|
|
mapping (address => uint256) public lastUsed;
|
|
|
|
|
|
|
|
event PeriodChange(uint256 _value);
|
2023-02-12 09:16:17 +01:00
|
|
|
event BalanceThresholdChange(uint256 _value);
|
2023-03-25 15:28:38 +01:00
|
|
|
|
2023-02-03 08:21:38 +01:00
|
|
|
constructor() {
|
|
|
|
owner = msg.sender;
|
|
|
|
poker = owner;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setPeriod(uint256 _period) public {
|
|
|
|
require(owner == msg.sender, 'ERR_NOT_OWNER');
|
|
|
|
period = _period;
|
2023-02-12 09:16:17 +01:00
|
|
|
emit PeriodChange(_period);
|
2023-02-03 08:21:38 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 16:04:44 +01:00
|
|
|
function setPoker(address _poker) public {
|
|
|
|
require(msg.sender == owner);
|
|
|
|
poker = _poker;
|
|
|
|
}
|
|
|
|
|
2023-02-04 07:13:20 +01:00
|
|
|
function setBalanceThreshold(uint256 _threshold) public {
|
|
|
|
require(msg.sender == owner);
|
|
|
|
balanceThreshold = _threshold;
|
2023-02-12 09:16:17 +01:00
|
|
|
emit BalanceThresholdChange(_threshold);
|
2023-02-04 07:13:20 +01:00
|
|
|
}
|
|
|
|
|
2023-03-20 10:03:20 +01:00
|
|
|
function next(address _subject) external view returns(uint256) {
|
|
|
|
return lastUsed[_subject] + period;
|
|
|
|
}
|
|
|
|
|
|
|
|
function check(address _subject) external view returns(bool) {
|
2023-03-24 17:09:04 +01:00
|
|
|
if (balanceThreshold > 0 && _subject.balance >= balanceThreshold) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-02-03 16:04:44 +01:00
|
|
|
if (lastUsed[_subject] == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
2023-03-20 10:03:20 +01:00
|
|
|
return block.timestamp > this.next(_subject);
|
2023-02-03 08:21:38 +01:00
|
|
|
}
|
|
|
|
|
2023-03-20 11:50:11 +01:00
|
|
|
function poke(address _subject) external returns(bool) {
|
2023-02-03 08:21:38 +01:00
|
|
|
require(msg.sender == owner || msg.sender == poker, 'ERR_ACCESS');
|
2023-03-24 17:09:04 +01:00
|
|
|
if (!this.check(_subject)) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-02-03 08:21:38 +01:00
|
|
|
lastUsed[_subject] = block.timestamp;
|
2023-03-20 11:50:11 +01:00
|
|
|
return true;
|
2023-02-03 08:21:38 +01:00
|
|
|
}
|
|
|
|
}
|