eth-faucet/solidity/PeriodSimple.sol

56 lines
1.3 KiB
Solidity
Raw Normal View History

pragma solidity >0.8.0;
// SPDX-License-Identifier: GPL-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);
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) {
2023-02-04 07:13:20 +01:00
require(_subject.balance >= balanceThreshold);
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');
2023-03-20 10:03:20 +01:00
require(this.check(_subject), 'ERR_PREMATURE');
lastUsed[_subject] = block.timestamp;
2023-03-20 11:50:11 +01:00
return true;
}
}