Skip to content

Commit

Permalink
fix: enhance panic messages
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaelVallenet committed Nov 28, 2024
1 parent d9692ab commit 3f26af8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
16 changes: 8 additions & 8 deletions gnovm/stdlibs/std/banker.gno
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ func (b banker) IssueCoin(addr Address, denom string, amount int64) {
}

if !strings.HasPrefix(denom, PrevRealm().PkgPath()) {
panic(b.bt.String() + " cannot issue coins with denom not prefixed by realm pkgPath, use std.CurrentRealm().Denom(denom) to get the correct denom")
panic(b.bt.String() + " cannot issue coins with denom not prefixed by current realm pkgPath, use std.CurrentRealm().Denom(denom) to get the correct denom")
}

dname := strings.TrimPrefix(denom, PrevRealm().PkgPath())
if !reDenom.MatchString(dname) {
panic(b.bt.String() + " cannot issue coins with invalid denom name, it should match [a-z][a-z0-9]{2,15}")
baseDenom := strings.TrimPrefix(denom, PrevRealm().PkgPath())
if !reDenom.MatchString(baseDenom) {
panic(b.bt.String() + " cannot issue coins with invalid denom name, it should start by a lowercase letter and be followed by 2-15 lowercase letters or digits")
}

bankerIssueCoin(uint8(b.bt), string(addr), denom, amount)
Expand All @@ -150,12 +150,12 @@ func (b banker) RemoveCoin(addr Address, denom string, amount int64) {
}

if !strings.HasPrefix(denom, PrevRealm().PkgPath()) {
panic(b.bt.String() + " cannot issue coins with denom not prefixed by realm pkgPath, use std.CurrentRealm().Denom(denom) to get the correct denom")
panic(b.bt.String() + " cannot issue coins with denom not prefixed by current realm pkgPath, use std.CurrentRealm().Denom(denom) to get the correct denom")
}

dname := strings.TrimPrefix(denom, PrevRealm().PkgPath())
if !reDenom.MatchString(dname) {
panic(b.bt.String() + " cannot issue coins with invalid denom name, it should match [a-z][a-z0-9]{2,15}")
baseDenom := strings.TrimPrefix(denom, PrevRealm().PkgPath())
if !reDenom.MatchString(baseDenom) {
panic(b.bt.String() + " cannot issue coins with invalid denom name, it should start by a lowercase letter and be followed by 2-15 lowercase letters or digits")
}

bankerRemoveCoin(uint8(b.bt), string(addr), denom, amount)
Expand Down
1 change: 0 additions & 1 deletion gnovm/stdlibs/std/native.gno
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func DecodeBech32(addr Address) (prefix string, bz [20]byte, ok bool) {
return decodeBech32(string(addr))
}

// TODO: add regex check for denom
func RealmDenom(pkgPath, denom string) string {
// Similar to ibc spec
// ibc_denom := 'ibc/' + hash('path' + 'base_denom')
Expand Down

0 comments on commit 3f26af8

Please sign in to comment.