Zilliqa / marketplace-contracts

GNU General Public License v3.0
2 stars 4 forks source link

payment_tokens not cleaned up #26

Closed bb111189 closed 2 years ago

bb111189 commented 2 years ago
(* 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.

bb111189 commented 2 years ago

( Withraws payment tokens ) ( - Anyone who has payment tokens can draw their tokens. )

It is not anyone due to the allowlist

ghost commented 2 years ago

Sure. It will make the transition much simpler.