Skip to content
This repository has been archived by the owner on Apr 29, 2022. It is now read-only.

inconsistent data types for function variable and storage variable #51

Open
Astrapolis-peasant opened this issue Jan 11, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@Astrapolis-peasant
Copy link

  protected _transfer(sender: AccountId, recipient: AccountId, amount: u128): void {
    assert(sender.notEq(AccountId.Null), "ERC20: transfer from the zero address");
    assert(recipient.notEq(AccountId.Null), "ERC20: transfer to the zero address");

    let spenderBalance =this.balanceOf(sender);
    assert(spenderBalance >= amount, "ERC20: transfer amount exceeds balance");

    let senderLeft = spenderBalance - amount;
    this.balances.set(sender, new UInt128(senderLeft));

    let recipientLeft = this.balanceOf(recipient) + amount;
    this.balances.set(recipient, new UInt128(recipientLeft));
    (new Transfer(sender, recipient, amount)).emit();
  }

In function parameters, ask uses u128 but when saving to data storage, it requires casting to UInt128.

@Astrapolis-peasant
Copy link
Author

It seems like the codec used by ask are separated for computation and storage

@yjhmelody yjhmelody added the enhancement New feature or request label Jan 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants