如果他们在最后一次收到token
后的特定时间内出售智能合约token
,我正在寻找一种方法来提高msg.sender
的税费。
在Solidity中,是否可以从msg.sender
获得timestamp
,直到他们最后一次收到令牌?或者还有其他方法可以实现这一点吗?
您可以实现地址到上次收到令牌时的映射,然后根据它进行验证。
pragma solidity ^0.8.5;
contract MyToken {
mapping (address => uint256) lastReceived;
function transfer(address _to, uint256 _amount) external {
uint256 fee = getFee(msg.sender);
// TODO rest of your transfer implementation
updateLastReceived(_to);
}
function getFee(address _sender) internal returns (uint256) {
if (block.timestamp - lastReceived[_sender] < 1 days) {
// if they received a token in the past 24 hours, set a fee
return 100;
}
return 0;
}
function updateLastReceived(address _receiver) internal {
lastReceived[_receiver] = block.timestamp;
}
}