Say I have a smart contract for exchanging 6
Token_A with 6
Token_B with an additional time condition when only 1 exchange can happen every 1 month (we don't care about
msg.sender here. we can assume all actions can be done by one address):
In day 0, owner will trigger
claimfunction that moves 1
Token_Ato their address and 1
Token_Bto someone else's address.
In day 6, if owner triggers
claimfunction, the request will be rejected.
In day 30, owner can trigger
claimfor another token exchange and so on.
The simple solution I can think of is to create a list of timestamps and fill it with 6 timestamps (starting from creation of contract) and one pointer. Every time a claim request comes in, we can compare
block.timestamp and increment pointer if this is a valid claim.
Though this might work for one user, this is going to become tricky if we have more than only one user (say we have a list of whitelisted users - timestamp list will be same for all but we will need multiple pointers for each user).
Any better solution for this problem?