(* Withraws payment tokens *)
(* - Anyone who has payment tokens can draw their tokens. *)
transition WithdrawPaymentTokens(payment_token_address: ByStr20, amount: Uint128)
RequireNotPaused;
RequireAllowedUser _sender;
maybe_balance <- payment_tokens[_sender][payment_token_address];
match maybe_balance with
| None =>
error = AccountNotFoundError;
Throw error
| Some balance =>
is_insufficient = builtin lt balance amount;
match is_insufficient with
| True =>
error = InsufficientPaymentTokenError;
Throw error
| False =>
is_native_zil = builtin eq payment_token_address zero_address;
match is_native_zil with
| True =>
(* marketplace transfers the native ZILs to _sender *)
AddFunds _sender amount
| False =>
(* marketplace transfers the amount to _sender *)
ZRC2Transfer payment_token_address _sender amount
end;
left = builtin sub balance amount;
payment_tokens[_sender][payment_token_address] := left;
e = {
_eventname : "WithdrawPaymentTokens";
recipient: _sender;
payment_token_address: payment_token_address;
amount: amount
};
event e
end
end
end
payment_tokens never get cleaned up and will keep growing in size.
I think it will be better to just force the user to withdraw the full amount of the tokens. It will make logic cleaner and interact with smart contracts easier.
payment_tokens
never get cleaned up and will keep growing in size.I think it will be better to just force the user to withdraw the full amount of the tokens. It will make logic cleaner and interact with smart contracts easier.