Withdrawal Address Holds
EasySimulation · Coinbase
To protect accounts, a newly added withdrawal address cannot be used until a security hold has passed. Process events in order; each event is one of:
["deposit", user, amount]: addsamountto the user's balance.["add_address", user, address, ts]: the user registersaddressat timets. If the user registers the same address again, its hold restarts from the newts.["withdraw", user, address, amount, ts]: a withdrawal request at timets.
A withdrawal succeeds only if all of these hold:
userhas registeredaddress(registrations by other users do not count),ts - registered_time >= hold_seconds, and- the user's current balance is at least
amount.
A successful withdrawal subtracts amount from the balance; a failed one changes nothing. Users start with balance 0. Return a list with one boolean per withdraw event, in order: True if it succeeded, False otherwise.
Example 1
- Input:
- events = [["deposit", "u1", 100], ["add_address", "u1", "addrA", 0], ["withdraw", "u1", "addrA", 30, 59], ["withdraw", "u1", "addrA", 30, 60], ["withdraw", "u1", "addrA", 80, 61], ["withdraw", "u1", "addrA", 70, 62]], hold_seconds = 60
- Output:
- [False, True, False, True]
- Explanation
- At time 59 the address is one second short of the 60-second hold. At 60 the hold has exactly elapsed, so 30 is withdrawn (balance 70). Withdrawing 80 then fails on balance, but 70 succeeds and empties the account.
Example 2
- Input:
- events = [["deposit", "u1", 50], ["add_address", "u2", "addrB", 0], ["withdraw", "u1", "addrB", 10, 100]], hold_seconds = 10
- Output:
- [False]
- Explanation
- addrB was added by u2, not u1, so u1 has never registered it and the withdrawal fails.
Example 3
- Input:
- events = [["deposit", "u", 20], ["add_address", "u", "a", 0], ["add_address", "u", "a", 50], ["withdraw", "u", "a", 5, 55]], hold_seconds = 10
- Output:
- [False]
- Explanation
- Re-adding an address restarts its hold. It was re-added at 50, so at 55 only 5 seconds have passed.
Constraints
0 <= events.length <= 10^5- Timestamps are non-decreasing across
add_addressandwithdrawevents 0 <= hold_seconds <= 10^91 <= amount <= 10^9