Skip to content

Commit

Permalink
use math.MaxUint64, modify if condition
Browse files Browse the repository at this point in the history
  • Loading branch information
MalekLahbib committed Oct 3, 2024
1 parent 7e174be commit 0356eca
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions examples/gno.land/p/demo/grc/grc20/banker.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package grc20

import (
"errors"
"math"
"std"
"strconv"

Expand All @@ -25,8 +26,6 @@ type Banker struct {
token *token // to share the same pointer
}

const uint64_max = 1<<64 - 1

func NewBanker(name, symbol string, decimals uint) *Banker {
if name == "" {
panic("name should not be empty")
Expand Down Expand Up @@ -59,8 +58,8 @@ func (b *Banker) Mint(address std.Address, amount uint64) error {
}

// check for overflow
if uint64_max-b.totalSupply < amount {
err := ufmt.Sprintf("you can't mint more than %d tokens", uint64_max-b.totalSupply)
if diff := math.MaxUint64 - b.totalSupply; diff < amount {
err := ufmt.Sprintf("you can't mint more than %d tokens", diff)
return errors.New(err)
}

Expand Down

0 comments on commit 0356eca

Please sign in to comment.