eth-faucet/solidity/PeriodSimple.sol

61 lines
1.4 KiB
Solidity
Raw Normal View History

2023-03-25 15:28:38 +01:00
pragma solidity >=0.8.0;
2023-03-25 15:28:38 +01:00
// SPDX-License-Identifier: AGPL-3.0-or-later
contract PeriodSimple {
address public owner;
address public poker;
uint256 public period;
2023-02-04 07:13:20 +01:00
uint256 public balanceThreshold;
mapping (address => uint256) public lastUsed;
event PeriodChange(uint256 _value);
event BalanceThresholdChange(uint256 _value);
2023-03-25 15:28:38 +01:00
constructor() {
owner = msg.sender;
poker = owner;
}
function setPeriod(uint256 _period) public {
require(owner == msg.sender, 'ERR_NOT_OWNER');
period = _period;
emit PeriodChange(_period);
}
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;
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) {
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-03-20 11:50:11 +01:00
function poke(address _subject) external returns(bool) {
require(msg.sender == owner || msg.sender == poker, 'ERR_ACCESS');
if (!this.check(_subject)) {
return false;
}
lastUsed[_subject] = block.timestamp;
2023-03-20 11:50:11 +01:00
return true;
}
}