From 308ba2376a05c3c00023145fa3f8cbfd4ec40315 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Thu, 28 Nov 2024 17:10:03 +0100 Subject: [PATCH 01/37] feat: expect full denom in issue & remove coins + add RealmDenom func and Realm.Denom method --- gnovm/stdlibs/std/banker.go | 29 +++++++++++++++-------------- gnovm/stdlibs/std/frame.gno | 4 ++++ gnovm/stdlibs/std/native.gno | 8 ++++++++ 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/gnovm/stdlibs/std/banker.go b/gnovm/stdlibs/std/banker.go index 892af94777f..96eeef56093 100644 --- a/gnovm/stdlibs/std/banker.go +++ b/gnovm/stdlibs/std/banker.go @@ -75,30 +75,31 @@ func X_bankerTotalCoin(m *gno.Machine, bt uint8, denom string) int64 { func X_bankerIssueCoin(m *gno.Machine, bt uint8, addr string, denom string, amount int64) { // gno checks for bt == RealmIssue + m.Context.(ExecContext).Banker.IssueCoin(crypto.Bech32Address(addr), denom, amount) // check origin denom format - matched := reDenom.MatchString(denom) - if !matched { - m.Panic(typedString("invalid denom format to issue coin, must be " + reDenom.String())) - return - } + // matched := reDenom.MatchString(denom) + // if !matched { + // m.Panic(typedString("invalid denom format to issue coin, must be " + reDenom.String())) + // return + // } // Similar to ibc spec // ibc_denom := 'ibc/' + hash('path' + 'base_denom') // gno_realm_denom := '/' + 'pkg_path' + ':' + 'base_denom' - newDenom := "/" + m.Realm.Path + ":" + denom - GetContext(m).Banker.IssueCoin(crypto.Bech32Address(addr), newDenom, amount) + // newDenom := "/" + m.Realm.Path + ":" + denom + // GetContext(m).Banker.IssueCoin(crypto.Bech32Address(addr), newDenom, amount) } func X_bankerRemoveCoin(m *gno.Machine, bt uint8, addr string, denom string, amount int64) { // gno checks for bt == RealmIssue - matched := reDenom.MatchString(denom) - if !matched { - m.Panic(typedString("invalid denom format to remove coin, must be " + reDenom.String())) - return - } + // matched := reDenom.MatchString(denom) + // if !matched { + // m.Panic(typedString("invalid denom format to remove coin, must be " + reDenom.String())) + // return + // } - newDenom := "/" + m.Realm.Path + ":" + denom - GetContext(m).Banker.RemoveCoin(crypto.Bech32Address(addr), newDenom, amount) + // newDenom := "/" + m.Realm.Path + ":" + denom + GetContext(m).Banker.RemoveCoin(crypto.Bech32Address(addr), denom, amount) } diff --git a/gnovm/stdlibs/std/frame.gno b/gnovm/stdlibs/std/frame.gno index bc3a000f5a0..87ffb5892fb 100644 --- a/gnovm/stdlibs/std/frame.gno +++ b/gnovm/stdlibs/std/frame.gno @@ -16,3 +16,7 @@ func (r Realm) PkgPath() string { func (r Realm) IsUser() bool { return r.pkgPath == "" } + +func (r Realm) Denom(denom string) string { + return RealmDenom(r.pkgPath, denom) +} diff --git a/gnovm/stdlibs/std/native.gno b/gnovm/stdlibs/std/native.gno index 5421e231de2..09f1c9b4be7 100644 --- a/gnovm/stdlibs/std/native.gno +++ b/gnovm/stdlibs/std/native.gno @@ -56,6 +56,14 @@ 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) { + // Similar to ibc spec + // ibc_denom := 'ibc/' + hash('path' + 'base_denom') + // gno_realm_denom := '/' + 'pkg_path' + ':' + 'base_denom' + return "/" + pkgPath + ":" + denom +} + // Variations which don't use named types. func origSend() (denoms []string, amounts []int64) func origCaller() string From d9692ab482f51c9fe55bb79e93f0e86361895cb2 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Thu, 28 Nov 2024 19:59:08 +0100 Subject: [PATCH 02/37] feat: expect full denom in issue & remove coins + add RealmDenom func and Realm.Denom method --- gnovm/stdlibs/std/banker.gno | 25 +++++++++++++++++++++++++ gnovm/stdlibs/std/banker.go | 29 +---------------------------- gnovm/stdlibs/std/native.gno | 2 +- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/gnovm/stdlibs/std/banker.gno b/gnovm/stdlibs/std/banker.gno index 5412b73281c..972ad228d55 100644 --- a/gnovm/stdlibs/std/banker.gno +++ b/gnovm/stdlibs/std/banker.gno @@ -1,7 +1,9 @@ package std import ( + "regexp" "strconv" + "strings" ) // Realm functions can call std.GetBanker(options) to get @@ -59,6 +61,9 @@ func (b BankerType) String() string { } } +// regexp for denom format +var reDenom = regexp.MustCompile("[a-z][a-z0-9]{2,15}") + //---------------------------------------- // adapter for native banker @@ -126,6 +131,16 @@ func (b banker) IssueCoin(addr Address, denom string, amount int64) { if b.bt != BankerTypeRealmIssue { panic(b.bt.String() + " cannot issue coins") } + + 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") + } + + 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}") + } + bankerIssueCoin(uint8(b.bt), string(addr), denom, amount) } @@ -133,5 +148,15 @@ func (b banker) RemoveCoin(addr Address, denom string, amount int64) { if b.bt != BankerTypeRealmIssue { panic(b.bt.String() + " cannot remove coins") } + + 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") + } + + 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}") + } + bankerRemoveCoin(uint8(b.bt), string(addr), denom, amount) } diff --git a/gnovm/stdlibs/std/banker.go b/gnovm/stdlibs/std/banker.go index 96eeef56093..c57ba8529ed 100644 --- a/gnovm/stdlibs/std/banker.go +++ b/gnovm/stdlibs/std/banker.go @@ -2,7 +2,6 @@ package std import ( "fmt" - "regexp" gno "github.com/gnolang/gno/gnovm/pkg/gnolang" "github.com/gnolang/gno/tm2/pkg/crypto" @@ -33,9 +32,6 @@ const ( btRealmIssue ) -// regexp for denom format -var reDenom = regexp.MustCompile("[a-z][a-z0-9]{2,15}") - func X_bankerGetCoins(m *gno.Machine, bt uint8, addr string) (denoms []string, amounts []int64) { coins := GetContext(m).Banker.GetCoins(crypto.Bech32Address(addr)) return ExpandCoins(coins) @@ -74,32 +70,9 @@ func X_bankerTotalCoin(m *gno.Machine, bt uint8, denom string) int64 { } func X_bankerIssueCoin(m *gno.Machine, bt uint8, addr string, denom string, amount int64) { - // gno checks for bt == RealmIssue - m.Context.(ExecContext).Banker.IssueCoin(crypto.Bech32Address(addr), denom, amount) - - // check origin denom format - // matched := reDenom.MatchString(denom) - // if !matched { - // m.Panic(typedString("invalid denom format to issue coin, must be " + reDenom.String())) - // return - // } - - // Similar to ibc spec - // ibc_denom := 'ibc/' + hash('path' + 'base_denom') - // gno_realm_denom := '/' + 'pkg_path' + ':' + 'base_denom' - // newDenom := "/" + m.Realm.Path + ":" + denom - // GetContext(m).Banker.IssueCoin(crypto.Bech32Address(addr), newDenom, amount) + GetContext(m).Banker.IssueCoin(crypto.Bech32Address(addr), denom, amount) } func X_bankerRemoveCoin(m *gno.Machine, bt uint8, addr string, denom string, amount int64) { - // gno checks for bt == RealmIssue - - // matched := reDenom.MatchString(denom) - // if !matched { - // m.Panic(typedString("invalid denom format to remove coin, must be " + reDenom.String())) - // return - // } - - // newDenom := "/" + m.Realm.Path + ":" + denom GetContext(m).Banker.RemoveCoin(crypto.Bech32Address(addr), denom, amount) } diff --git a/gnovm/stdlibs/std/native.gno b/gnovm/stdlibs/std/native.gno index 09f1c9b4be7..168e58eede2 100644 --- a/gnovm/stdlibs/std/native.gno +++ b/gnovm/stdlibs/std/native.gno @@ -57,7 +57,7 @@ func DecodeBech32(addr Address) (prefix string, bz [20]byte, ok bool) { } // TODO: add regex check for denom -func RealmDenom(pkgPath, denom string) { +func RealmDenom(pkgPath, denom string) string { // Similar to ibc spec // ibc_denom := 'ibc/' + hash('path' + 'base_denom') // gno_realm_denom := '/' + 'pkg_path' + ':' + 'base_denom' From 3f26af8fc80b61a587701e33e4ae78fec6ab68d7 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Thu, 28 Nov 2024 20:51:55 +0100 Subject: [PATCH 03/37] fix: enhance panic messages --- gnovm/stdlibs/std/banker.gno | 16 ++++++++-------- gnovm/stdlibs/std/native.gno | 1 - 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/gnovm/stdlibs/std/banker.gno b/gnovm/stdlibs/std/banker.gno index 972ad228d55..e67f4a6d07f 100644 --- a/gnovm/stdlibs/std/banker.gno +++ b/gnovm/stdlibs/std/banker.gno @@ -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) @@ -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) diff --git a/gnovm/stdlibs/std/native.gno b/gnovm/stdlibs/std/native.gno index 168e58eede2..d1d0039fa80 100644 --- a/gnovm/stdlibs/std/native.gno +++ b/gnovm/stdlibs/std/native.gno @@ -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') From f9aab7509e3cbf2e1941b220765f12809c6347f0 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Thu, 28 Nov 2024 21:14:35 +0100 Subject: [PATCH 04/37] fix: test --- .../cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar b/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar index 71ef6400471..093b19ec136 100644 --- a/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar +++ b/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar @@ -61,12 +61,12 @@ import ( func Mint(addr std.Address, denom string, amount int64) { banker := std.GetBanker(std.BankerTypeRealmIssue) - banker.IssueCoin(addr, denom, amount) + banker.IssueCoin(addr, std.CurrentRealm().Denom(denom), amount) } func Burn(addr std.Address, denom string, amount int64) { banker := std.GetBanker(std.BankerTypeRealmIssue) - banker.RemoveCoin(addr, denom, amount) + banker.RemoveCoin(addr, std.CurrentRealm().Denom(denom), amount) } -- long/realm_banker.gno -- From 1b90a884c639dfb97ae1289ab42ff043b996cd4d Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Thu, 28 Nov 2024 23:12:35 +0100 Subject: [PATCH 05/37] fix: test --- gno.land/cmd/gnoland/testdata/prevrealm.txtar | 22 +++++++++---------- .../realm_banker_issued_coin_denom.txtar | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/prevrealm.txtar b/gno.land/cmd/gnoland/testdata/prevrealm.txtar index 4a7cece6d62..58b0cdce1d6 100644 --- a/gno.land/cmd/gnoland/testdata/prevrealm.txtar +++ b/gno.land/cmd/gnoland/testdata/prevrealm.txtar @@ -34,19 +34,19 @@ env RFOO_ADDR=g1evezrh92xaucffmtgsaa3rvmz5s8kedffsg469 # Test cases ## 1. MsgCall -> myrlm.A: user address -gnokey maketx call -pkgpath gno.land/r/myrlm -func A -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 +gnokey maketx call -pkgpath gno.land/r/myrlm -func A -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 stdout ${USER_ADDR_test1} ## 2. MsgCall -> myrealm.B -> myrlm.A: user address -gnokey maketx call -pkgpath gno.land/r/myrlm -func B -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 +gnokey maketx call -pkgpath gno.land/r/myrlm -func B -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 stdout ${USER_ADDR_test1} ## 3. MsgCall -> r/foo.A -> myrlm.A: r/foo -gnokey maketx call -pkgpath gno.land/r/foo -func A -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 +gnokey maketx call -pkgpath gno.land/r/foo -func A -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 stdout ${RFOO_ADDR} ## 4. MsgCall -> r/foo.B -> myrlm.B -> r/foo.A: r/foo -gnokey maketx call -pkgpath gno.land/r/foo -func B -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 +gnokey maketx call -pkgpath gno.land/r/foo -func B -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 stdout ${RFOO_ADDR} ## remove due to update to maketx call can only call realm (case 5, 6, 13) @@ -59,27 +59,27 @@ stdout ${RFOO_ADDR} ## stdout ${USER_ADDR_test1} ## 7. MsgRun -> myrlm.A: user address -gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmA.gno +gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmA.gno stdout ${USER_ADDR_test1} ## 8. MsgRun -> myrealm.B -> myrlm.A: user address -gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmB.gno +gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmB.gno stdout ${USER_ADDR_test1} ## 9. MsgRun -> r/foo.A -> myrlm.A: r/foo -gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooA.gno +gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooA.gno stdout ${RFOO_ADDR} ## 10. MsgRun -> r/foo.B -> myrlm.B -> r/foo.A: r/foo -gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooB.gno +gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooB.gno stdout ${RFOO_ADDR} ## 11. MsgRun -> p/demo/bar.A: user address -gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/barA.gno +gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 $WORK/run/barA.gno stdout ${USER_ADDR_test1} ## 12. MsgRun -> p/demo/bar.B: user address -gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/barB.gno +gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 $WORK/run/barB.gno stdout ${USER_ADDR_test1} ## 13. MsgCall -> std.PrevRealm(): user address @@ -87,7 +87,7 @@ stdout ${USER_ADDR_test1} ## stdout ${USER_ADDR_test1} ## 14. MsgRun -> std.PrevRealm(): user address -gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/baz.gno +gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 $WORK/run/baz.gno stdout ${USER_ADDR_test1} -- r/myrlm/myrlm.gno -- diff --git a/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar b/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar index 093b19ec136..fc389bb8308 100644 --- a/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar +++ b/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar @@ -79,10 +79,10 @@ import ( func Mint(addr std.Address, denom string, amount int64) { banker := std.GetBanker(std.BankerTypeRealmIssue) - banker.IssueCoin(addr, denom, amount) + banker.IssueCoin(addr, std.CurrentRealm().Denom(denom), amount) } func Burn(addr std.Address, denom string, amount int64) { banker := std.GetBanker(std.BankerTypeRealmIssue) - banker.RemoveCoin(addr, denom, amount) + banker.RemoveCoin(addr, std.CurrentRealm().Denom(denom), amount) } \ No newline at end of file From 8ab1cc396f279584629691328305e480fa43232d Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Thu, 28 Nov 2024 23:35:55 +0100 Subject: [PATCH 06/37] fix: add gas wanted in test since stdlib got bigger --- gno.land/pkg/gnoclient/integration_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/gno.land/pkg/gnoclient/integration_test.go b/gno.land/pkg/gnoclient/integration_test.go index 0a06eb4756a..945121fbacf 100644 --- a/gno.land/pkg/gnoclient/integration_test.go +++ b/gno.land/pkg/gnoclient/integration_test.go @@ -40,7 +40,7 @@ func TestCallSingle_Integration(t *testing.T) { // Make Tx config baseCfg := BaseTxCfg{ GasFee: ugnot.ValueString(10000), - GasWanted: 8000000, + GasWanted: 9000000, AccountNumber: 0, SequenceNumber: 0, Memo: "", @@ -93,7 +93,7 @@ func TestCallMultiple_Integration(t *testing.T) { // Make Tx config baseCfg := BaseTxCfg{ GasFee: ugnot.ValueString(10000), - GasWanted: 8000000, + GasWanted: 9000000, AccountNumber: 0, SequenceNumber: 0, Memo: "", @@ -155,7 +155,7 @@ func TestSendSingle_Integration(t *testing.T) { // Make Tx config baseCfg := BaseTxCfg{ GasFee: ugnot.ValueString(10000), - GasWanted: 8000000, + GasWanted: 9000000, AccountNumber: 0, SequenceNumber: 0, Memo: "", @@ -219,7 +219,7 @@ func TestSendMultiple_Integration(t *testing.T) { // Make Tx config baseCfg := BaseTxCfg{ GasFee: ugnot.ValueString(10000), - GasWanted: 8000000, + GasWanted: 9000000, AccountNumber: 0, SequenceNumber: 0, Memo: "", @@ -291,7 +291,7 @@ func TestRunSingle_Integration(t *testing.T) { // Make Tx config baseCfg := BaseTxCfg{ GasFee: ugnot.ValueString(10000), - GasWanted: 8000000, + GasWanted: 9000000, AccountNumber: 0, SequenceNumber: 0, Memo: "", @@ -452,7 +452,7 @@ func TestAddPackageSingle_Integration(t *testing.T) { // Make Tx config baseCfg := BaseTxCfg{ GasFee: ugnot.ValueString(10000), - GasWanted: 8000000, + GasWanted: 9000000, AccountNumber: 0, SequenceNumber: 0, Memo: "", @@ -537,7 +537,7 @@ func TestAddPackageMultiple_Integration(t *testing.T) { // Make Tx config baseCfg := BaseTxCfg{ GasFee: ugnot.ValueString(10000), - GasWanted: 8000000, + GasWanted: 9000000, AccountNumber: 0, SequenceNumber: 0, Memo: "", From 54bc8c098b58c3a09e8bb1433b0940d958a81627 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Thu, 28 Nov 2024 23:44:26 +0100 Subject: [PATCH 07/37] fix: tests --- gnovm/tests/files/std5.gno | 2 +- gnovm/tests/files/std8.gno | 2 +- gnovm/tests/files/zrealm_natbind0.gno | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gnovm/tests/files/std5.gno b/gnovm/tests/files/std5.gno index 54cfb7846ab..5070d13c42c 100644 --- a/gnovm/tests/files/std5.gno +++ b/gnovm/tests/files/std5.gno @@ -13,7 +13,7 @@ func main() { // Stacktrace: // panic: frame not found -// callerAt(n) +// callerAt(n) // gonative:std.callerAt // std.GetCallerAt(2) // std/native.gno:44 diff --git a/gnovm/tests/files/std8.gno b/gnovm/tests/files/std8.gno index 27545f267ce..0ba203b00e1 100644 --- a/gnovm/tests/files/std8.gno +++ b/gnovm/tests/files/std8.gno @@ -23,7 +23,7 @@ func main() { // Stacktrace: // panic: frame not found -// callerAt(n) +// callerAt(n) // gonative:std.callerAt // std.GetCallerAt(4) // std/native.gno:44 diff --git a/gnovm/tests/files/zrealm_natbind0.gno b/gnovm/tests/files/zrealm_natbind0.gno index 16a374164d5..6baf4a055e7 100644 --- a/gnovm/tests/files/zrealm_natbind0.gno +++ b/gnovm/tests/files/zrealm_natbind0.gno @@ -69,7 +69,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "a7f5397443359ea76c50be82c77f1f893a060925:8" +// "ObjectID": "a7f5397443359ea76c50be82c77f1f893a060925:47" // }, // "FileName": "native.gno", // "IsMethod": false, From 2d734e87782db85d893368d6174614b85a323917 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Fri, 29 Nov 2024 00:06:04 +0100 Subject: [PATCH 08/37] fix: tests --- .../gnoland/testdata/assertorigincall.txtar | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/assertorigincall.txtar b/gno.land/cmd/gnoland/testdata/assertorigincall.txtar index 62d660a9215..1a5664d6bef 100644 --- a/gno.land/cmd/gnoland/testdata/assertorigincall.txtar +++ b/gno.land/cmd/gnoland/testdata/assertorigincall.txtar @@ -33,85 +33,85 @@ gnoland start # Test cases ## 1. MsgCall -> myrlm.A: PANIC -! gnokey maketx call -pkgpath gno.land/r/myrlm -func A -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 +! gnokey maketx call -pkgpath gno.land/r/myrlm -func A -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 stderr 'invalid non-origin call' ## 2. MsgCall -> myrlm.B: PASS -gnokey maketx call -pkgpath gno.land/r/myrlm -func B -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 +gnokey maketx call -pkgpath gno.land/r/myrlm -func B -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 stdout 'OK!' ## 3. MsgCall -> myrlm.C: PASS -gnokey maketx call -pkgpath gno.land/r/myrlm -func C -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 +gnokey maketx call -pkgpath gno.land/r/myrlm -func C -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 stdout 'OK!' ## 4. MsgCall -> r/foo.A -> myrlm.A: PANIC -! gnokey maketx call -pkgpath gno.land/r/foo -func A -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 +! gnokey maketx call -pkgpath gno.land/r/foo -func A -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 stderr 'invalid non-origin call' ## 5. MsgCall -> r/foo.B -> myrlm.B: PASS -gnokey maketx call -pkgpath gno.land/r/foo -func B -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 +gnokey maketx call -pkgpath gno.land/r/foo -func B -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 stdout 'OK!' ## 6. MsgCall -> r/foo.C -> myrlm.C: PANIC -! gnokey maketx call -pkgpath gno.land/r/foo -func C -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 +! gnokey maketx call -pkgpath gno.land/r/foo -func C -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 stderr 'invalid non-origin call' ## remove due to update to maketx call can only call realm (case 7,8,9) ## 7. MsgCall -> p/demo/bar.A: PANIC -## ! gnokey maketx call -pkgpath gno.land/p/demo/bar -func A -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 +## ! gnokey maketx call -pkgpath gno.land/p/demo/bar -func A -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 ## stderr 'invalid non-origin call' ## 8. MsgCall -> p/demo/bar.B: PASS -## gnokey maketx call -pkgpath gno.land/p/demo/bar -func B -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 +## gnokey maketx call -pkgpath gno.land/p/demo/bar -func B -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 ## stdout 'OK!' ## 9. MsgCall -> p/demo/bar.C: PANIC -## ! gnokey maketx call -pkgpath gno.land/p/demo/bar -func C -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 +## ! gnokey maketx call -pkgpath gno.land/p/demo/bar -func C -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 ## stderr 'invalid non-origin call' ## 10. MsgRun -> run.main -> myrlm.A: PANIC -! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmA.gno +! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmA.gno stderr 'invalid non-origin call' ## 11. MsgRun -> run.main -> myrlm.B: PASS -gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmB.gno +gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmB.gno stdout 'OK!' ## 12. MsgRun -> run.main -> myrlm.C: PANIC -! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmC.gno +! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmC.gno stderr 'invalid non-origin call' ## 13. MsgRun -> run.main -> foo.A: PANIC -! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooA.gno +! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooA.gno stderr 'invalid non-origin call' ## 14. MsgRun -> run.main -> foo.B: PASS -gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooB.gno +gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooB.gno stdout 'OK!' ## 15. MsgRun -> run.main -> foo.C: PANIC -! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooC.gno +! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 $WORK/run/fooC.gno stderr 'invalid non-origin call' ## 16. MsgRun -> run.main -> bar.A: PANIC -! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/barA.gno +! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 $WORK/run/barA.gno stderr 'invalid non-origin call' ## 17. MsgRun -> run.main -> bar.B: PASS -gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/barB.gno +gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 $WORK/run/barB.gno stdout 'OK!' ## 18. MsgRun -> run.main -> bar.C: PANIC -! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/barC.gno +! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 $WORK/run/barC.gno stderr 'invalid non-origin call' ## remove testcase 19 due to maketx call forced to call a realm ## 19. MsgCall -> std.AssertOriginCall: pass -## gnokey maketx call -pkgpath std -func AssertOriginCall -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 +## gnokey maketx call -pkgpath std -func AssertOriginCall -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 ## stdout 'OK!' ## 20. MsgRun -> std.AssertOriginCall: PANIC -! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 4000000 -broadcast -chainid tendermint_test test1 $WORK/run/baz.gno +! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 5000000 -broadcast -chainid tendermint_test test1 $WORK/run/baz.gno stderr 'invalid non-origin call' From b1a9b8b893dd4f309948a86c1fb2094f3d2ad4ba Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Fri, 29 Nov 2024 00:27:05 +0100 Subject: [PATCH 09/37] fix: tests --- gno.land/cmd/gnoland/testdata/grc20_registry.txtar | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/grc20_registry.txtar b/gno.land/cmd/gnoland/testdata/grc20_registry.txtar index a5f7ad5eee3..417ab04539d 100644 --- a/gno.land/cmd/gnoland/testdata/grc20_registry.txtar +++ b/gno.land/cmd/gnoland/testdata/grc20_registry.txtar @@ -6,15 +6,15 @@ loadpkg gno.land/r/registry $WORK/registry gnoland start # we call Transfer with foo20, before it's registered -gnokey maketx call -pkgpath gno.land/r/registry -func TransferByName -args 'foo20' -args 'g123456789' -args '42' -gas-fee 1000000ugnot -gas-wanted 4000000 -broadcast -chainid=tendermint_test test1 +gnokey maketx call -pkgpath gno.land/r/registry -func TransferByName -args 'foo20' -args 'g123456789' -args '42' -gas-fee 1000000ugnot -gas-wanted 5000000 -broadcast -chainid=tendermint_test test1 stdout 'not found' # add foo20, and foo20wrapper -gnokey maketx addpkg -pkgdir $WORK/foo20 -pkgpath gno.land/r/foo20 -gas-fee 1000000ugnot -gas-wanted 4000000 -broadcast -chainid=tendermint_test test1 -gnokey maketx addpkg -pkgdir $WORK/foo20wrapper -pkgpath gno.land/r/foo20wrapper -gas-fee 1000000ugnot -gas-wanted 4000000 -broadcast -chainid=tendermint_test test1 +gnokey maketx addpkg -pkgdir $WORK/foo20 -pkgpath gno.land/r/foo20 -gas-fee 1000000ugnot -gas-wanted 5000000 -broadcast -chainid=tendermint_test test1 +gnokey maketx addpkg -pkgdir $WORK/foo20wrapper -pkgpath gno.land/r/foo20wrapper -gas-fee 1000000ugnot -gas-wanted 5000000 -broadcast -chainid=tendermint_test test1 # we call Transfer with foo20, after it's registered -gnokey maketx call -pkgpath gno.land/r/registry -func TransferByName -args 'foo20' -args 'g123456789' -args '42' -gas-fee 1000000ugnot -gas-wanted 4000000 -broadcast -chainid=tendermint_test test1 +gnokey maketx call -pkgpath gno.land/r/registry -func TransferByName -args 'foo20' -args 'g123456789' -args '42' -gas-fee 1000000ugnot -gas-wanted 5000000 -broadcast -chainid=tendermint_test test1 stdout 'same address, success!' -- registry/registry.gno -- From f2c3ed10b813afdc10c4ae78231dbb6917b209ec Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Fri, 29 Nov 2024 01:16:34 +0100 Subject: [PATCH 10/37] fix: fix regex by adding starting & ending char + add tests --- .../realm_banker_issued_coin_denom.txtar | 36 +++++++++++++++++++ gnovm/stdlibs/std/banker.gno | 12 ++++--- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar b/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar index fc389bb8308..9da40b20cad 100644 --- a/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar +++ b/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar @@ -12,6 +12,9 @@ gnokey maketx addpkg -pkgdir $WORK/short -pkgpath gno.land/r/test/realm_banker - ## add realm_banker with long package_name gnokey maketx addpkg -pkgdir $WORK/long -pkgpath gno.land/r/test/package89_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_1234567890 -gas-fee 1000000ugnot -gas-wanted 100000000 -broadcast -chainid=tendermint_test test1 +## add invalid realm_denom +gnokey maketx addpkg -pkgdir $WORK/invalid_realm_denom -pkgpath gno.land/r/test/invalid_realm_denom -gas-fee 1000000ugnot -gas-wanted 100000000 -broadcast -chainid=tendermint_test test1 + ## test2 spend all balance gnokey maketx send -send "9999999ugnot" -to g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5 -gas-fee 1ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test2 @@ -52,6 +55,22 @@ gnokey maketx call -pkgpath gno.land/r/test/package89_123456789_123456789_123456 gnokey query bank/balances/g1cq2ecdq3eyn5qa0fzznpurg87zq3k77g63q6u7 stdout '"100/gno.land/r/test/package89_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_1234567890:ugnot"' +## mint invalid base denom +! gnokey maketx call -pkgpath gno.land/r/test/realm_banker -func Mint -args "g1cq2ecdq3eyn5qa0fzznpurg87zq3k77g63q6u7" -args "2gnot" -args "100" -gas-fee 1000000ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1 +stderr 'cannot issue coins with invalid denom name, it should start by a lowercase letter and be followed by 2-15 lowercase letters or digits' + +## burn invalid base denom +! gnokey maketx call -pkgpath gno.land/r/test/realm_banker -func Burn -args "g1cq2ecdq3eyn5qa0fzznpurg87zq3k77g63q6u7" -args "2gnot" -args "100" -gas-fee 1000000ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1 +stderr 'cannot issue coins with invalid denom name, it should start by a lowercase letter and be followed by 2-15 lowercase letters or digits' + +## mint invalid realm denom +! gnokey maketx call -pkgpath gno.land/r/test/invalid_realm_denom -func Mint -args "g1cq2ecdq3eyn5qa0fzznpurg87zq3k77g63q6u7" -args "ugnot" -args "100" -gas-fee 1000000ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1 +stderr 'cannot issue coins with denom not prefixed by current realm pkgPath' + +## burn invalid realm denom +! gnokey maketx call -pkgpath gno.land/r/test/invalid_realm_denom -func Burn -args "g1cq2ecdq3eyn5qa0fzznpurg87zq3k77g63q6u7" -args "ugnot" -args "100" -gas-fee 1000000ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1 +stderr 'cannot issue coins with denom not prefixed by current realm pkgPath' + -- short/realm_banker.gno -- package realm_banker @@ -85,4 +104,21 @@ func Mint(addr std.Address, denom string, amount int64) { func Burn(addr std.Address, denom string, amount int64) { banker := std.GetBanker(std.BankerTypeRealmIssue) banker.RemoveCoin(addr, std.CurrentRealm().Denom(denom), amount) +} + +-- invalid_realm_denom/realm_banker.gno -- +package invalid_realm_denom + +import ( + "std" +) + +func Mint(addr std.Address, denom string, amount int64) { + banker := std.GetBanker(std.BankerTypeRealmIssue) + banker.IssueCoin(addr, denom, amount) +} + +func Burn(addr std.Address, denom string, amount int64) { + banker := std.GetBanker(std.BankerTypeRealmIssue) + banker.RemoveCoin(addr, denom, amount) } \ No newline at end of file diff --git a/gnovm/stdlibs/std/banker.gno b/gnovm/stdlibs/std/banker.gno index e67f4a6d07f..7ca80bbde23 100644 --- a/gnovm/stdlibs/std/banker.gno +++ b/gnovm/stdlibs/std/banker.gno @@ -62,7 +62,7 @@ func (b BankerType) String() string { } // regexp for denom format -var reDenom = regexp.MustCompile("[a-z][a-z0-9]{2,15}") +var reDenom = regexp.MustCompile(`^[a-z][a-z0-9]{2,15}$`) //---------------------------------------- // adapter for native banker @@ -132,11 +132,12 @@ func (b banker) IssueCoin(addr Address, denom string, amount int64) { panic(b.bt.String() + " cannot issue coins") } - if !strings.HasPrefix(denom, PrevRealm().PkgPath()) { + prefix := "/" + CurrentRealm().PkgPath() + ":" + if !strings.HasPrefix(denom, prefix) { 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") } - baseDenom := strings.TrimPrefix(denom, PrevRealm().PkgPath()) + baseDenom := strings.TrimPrefix(denom, prefix) 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") } @@ -149,11 +150,12 @@ func (b banker) RemoveCoin(addr Address, denom string, amount int64) { panic(b.bt.String() + " cannot remove coins") } - if !strings.HasPrefix(denom, PrevRealm().PkgPath()) { + prefix := "/" + CurrentRealm().PkgPath() + ":" + if !strings.HasPrefix(denom, prefix) { 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") } - baseDenom := strings.TrimPrefix(denom, PrevRealm().PkgPath()) + baseDenom := strings.TrimPrefix(denom, prefix) 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") } From de1d78b7be5a365c57098274c1a6ede33e1a0c3d Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Fri, 29 Nov 2024 11:17:38 +0100 Subject: [PATCH 11/37] fix: test --- gnovm/tests/files/zrealm_natbind0.gno | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/tests/files/zrealm_natbind0.gno b/gnovm/tests/files/zrealm_natbind0.gno index 6baf4a055e7..013806347dd 100644 --- a/gnovm/tests/files/zrealm_natbind0.gno +++ b/gnovm/tests/files/zrealm_natbind0.gno @@ -69,7 +69,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "a7f5397443359ea76c50be82c77f1f893a060925:47" +// "ObjectID": "a7f5397443359ea76c50be82c77f1f893a060925:178" // }, // "FileName": "native.gno", // "IsMethod": false, From 9c14a1fc394fec02fd6ec90fc15dbfc6a907ba5e Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Fri, 29 Nov 2024 14:56:57 +0100 Subject: [PATCH 12/37] fix: refactor assertDenom to follow DRY principles --- gnovm/stdlibs/std/banker.gno | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/gnovm/stdlibs/std/banker.gno b/gnovm/stdlibs/std/banker.gno index 7ca80bbde23..fa2e8f4da03 100644 --- a/gnovm/stdlibs/std/banker.gno +++ b/gnovm/stdlibs/std/banker.gno @@ -131,17 +131,7 @@ func (b banker) IssueCoin(addr Address, denom string, amount int64) { if b.bt != BankerTypeRealmIssue { panic(b.bt.String() + " cannot issue coins") } - - prefix := "/" + CurrentRealm().PkgPath() + ":" - if !strings.HasPrefix(denom, prefix) { - 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") - } - - baseDenom := strings.TrimPrefix(denom, prefix) - 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") - } - + assertRealmDenom(denom) bankerIssueCoin(uint8(b.bt), string(addr), denom, amount) } @@ -149,16 +139,18 @@ func (b banker) RemoveCoin(addr Address, denom string, amount int64) { if b.bt != BankerTypeRealmIssue { panic(b.bt.String() + " cannot remove coins") } + assertRealmDenom(denom) + bankerRemoveCoin(uint8(b.bt), string(addr), denom, amount) +} +func assertRealmDenom(denom string) { prefix := "/" + CurrentRealm().PkgPath() + ":" if !strings.HasPrefix(denom, prefix) { - 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") + panic("cannot issue coins with denom not prefixed by / + std.CurrentRealm().PkgPath() + :, take a look at std.CurrentRealm().Denom() function") } baseDenom := strings.TrimPrefix(denom, prefix) 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") + panic("cannot issue coins with invalid denom base 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) } From daf9d8e971976fa3ae8e6d4f94db785b35c03e24 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Mon, 2 Dec 2024 10:47:12 +0100 Subject: [PATCH 13/37] chore: rename denom functions --- .../cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar | 4 ++-- gnovm/stdlibs/std/frame.gno | 4 ++-- gnovm/stdlibs/std/native.gno | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar b/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar index 9da40b20cad..3b1a5067656 100644 --- a/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar +++ b/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar @@ -98,12 +98,12 @@ import ( func Mint(addr std.Address, denom string, amount int64) { banker := std.GetBanker(std.BankerTypeRealmIssue) - banker.IssueCoin(addr, std.CurrentRealm().Denom(denom), amount) + banker.IssueCoin(addr, std.CurrentRealm().ComposeDenom(denom), amount) } func Burn(addr std.Address, denom string, amount int64) { banker := std.GetBanker(std.BankerTypeRealmIssue) - banker.RemoveCoin(addr, std.CurrentRealm().Denom(denom), amount) + banker.RemoveCoin(addr, std.CurrentRealm().ComposeDenom(denom), amount) } -- invalid_realm_denom/realm_banker.gno -- diff --git a/gnovm/stdlibs/std/frame.gno b/gnovm/stdlibs/std/frame.gno index 87ffb5892fb..a4d4080d4d0 100644 --- a/gnovm/stdlibs/std/frame.gno +++ b/gnovm/stdlibs/std/frame.gno @@ -17,6 +17,6 @@ func (r Realm) IsUser() bool { return r.pkgPath == "" } -func (r Realm) Denom(denom string) string { - return RealmDenom(r.pkgPath, denom) +func (r Realm) ComposeDenom(denom string) string { + return ComposeRealmDenom(r.pkgPath, denom) } diff --git a/gnovm/stdlibs/std/native.gno b/gnovm/stdlibs/std/native.gno index d1d0039fa80..4db4696b410 100644 --- a/gnovm/stdlibs/std/native.gno +++ b/gnovm/stdlibs/std/native.gno @@ -56,7 +56,7 @@ func DecodeBech32(addr Address) (prefix string, bz [20]byte, ok bool) { return decodeBech32(string(addr)) } -func RealmDenom(pkgPath, denom string) string { +func ComposeRealmDenom(pkgPath, denom string) string { // Similar to ibc spec // ibc_denom := 'ibc/' + hash('path' + 'base_denom') // gno_realm_denom := '/' + 'pkg_path' + ':' + 'base_denom' From 4e4f3e9c1e677cb9a42819e4be85c9d35c5b2429 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Mon, 2 Dec 2024 10:50:19 +0100 Subject: [PATCH 14/37] chore: update error message with new functions names --- gnovm/stdlibs/std/banker.gno | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/stdlibs/std/banker.gno b/gnovm/stdlibs/std/banker.gno index fa2e8f4da03..b23d03df4bf 100644 --- a/gnovm/stdlibs/std/banker.gno +++ b/gnovm/stdlibs/std/banker.gno @@ -146,7 +146,7 @@ func (b banker) RemoveCoin(addr Address, denom string, amount int64) { func assertRealmDenom(denom string) { prefix := "/" + CurrentRealm().PkgPath() + ":" if !strings.HasPrefix(denom, prefix) { - panic("cannot issue coins with denom not prefixed by / + std.CurrentRealm().PkgPath() + :, take a look at std.CurrentRealm().Denom() function") + panic("cannot issue coins with denom not prefixed by / + std.CurrentRealm().PkgPath() + :, take a look at std.CurrentRealm().ComposeDenom() function") } baseDenom := strings.TrimPrefix(denom, prefix) From 714fca37a6433dbef7b7afd81eb31f2160cd02c7 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Mon, 2 Dec 2024 10:59:02 +0100 Subject: [PATCH 15/37] chore: update error message with new functions names --- .../testdata/realm_banker_issued_coin_denom.txtar | 12 ++++++------ gnovm/stdlibs/std/banker.gno | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar b/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar index 3b1a5067656..7a51df68628 100644 --- a/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar +++ b/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar @@ -57,19 +57,19 @@ stdout '"100/gno.land/r/test/package89_123456789_123456789_123456789_123456789_1 ## mint invalid base denom ! gnokey maketx call -pkgpath gno.land/r/test/realm_banker -func Mint -args "g1cq2ecdq3eyn5qa0fzznpurg87zq3k77g63q6u7" -args "2gnot" -args "100" -gas-fee 1000000ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1 -stderr 'cannot issue coins with invalid denom name, it should start by a lowercase letter and be followed by 2-15 lowercase letters or digits' +stderr 'cannot issue coins with invalid denom base name, it should start by a lowercase letter and be followed by 2-15 lowercase letters or digits' ## burn invalid base denom ! gnokey maketx call -pkgpath gno.land/r/test/realm_banker -func Burn -args "g1cq2ecdq3eyn5qa0fzznpurg87zq3k77g63q6u7" -args "2gnot" -args "100" -gas-fee 1000000ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1 -stderr 'cannot issue coins with invalid denom name, it should start by a lowercase letter and be followed by 2-15 lowercase letters or digits' +stderr 'cannot issue coins with invalid denom base name, it should start by a lowercase letter and be followed by 2-15 lowercase letters or digits' ## mint invalid realm denom ! gnokey maketx call -pkgpath gno.land/r/test/invalid_realm_denom -func Mint -args "g1cq2ecdq3eyn5qa0fzznpurg87zq3k77g63q6u7" -args "ugnot" -args "100" -gas-fee 1000000ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1 -stderr 'cannot issue coins with denom not prefixed by current realm pkgPath' +stderr 'cannot issue coins with denom not prefixed by: /realmPath:' ## burn invalid realm denom ! gnokey maketx call -pkgpath gno.land/r/test/invalid_realm_denom -func Burn -args "g1cq2ecdq3eyn5qa0fzznpurg87zq3k77g63q6u7" -args "ugnot" -args "100" -gas-fee 1000000ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1 -stderr 'cannot issue coins with denom not prefixed by current realm pkgPath' +stderr 'cannot issue coins with denom not prefixed by: /realmPath:' -- short/realm_banker.gno -- package realm_banker @@ -80,12 +80,12 @@ import ( func Mint(addr std.Address, denom string, amount int64) { banker := std.GetBanker(std.BankerTypeRealmIssue) - banker.IssueCoin(addr, std.CurrentRealm().Denom(denom), amount) + banker.IssueCoin(addr, std.CurrentRealm().ComposeDenom(denom), amount) } func Burn(addr std.Address, denom string, amount int64) { banker := std.GetBanker(std.BankerTypeRealmIssue) - banker.RemoveCoin(addr, std.CurrentRealm().Denom(denom), amount) + banker.RemoveCoin(addr, std.CurrentRealm().ComposeDenom(denom), amount) } -- long/realm_banker.gno -- diff --git a/gnovm/stdlibs/std/banker.gno b/gnovm/stdlibs/std/banker.gno index b23d03df4bf..d34c7279ac9 100644 --- a/gnovm/stdlibs/std/banker.gno +++ b/gnovm/stdlibs/std/banker.gno @@ -146,7 +146,7 @@ func (b banker) RemoveCoin(addr Address, denom string, amount int64) { func assertRealmDenom(denom string) { prefix := "/" + CurrentRealm().PkgPath() + ":" if !strings.HasPrefix(denom, prefix) { - panic("cannot issue coins with denom not prefixed by / + std.CurrentRealm().PkgPath() + :, take a look at std.CurrentRealm().ComposeDenom() function") + panic("cannot issue coins with denom not prefixed by: /realmPath:") } baseDenom := strings.TrimPrefix(denom, prefix) From fae0a3a425190d06bd4bb3d7664514e91d0e179c Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Mon, 2 Dec 2024 11:35:08 +0100 Subject: [PATCH 16/37] docs: update doc with new informations --- docs/reference/stdlibs/std/banker.md | 3 +++ docs/reference/stdlibs/std/chain.md | 18 ++++++++++++++++++ docs/reference/stdlibs/std/realm.md | 12 ++++++++++++ gnovm/stdlibs/std/native.gno | 14 +++++++------- 4 files changed, 40 insertions(+), 7 deletions(-) diff --git a/docs/reference/stdlibs/std/banker.md b/docs/reference/stdlibs/std/banker.md index 71eb3709ea2..e63fc9302c1 100644 --- a/docs/reference/stdlibs/std/banker.md +++ b/docs/reference/stdlibs/std/banker.md @@ -38,6 +38,9 @@ Returns `Banker` of the specified type. ```go banker := std.GetBanker(std.) ``` + +⚠️ Methods of `Banker` expect full denomination of the coins, [see more here](#chain.md#composerealmdenom). + --- ## GetCoins diff --git a/docs/reference/stdlibs/std/chain.md b/docs/reference/stdlibs/std/chain.md index 089de682cfd..70d4c0e05aa 100644 --- a/docs/reference/stdlibs/std/chain.md +++ b/docs/reference/stdlibs/std/chain.md @@ -150,3 +150,21 @@ Derives the Realm address from its `pkgpath` parameter. ```go realmAddr := std.DerivePkgAddr("gno.land/r/demo/tamagotchi") // g1a3tu874agjlkrpzt9x90xv3uzncapcn959yte4 ``` + +--- + +## ComposeRealmDenom +```go +func ComposeRealmDenom(pkgPath, denom string) string +``` + +Composes a denomination string from the realm's pkg path and the provided denomination. e.g `/gno.land/r/demo/blog:ugnot`. This method should be used when interacting with the `Banker` interface. It can also be used as a method of the `Realm` object, see [here](realm.md#composedenom). + +#### Parameters +- `pkgPath` **string** - package path of the realm +- `denom` **string** - denomination to compose with the realm's pkg path + +#### Usage +```go +denom := std.ComposeRealmDenom("gno.land/r/demo/blog", "ugnot") +``` \ No newline at end of file diff --git a/docs/reference/stdlibs/std/realm.md b/docs/reference/stdlibs/std/realm.md index 0c99b7134ea..4505e54bf13 100644 --- a/docs/reference/stdlibs/std/realm.md +++ b/docs/reference/stdlibs/std/realm.md @@ -14,6 +14,7 @@ type Realm struct { func (r Realm) Addr() Address {...} func (r Realm) PkgPath() string {...} func (r Realm) IsUser() bool {...} +func (r Realm) ComposeDenom(denom string) string {...} ``` ## Addr @@ -39,3 +40,14 @@ Checks if the realm it was called upon is a user realm. ```go if r.IsUser() {...} ``` + +## ComposeDenom +Composes a denomination string from the realm's pkg path and the provided denomination. e.g `/gno.land/r/demo/blog:ugnot`. This method should be used when interacting with the `Banker` interface. + +#### Parameters +- `denom` **string** - denomination to compose with the realm's pkg path + +#### Usage +```go +denom := r.ComposeDenom("ugnot") +``` diff --git a/gnovm/stdlibs/std/native.gno b/gnovm/stdlibs/std/native.gno index 4db4696b410..fd68628e3a1 100644 --- a/gnovm/stdlibs/std/native.gno +++ b/gnovm/stdlibs/std/native.gno @@ -48,6 +48,13 @@ func DerivePkgAddr(pkgPath string) Address { return Address(derivePkgAddr(pkgPath)) } +func ComposeRealmDenom(pkgPath, denom string) string { + // Similar to ibc spec + // ibc_denom := 'ibc/' + hash('path' + 'base_denom') + // gno_realm_denom := '/' + 'pkg_path' + ':' + 'base_denom' + return "/" + pkgPath + ":" + denom +} + func EncodeBech32(prefix string, bz [20]byte) Address { return Address(encodeBech32(prefix, bz)) } @@ -56,13 +63,6 @@ func DecodeBech32(addr Address) (prefix string, bz [20]byte, ok bool) { return decodeBech32(string(addr)) } -func ComposeRealmDenom(pkgPath, denom string) string { - // Similar to ibc spec - // ibc_denom := 'ibc/' + hash('path' + 'base_denom') - // gno_realm_denom := '/' + 'pkg_path' + ':' + 'base_denom' - return "/" + pkgPath + ":" + denom -} - // Variations which don't use named types. func origSend() (denoms []string, amounts []int64) func origCaller() string From a9fe4d58f4af336f65f094c572d3ea040d143513 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Mon, 2 Dec 2024 17:02:16 +0100 Subject: [PATCH 17/37] docs: lint add newline at end of the file --- docs/reference/stdlibs/std/chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/stdlibs/std/chain.md b/docs/reference/stdlibs/std/chain.md index 70d4c0e05aa..b0d50babf5a 100644 --- a/docs/reference/stdlibs/std/chain.md +++ b/docs/reference/stdlibs/std/chain.md @@ -167,4 +167,4 @@ Composes a denomination string from the realm's pkg path and the provided denomi #### Usage ```go denom := std.ComposeRealmDenom("gno.land/r/demo/blog", "ugnot") -``` \ No newline at end of file +``` From f72599111f4a2d39f187fda751ba5b9000d5a7fb Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Mon, 2 Dec 2024 17:03:23 +0100 Subject: [PATCH 18/37] fix: gno test update output expected --- gnovm/tests/files/std5.gno | 2 +- gnovm/tests/files/std8.gno | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gnovm/tests/files/std5.gno b/gnovm/tests/files/std5.gno index 5070d13c42c..a8116509326 100644 --- a/gnovm/tests/files/std5.gno +++ b/gnovm/tests/files/std5.gno @@ -13,7 +13,7 @@ func main() { // Stacktrace: // panic: frame not found -// callerAt(n) +// callerAt(n) // gonative:std.callerAt // std.GetCallerAt(2) // std/native.gno:44 diff --git a/gnovm/tests/files/std8.gno b/gnovm/tests/files/std8.gno index 0ba203b00e1..fd478704537 100644 --- a/gnovm/tests/files/std8.gno +++ b/gnovm/tests/files/std8.gno @@ -23,7 +23,7 @@ func main() { // Stacktrace: // panic: frame not found -// callerAt(n) +// callerAt(n) // gonative:std.callerAt // std.GetCallerAt(4) // std/native.gno:44 From 903e06efb14e905d2620eaaace69f4f8249654da Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Mon, 9 Dec 2024 14:18:01 +0100 Subject: [PATCH 19/37] fix: revert denom nomenclature & add helper function instead of regexp --- .../realm_banker_issued_coin_denom.txtar | 12 ++++----- gnovm/stdlibs/std/banker.gno | 26 ++++++++++++++++--- gnovm/stdlibs/std/frame.gno | 11 ++++++-- gnovm/stdlibs/std/native.gno | 7 ----- 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar b/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar index 7a51df68628..2239fc8698f 100644 --- a/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar +++ b/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar @@ -65,11 +65,11 @@ stderr 'cannot issue coins with invalid denom base name, it should start by a lo ## mint invalid realm denom ! gnokey maketx call -pkgpath gno.land/r/test/invalid_realm_denom -func Mint -args "g1cq2ecdq3eyn5qa0fzznpurg87zq3k77g63q6u7" -args "ugnot" -args "100" -gas-fee 1000000ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1 -stderr 'cannot issue coins with denom not prefixed by: /realmPath:' +stderr 'cannot issue coins with denom not prefixed by: / + std.CurrentRealm.PkgPath() + :' ## burn invalid realm denom ! gnokey maketx call -pkgpath gno.land/r/test/invalid_realm_denom -func Burn -args "g1cq2ecdq3eyn5qa0fzznpurg87zq3k77g63q6u7" -args "ugnot" -args "100" -gas-fee 1000000ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1 -stderr 'cannot issue coins with denom not prefixed by: /realmPath:' +stderr 'cannot issue coins with denom not prefixed by: / + std.CurrentRealm.PkgPath() + :' -- short/realm_banker.gno -- package realm_banker @@ -80,12 +80,12 @@ import ( func Mint(addr std.Address, denom string, amount int64) { banker := std.GetBanker(std.BankerTypeRealmIssue) - banker.IssueCoin(addr, std.CurrentRealm().ComposeDenom(denom), amount) + banker.IssueCoin(addr, std.CurrentRealm().Denom(denom), amount) } func Burn(addr std.Address, denom string, amount int64) { banker := std.GetBanker(std.BankerTypeRealmIssue) - banker.RemoveCoin(addr, std.CurrentRealm().ComposeDenom(denom), amount) + banker.RemoveCoin(addr, std.CurrentRealm().Denom(denom), amount) } -- long/realm_banker.gno -- @@ -98,12 +98,12 @@ import ( func Mint(addr std.Address, denom string, amount int64) { banker := std.GetBanker(std.BankerTypeRealmIssue) - banker.IssueCoin(addr, std.CurrentRealm().ComposeDenom(denom), amount) + banker.IssueCoin(addr, std.CurrentRealm().Denom(denom), amount) } func Burn(addr std.Address, denom string, amount int64) { banker := std.GetBanker(std.BankerTypeRealmIssue) - banker.RemoveCoin(addr, std.CurrentRealm().ComposeDenom(denom), amount) + banker.RemoveCoin(addr, std.CurrentRealm().Denom(denom), amount) } -- invalid_realm_denom/realm_banker.gno -- diff --git a/gnovm/stdlibs/std/banker.gno b/gnovm/stdlibs/std/banker.gno index d34c7279ac9..07b381255b1 100644 --- a/gnovm/stdlibs/std/banker.gno +++ b/gnovm/stdlibs/std/banker.gno @@ -146,11 +146,31 @@ func (b banker) RemoveCoin(addr Address, denom string, amount int64) { func assertRealmDenom(denom string) { prefix := "/" + CurrentRealm().PkgPath() + ":" if !strings.HasPrefix(denom, prefix) { - panic("cannot issue coins with denom not prefixed by: /realmPath:") + panic("cannot issue coins with denom not prefixed by: / + std.CurrentRealm.PkgPath() + :") } - baseDenom := strings.TrimPrefix(denom, prefix) - if !reDenom.MatchString(baseDenom) { + baseDenom := denom[len(prefix):] + if !isValidBaseDenom(baseDenom) { panic("cannot issue coins with invalid denom base name, it should start by a lowercase letter and be followed by 2-15 lowercase letters or digits") } } + +// check start by a lowercase letter and be followed by 2-15 lowercase letters or digits +func isValidBaseDenom(denom string) bool { + length := len(denom) + if length < 3 || length > 16 { + return false + } + for i, c := range denom { + if i == 0 { + if c < 'a' || c > 'z' { + return false + } + } else { + if (c < 'a' || c > 'z') && (c < '0' || c > '9') { + return false + } + } + } + return true +} diff --git a/gnovm/stdlibs/std/frame.gno b/gnovm/stdlibs/std/frame.gno index a4d4080d4d0..216f12c6f17 100644 --- a/gnovm/stdlibs/std/frame.gno +++ b/gnovm/stdlibs/std/frame.gno @@ -17,6 +17,13 @@ func (r Realm) IsUser() bool { return r.pkgPath == "" } -func (r Realm) ComposeDenom(denom string) string { - return ComposeRealmDenom(r.pkgPath, denom) +func (r Realm) Denom(denom string) string { + return RealmDenom(r.pkgPath, denom) +} + +func RealmDenom(pkgPath, denom string) string { + // Similar to ibc spec + // ibc_denom := 'ibc/' + hash('path' + 'base_denom') + // gno_realm_denom := '/' + 'pkg_path' + ':' + 'base_denom' + return "/" + pkgPath + ":" + denom } diff --git a/gnovm/stdlibs/std/native.gno b/gnovm/stdlibs/std/native.gno index 7f1cf8db1ca..0dcde1148e1 100644 --- a/gnovm/stdlibs/std/native.gno +++ b/gnovm/stdlibs/std/native.gno @@ -49,13 +49,6 @@ func DerivePkgAddr(pkgPath string) Address { return Address(derivePkgAddr(pkgPath)) } -func ComposeRealmDenom(pkgPath, denom string) string { - // Similar to ibc spec - // ibc_denom := 'ibc/' + hash('path' + 'base_denom') - // gno_realm_denom := '/' + 'pkg_path' + ':' + 'base_denom' - return "/" + pkgPath + ":" + denom -} - func EncodeBech32(prefix string, bz [20]byte) Address { return Address(encodeBech32(prefix, bz)) } From efb8a389f18985a06bea9e1b1c4fa4f1cf4ed4f5 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Mon, 9 Dec 2024 14:33:32 +0100 Subject: [PATCH 20/37] docs: use term qualified documentation and move function into realm section --- docs/reference/stdlibs/std/banker.md | 2 +- docs/reference/stdlibs/std/chain.md | 18 ------------------ docs/reference/stdlibs/std/realm.md | 21 ++++++++++++++++++++- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/docs/reference/stdlibs/std/banker.md b/docs/reference/stdlibs/std/banker.md index e63fc9302c1..41975396e95 100644 --- a/docs/reference/stdlibs/std/banker.md +++ b/docs/reference/stdlibs/std/banker.md @@ -39,7 +39,7 @@ Returns `Banker` of the specified type. banker := std.GetBanker(std.) ``` -⚠️ Methods of `Banker` expect full denomination of the coins, [see more here](#chain.md#composerealmdenom). +⚠️ Methods of `Banker` expect qualified denomination of the coins, [see more here](#realm.md#composerealmdenom). --- diff --git a/docs/reference/stdlibs/std/chain.md b/docs/reference/stdlibs/std/chain.md index e2807ef2720..b1791e65608 100644 --- a/docs/reference/stdlibs/std/chain.md +++ b/docs/reference/stdlibs/std/chain.md @@ -162,21 +162,3 @@ Derives the Realm address from its `pkgpath` parameter. ```go realmAddr := std.DerivePkgAddr("gno.land/r/demo/tamagotchi") // g1a3tu874agjlkrpzt9x90xv3uzncapcn959yte4 ``` - ---- - -## ComposeRealmDenom -```go -func ComposeRealmDenom(pkgPath, denom string) string -``` - -Composes a denomination string from the realm's pkg path and the provided denomination. e.g `/gno.land/r/demo/blog:ugnot`. This method should be used when interacting with the `Banker` interface. It can also be used as a method of the `Realm` object, see [here](realm.md#composedenom). - -#### Parameters -- `pkgPath` **string** - package path of the realm -- `denom` **string** - denomination to compose with the realm's pkg path - -#### Usage -```go -denom := std.ComposeRealmDenom("gno.land/r/demo/blog", "ugnot") -``` diff --git a/docs/reference/stdlibs/std/realm.md b/docs/reference/stdlibs/std/realm.md index 4505e54bf13..cad7a337186 100644 --- a/docs/reference/stdlibs/std/realm.md +++ b/docs/reference/stdlibs/std/realm.md @@ -42,7 +42,7 @@ if r.IsUser() {...} ``` ## ComposeDenom -Composes a denomination string from the realm's pkg path and the provided denomination. e.g `/gno.land/r/demo/blog:ugnot`. This method should be used when interacting with the `Banker` interface. +Composes a qualified denomination string from the realm's pkg path and the provided base denomination. e.g `/gno.land/r/demo/blog:ugnot`. This method should be used when interacting with the `Banker` interface. #### Parameters - `denom` **string** - denomination to compose with the realm's pkg path @@ -51,3 +51,22 @@ Composes a denomination string from the realm's pkg path and the provided denomi ```go denom := r.ComposeDenom("ugnot") ``` + +--- + +## ComposeRealmDenom +```go +func ComposeRealmDenom(pkgPath, denom string) string +``` + +Composes a qualified denomination string from the realm's pkg path and the provided base denomination. e.g `/gno.land/r/demo/blog:ugnot`. This method should be used when interacting with the `Banker` interface. It can also be used as a method of the `Realm` object, see [Realm.Denom](realm.md#composedenom). + +#### Parameters +- `pkgPath` **string** - package path of the realm +- `denom` **string** - denomination to compose with the realm's pkg path + +#### Usage +```go +denom := std.ComposeRealmDenom("gno.land/r/demo/blog", "ugnot") +``` + From 66161582c751fa47bdd8a937b4f10d242013ed45 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Mon, 9 Dec 2024 14:40:23 +0100 Subject: [PATCH 21/37] docs: adapt to new nomenclature --- docs/reference/stdlibs/std/banker.md | 2 +- docs/reference/stdlibs/std/realm.md | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/reference/stdlibs/std/banker.md b/docs/reference/stdlibs/std/banker.md index 41975396e95..27e55c3b018 100644 --- a/docs/reference/stdlibs/std/banker.md +++ b/docs/reference/stdlibs/std/banker.md @@ -39,7 +39,7 @@ Returns `Banker` of the specified type. banker := std.GetBanker(std.) ``` -⚠️ Methods of `Banker` expect qualified denomination of the coins, [see more here](#realm.md#composerealmdenom). +⚠️ Methods of `Banker` expect qualified denomination of the coins, [see more here](#realm.md#realmdenom). --- diff --git a/docs/reference/stdlibs/std/realm.md b/docs/reference/stdlibs/std/realm.md index cad7a337186..c29df3c6b4c 100644 --- a/docs/reference/stdlibs/std/realm.md +++ b/docs/reference/stdlibs/std/realm.md @@ -41,32 +41,32 @@ Checks if the realm it was called upon is a user realm. if r.IsUser() {...} ``` -## ComposeDenom +## Denom Composes a qualified denomination string from the realm's pkg path and the provided base denomination. e.g `/gno.land/r/demo/blog:ugnot`. This method should be used when interacting with the `Banker` interface. #### Parameters -- `denom` **string** - denomination to compose with the realm's pkg path +- `denom` **string** - The base denomination used to build the qualified denomination. Must start with a lowercase letter, followed by 2–15 lowercase letters or digits. #### Usage ```go -denom := r.ComposeDenom("ugnot") +denom := r.Denom("ugnot") ``` --- -## ComposeRealmDenom +## RealmDenom ```go -func ComposeRealmDenom(pkgPath, denom string) string +func RealmDenom(pkgPath, denom string) string ``` -Composes a qualified denomination string from the realm's pkg path and the provided base denomination. e.g `/gno.land/r/demo/blog:ugnot`. This method should be used when interacting with the `Banker` interface. It can also be used as a method of the `Realm` object, see [Realm.Denom](realm.md#composedenom). +Composes a qualified denomination string from the realm's pkg path and the provided base denomination. e.g `/gno.land/r/demo/blog:ugnot`. This method should be used when interacting with the `Banker` interface. It can also be used as a method of the `Realm` object, see [Realm.Denom](realm.md#denom). #### Parameters - `pkgPath` **string** - package path of the realm -- `denom` **string** - denomination to compose with the realm's pkg path +- `denom` **string** - The base denomination used to build the qualified denomination. Must start with a lowercase letter, followed by 2–15 lowercase letters or digits. #### Usage ```go -denom := std.ComposeRealmDenom("gno.land/r/demo/blog", "ugnot") +denom := std.RealmDenom("gno.land/r/demo/blog", "ugnot") ``` From f59f49e1070db9cd3be8748c89a2c0da92df7afa Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Mon, 9 Dec 2024 14:42:10 +0100 Subject: [PATCH 22/37] docs: fix forgotten mistake --- docs/reference/stdlibs/std/realm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/stdlibs/std/realm.md b/docs/reference/stdlibs/std/realm.md index c29df3c6b4c..e6c24fc416c 100644 --- a/docs/reference/stdlibs/std/realm.md +++ b/docs/reference/stdlibs/std/realm.md @@ -14,7 +14,7 @@ type Realm struct { func (r Realm) Addr() Address {...} func (r Realm) PkgPath() string {...} func (r Realm) IsUser() bool {...} -func (r Realm) ComposeDenom(denom string) string {...} +func (r Realm) Denom(denom string) string {...} ``` ## Addr From 0cafb107dee287e00bb9f664c649cb46358ba4f3 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Mon, 9 Dec 2024 14:45:36 +0100 Subject: [PATCH 23/37] fix: remove unused regexp --- gnovm/stdlibs/std/banker.gno | 4 ---- 1 file changed, 4 deletions(-) diff --git a/gnovm/stdlibs/std/banker.gno b/gnovm/stdlibs/std/banker.gno index 07b381255b1..483d7b0cfca 100644 --- a/gnovm/stdlibs/std/banker.gno +++ b/gnovm/stdlibs/std/banker.gno @@ -1,7 +1,6 @@ package std import ( - "regexp" "strconv" "strings" ) @@ -61,9 +60,6 @@ func (b BankerType) String() string { } } -// regexp for denom format -var reDenom = regexp.MustCompile(`^[a-z][a-z0-9]{2,15}$`) - //---------------------------------------- // adapter for native banker From d8c18c5105b6d60646ecbe8de49e229c135be854 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Mon, 9 Dec 2024 15:12:49 +0100 Subject: [PATCH 24/37] test: fix --- gnovm/tests/files/zrealm_natbind0.gno | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/tests/files/zrealm_natbind0.gno b/gnovm/tests/files/zrealm_natbind0.gno index 013806347dd..8e5f641e734 100644 --- a/gnovm/tests/files/zrealm_natbind0.gno +++ b/gnovm/tests/files/zrealm_natbind0.gno @@ -69,7 +69,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "a7f5397443359ea76c50be82c77f1f893a060925:178" +// "ObjectID": "a7f5397443359ea76c50be82c77f1f893a060925:9" // }, // "FileName": "native.gno", // "IsMethod": false, From d68ef0d23dfa1f9aaafa20d67f55cb5e2ad5a99b Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Mon, 9 Dec 2024 16:49:58 +0100 Subject: [PATCH 25/37] test: fix --- .../cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar | 4 ++-- gnovm/stdlibs/std/banker.gno | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar b/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar index 2239fc8698f..c751753a906 100644 --- a/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar +++ b/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar @@ -65,11 +65,11 @@ stderr 'cannot issue coins with invalid denom base name, it should start by a lo ## mint invalid realm denom ! gnokey maketx call -pkgpath gno.land/r/test/invalid_realm_denom -func Mint -args "g1cq2ecdq3eyn5qa0fzznpurg87zq3k77g63q6u7" -args "ugnot" -args "100" -gas-fee 1000000ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1 -stderr 'cannot issue coins with denom not prefixed by: / + std.CurrentRealm.PkgPath() + :' +stderr 'cannot issue coins with denom not prefixed by: / \+ std.CurrentRealm\(\).PkgPath\(\) \+ :' ## burn invalid realm denom ! gnokey maketx call -pkgpath gno.land/r/test/invalid_realm_denom -func Burn -args "g1cq2ecdq3eyn5qa0fzznpurg87zq3k77g63q6u7" -args "ugnot" -args "100" -gas-fee 1000000ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1 -stderr 'cannot issue coins with denom not prefixed by: / + std.CurrentRealm.PkgPath() + :' +stderr 'cannot issue coins with denom not prefixed by: / \+ std.CurrentRealm\(\).PkgPath\(\) \+ :' -- short/realm_banker.gno -- package realm_banker diff --git a/gnovm/stdlibs/std/banker.gno b/gnovm/stdlibs/std/banker.gno index 483d7b0cfca..eedf170294e 100644 --- a/gnovm/stdlibs/std/banker.gno +++ b/gnovm/stdlibs/std/banker.gno @@ -142,7 +142,7 @@ func (b banker) RemoveCoin(addr Address, denom string, amount int64) { func assertRealmDenom(denom string) { prefix := "/" + CurrentRealm().PkgPath() + ":" if !strings.HasPrefix(denom, prefix) { - panic("cannot issue coins with denom not prefixed by: / + std.CurrentRealm.PkgPath() + :") + panic("cannot issue coins with denom not prefixed by: / + std.CurrentRealm().PkgPath() + :") } baseDenom := denom[len(prefix):] From 70ec4da267f1f2cbd0a8ca938578c826cf1be118 Mon Sep 17 00:00:00 2001 From: Morgan Date: Tue, 10 Dec 2024 16:31:51 +0100 Subject: [PATCH 26/37] Update gnovm/stdlibs/std/frame.gno --- gnovm/stdlibs/std/frame.gno | 1 + 1 file changed, 1 insertion(+) diff --git a/gnovm/stdlibs/std/frame.gno b/gnovm/stdlibs/std/frame.gno index 216f12c6f17..5d309e4b66b 100644 --- a/gnovm/stdlibs/std/frame.gno +++ b/gnovm/stdlibs/std/frame.gno @@ -22,6 +22,7 @@ func (r Realm) Denom(denom string) string { } func RealmDenom(pkgPath, denom string) string { + // TODO: Possibly remove after https://github.com/gnolang/gno/issues/3164 // Similar to ibc spec // ibc_denom := 'ibc/' + hash('path' + 'base_denom') // gno_realm_denom := '/' + 'pkg_path' + ':' + 'base_denom' From 7c6ceb60636b4b766c53f77b9df8d2463c9b51c9 Mon Sep 17 00:00:00 2001 From: Morgan Date: Tue, 10 Dec 2024 16:41:18 +0100 Subject: [PATCH 27/37] Update docs/reference/stdlibs/std/banker.md --- docs/reference/stdlibs/std/banker.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/stdlibs/std/banker.md b/docs/reference/stdlibs/std/banker.md index 27e55c3b018..1bf742495a8 100644 --- a/docs/reference/stdlibs/std/banker.md +++ b/docs/reference/stdlibs/std/banker.md @@ -39,7 +39,7 @@ Returns `Banker` of the specified type. banker := std.GetBanker(std.) ``` -⚠️ Methods of `Banker` expect qualified denomination of the coins, [see more here](#realm.md#realmdenom). +⚠️ Methods of `Banker` expect qualified denomination of the coins, [see more here](./realm.md#realmdenom). --- From 3e491eb1c38dd37438ee3c17dd4d87a528677007 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Tue, 10 Dec 2024 17:01:52 +0100 Subject: [PATCH 28/37] fixup --- gnovm/stdlibs/std/banker.gno | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/gnovm/stdlibs/std/banker.gno b/gnovm/stdlibs/std/banker.gno index eedf170294e..98cfc91f14f 100644 --- a/gnovm/stdlibs/std/banker.gno +++ b/gnovm/stdlibs/std/banker.gno @@ -142,7 +142,7 @@ func (b banker) RemoveCoin(addr Address, denom string, amount int64) { func assertRealmDenom(denom string) { prefix := "/" + CurrentRealm().PkgPath() + ":" if !strings.HasPrefix(denom, prefix) { - panic("cannot issue coins with denom not prefixed by: / + std.CurrentRealm().PkgPath() + :") + panic("invalid denom, can only issue/remove coins with the realm's prefix: " + prefix) } baseDenom := denom[len(prefix):] @@ -158,14 +158,11 @@ func isValidBaseDenom(denom string) bool { return false } for i, c := range denom { - if i == 0 { - if c < 'a' || c > 'z' { - return false - } - } else { - if (c < 'a' || c > 'z') && (c < '0' || c > '9') { - return false - } + switch { + case c >= 'a' && c <= 'z', + i > 0 && (c >= '0' && c <= '9'): // continue + default: + return false } } return true From 7e81bcb98971d265237863329f902af78e0ac1e7 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Tue, 10 Dec 2024 17:29:23 +0100 Subject: [PATCH 29/37] fixup error message --- .../gnoland/testdata/realm_banker_issued_coin_denom.txtar | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar b/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar index c751753a906..97009afa53d 100644 --- a/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar +++ b/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar @@ -65,11 +65,11 @@ stderr 'cannot issue coins with invalid denom base name, it should start by a lo ## mint invalid realm denom ! gnokey maketx call -pkgpath gno.land/r/test/invalid_realm_denom -func Mint -args "g1cq2ecdq3eyn5qa0fzznpurg87zq3k77g63q6u7" -args "ugnot" -args "100" -gas-fee 1000000ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1 -stderr 'cannot issue coins with denom not prefixed by: / \+ std.CurrentRealm\(\).PkgPath\(\) \+ :' +stderr 'invalid denom, can only issue/remove coins with the realm.s prefix' ## burn invalid realm denom ! gnokey maketx call -pkgpath gno.land/r/test/invalid_realm_denom -func Burn -args "g1cq2ecdq3eyn5qa0fzznpurg87zq3k77g63q6u7" -args "ugnot" -args "100" -gas-fee 1000000ugnot -gas-wanted 10000000 -broadcast -chainid=tendermint_test test1 -stderr 'cannot issue coins with denom not prefixed by: / \+ std.CurrentRealm\(\).PkgPath\(\) \+ :' +stderr 'invalid denom, can only issue/remove coins with the realm.s prefix' -- short/realm_banker.gno -- package realm_banker @@ -121,4 +121,4 @@ func Mint(addr std.Address, denom string, amount int64) { func Burn(addr std.Address, denom string, amount int64) { banker := std.GetBanker(std.BankerTypeRealmIssue) banker.RemoveCoin(addr, denom, amount) -} \ No newline at end of file +} From c05e445cca54244d2e6a69e8127ab1425bf524d6 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Thu, 12 Dec 2024 09:25:59 +0100 Subject: [PATCH 30/37] feat: change naming to CoinDenom --- docs/reference/stdlibs/std/banker.md | 3 ++- docs/reference/stdlibs/std/chain.md | 17 ++++++++++++ docs/reference/stdlibs/std/realm.md | 26 ++++--------------- .../realm_banker_issued_coin_denom.txtar | 10 +++---- gnovm/stdlibs/std/banker.gno | 6 ++--- gnovm/stdlibs/std/frame.gno | 10 +++---- 6 files changed, 37 insertions(+), 35 deletions(-) diff --git a/docs/reference/stdlibs/std/banker.md b/docs/reference/stdlibs/std/banker.md index 1bf742495a8..b60b55ee93b 100644 --- a/docs/reference/stdlibs/std/banker.md +++ b/docs/reference/stdlibs/std/banker.md @@ -39,7 +39,8 @@ Returns `Banker` of the specified type. banker := std.GetBanker(std.) ``` -⚠️ Methods of `Banker` expect qualified denomination of the coins, [see more here](./realm.md#realmdenom). +:::info `Banker` methods expect qualified denomination of the coins. Read more [here](./realm.md#coindenom). +::: --- diff --git a/docs/reference/stdlibs/std/chain.md b/docs/reference/stdlibs/std/chain.md index b1791e65608..8ab9d0d1573 100644 --- a/docs/reference/stdlibs/std/chain.md +++ b/docs/reference/stdlibs/std/chain.md @@ -162,3 +162,20 @@ Derives the Realm address from its `pkgpath` parameter. ```go realmAddr := std.DerivePkgAddr("gno.land/r/demo/tamagotchi") // g1a3tu874agjlkrpzt9x90xv3uzncapcn959yte4 ``` + +--- + +## CoinDenom +```go +func CoinDenom(pkgPath, coinName string) string +``` +Composes a qualified denomination string from the realm's `pkgPath` and the provided coin name, e.g. `/gno.land/r/demo/blog:ugnot`. This method should be used to get fully qualified denominations of coins when interacting with the `Banker` module. It can also be used as a method of the `Realm` object, see [Realm.CoinDenom](./realm.md#coindenom). + +#### Parameters +- `pkgPath` **string** - package path of the realm +- `coinName` **string** - The coin name used to build the qualified denomination. Must start with a lowercase letter, followed by 2–15 lowercase letters or digits. + +#### Usage +```go +denom := std.CoinDenom("gno.land/r/demo/blog", "ugnot") +``` diff --git a/docs/reference/stdlibs/std/realm.md b/docs/reference/stdlibs/std/realm.md index e6c24fc416c..86c68e9c29c 100644 --- a/docs/reference/stdlibs/std/realm.md +++ b/docs/reference/stdlibs/std/realm.md @@ -14,7 +14,7 @@ type Realm struct { func (r Realm) Addr() Address {...} func (r Realm) PkgPath() string {...} func (r Realm) IsUser() bool {...} -func (r Realm) Denom(denom string) string {...} +func (r Realm) CoinDenom(coinName string) string {...} ``` ## Addr @@ -41,32 +41,16 @@ Checks if the realm it was called upon is a user realm. if r.IsUser() {...} ``` -## Denom -Composes a qualified denomination string from the realm's pkg path and the provided base denomination. e.g `/gno.land/r/demo/blog:ugnot`. This method should be used when interacting with the `Banker` interface. - -#### Parameters -- `denom` **string** - The base denomination used to build the qualified denomination. Must start with a lowercase letter, followed by 2–15 lowercase letters or digits. - -#### Usage -```go -denom := r.Denom("ugnot") -``` - --- -## RealmDenom -```go -func RealmDenom(pkgPath, denom string) string -``` - -Composes a qualified denomination string from the realm's pkg path and the provided base denomination. e.g `/gno.land/r/demo/blog:ugnot`. This method should be used when interacting with the `Banker` interface. It can also be used as a method of the `Realm` object, see [Realm.Denom](realm.md#denom). +## CoinDenom +Composes a qualified denomination string from the realm's `pkgPath` and the provided coin name, e.g. `/gno.land/r/demo/blog:ugnot`. This method should be used to get fully qualified denominations of coins when interacting with the `Banker` module. #### Parameters -- `pkgPath` **string** - package path of the realm -- `denom` **string** - The base denomination used to build the qualified denomination. Must start with a lowercase letter, followed by 2–15 lowercase letters or digits. +- `coinName` **string** - The coin name used to build the qualified denomination. Must start with a lowercase letter, followed by 2–15 lowercase letters or digits. #### Usage ```go -denom := std.RealmDenom("gno.land/r/demo/blog", "ugnot") +denom := r.CoinDenom("ugnot") ``` diff --git a/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar b/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar index 97009afa53d..be9a686bac6 100644 --- a/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar +++ b/gno.land/cmd/gnoland/testdata/realm_banker_issued_coin_denom.txtar @@ -80,12 +80,12 @@ import ( func Mint(addr std.Address, denom string, amount int64) { banker := std.GetBanker(std.BankerTypeRealmIssue) - banker.IssueCoin(addr, std.CurrentRealm().Denom(denom), amount) + banker.IssueCoin(addr, std.CurrentRealm().CoinDenom(denom), amount) } func Burn(addr std.Address, denom string, amount int64) { banker := std.GetBanker(std.BankerTypeRealmIssue) - banker.RemoveCoin(addr, std.CurrentRealm().Denom(denom), amount) + banker.RemoveCoin(addr, std.CurrentRealm().CoinDenom(denom), amount) } -- long/realm_banker.gno -- @@ -98,12 +98,12 @@ import ( func Mint(addr std.Address, denom string, amount int64) { banker := std.GetBanker(std.BankerTypeRealmIssue) - banker.IssueCoin(addr, std.CurrentRealm().Denom(denom), amount) + banker.IssueCoin(addr, std.CurrentRealm().CoinDenom(denom), amount) } func Burn(addr std.Address, denom string, amount int64) { banker := std.GetBanker(std.BankerTypeRealmIssue) - banker.RemoveCoin(addr, std.CurrentRealm().Denom(denom), amount) + banker.RemoveCoin(addr, std.CurrentRealm().CoinDenom(denom), amount) } -- invalid_realm_denom/realm_banker.gno -- @@ -121,4 +121,4 @@ func Mint(addr std.Address, denom string, amount int64) { func Burn(addr std.Address, denom string, amount int64) { banker := std.GetBanker(std.BankerTypeRealmIssue) banker.RemoveCoin(addr, denom, amount) -} +} \ No newline at end of file diff --git a/gnovm/stdlibs/std/banker.gno b/gnovm/stdlibs/std/banker.gno index 98cfc91f14f..4c20e8d4b61 100644 --- a/gnovm/stdlibs/std/banker.gno +++ b/gnovm/stdlibs/std/banker.gno @@ -127,7 +127,7 @@ func (b banker) IssueCoin(addr Address, denom string, amount int64) { if b.bt != BankerTypeRealmIssue { panic(b.bt.String() + " cannot issue coins") } - assertRealmDenom(denom) + assertCoinDenom(denom) bankerIssueCoin(uint8(b.bt), string(addr), denom, amount) } @@ -135,11 +135,11 @@ func (b banker) RemoveCoin(addr Address, denom string, amount int64) { if b.bt != BankerTypeRealmIssue { panic(b.bt.String() + " cannot remove coins") } - assertRealmDenom(denom) + assertCoinDenom(denom) bankerRemoveCoin(uint8(b.bt), string(addr), denom, amount) } -func assertRealmDenom(denom string) { +func assertCoinDenom(denom string) { prefix := "/" + CurrentRealm().PkgPath() + ":" if !strings.HasPrefix(denom, prefix) { panic("invalid denom, can only issue/remove coins with the realm's prefix: " + prefix) diff --git a/gnovm/stdlibs/std/frame.gno b/gnovm/stdlibs/std/frame.gno index 5d309e4b66b..1709f8cb8b5 100644 --- a/gnovm/stdlibs/std/frame.gno +++ b/gnovm/stdlibs/std/frame.gno @@ -17,14 +17,14 @@ func (r Realm) IsUser() bool { return r.pkgPath == "" } -func (r Realm) Denom(denom string) string { - return RealmDenom(r.pkgPath, denom) +func (r Realm) CoinDenom(coinName string) string { + return CoinDenom(r.pkgPath, coinName) } -func RealmDenom(pkgPath, denom string) string { +func CoinDenom(pkgPath, coinName string) string { // TODO: Possibly remove after https://github.com/gnolang/gno/issues/3164 // Similar to ibc spec // ibc_denom := 'ibc/' + hash('path' + 'base_denom') - // gno_realm_denom := '/' + 'pkg_path' + ':' + 'base_denom' - return "/" + pkgPath + ":" + denom + // gno_qualified_denom := '/' + 'pkg_path' + ':' + 'base_denom' + return "/" + pkgPath + ":" + coinName } From 437e1b30bf7dcffa0b16e20bc07bfcca408bae3f Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Thu, 12 Dec 2024 09:40:02 +0100 Subject: [PATCH 31/37] docs: format --- docs/reference/stdlibs/std/realm.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/docs/reference/stdlibs/std/realm.md b/docs/reference/stdlibs/std/realm.md index 86c68e9c29c..a315628bfe9 100644 --- a/docs/reference/stdlibs/std/realm.md +++ b/docs/reference/stdlibs/std/realm.md @@ -40,9 +40,7 @@ Checks if the realm it was called upon is a user realm. ```go if r.IsUser() {...} ``` - --- - ## CoinDenom Composes a qualified denomination string from the realm's `pkgPath` and the provided coin name, e.g. `/gno.land/r/demo/blog:ugnot`. This method should be used to get fully qualified denominations of coins when interacting with the `Banker` module. @@ -53,4 +51,3 @@ Composes a qualified denomination string from the realm's `pkgPath` and the prov ```go denom := r.CoinDenom("ugnot") ``` - From e2cd2e709a0e8fb22f29d3cab65736b3b9e5a656 Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Thu, 12 Dec 2024 09:43:32 +0100 Subject: [PATCH 32/37] docs: format --- docs/reference/stdlibs/std/chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/stdlibs/std/chain.md b/docs/reference/stdlibs/std/chain.md index 8ab9d0d1573..671190fb3e7 100644 --- a/docs/reference/stdlibs/std/chain.md +++ b/docs/reference/stdlibs/std/chain.md @@ -169,7 +169,7 @@ realmAddr := std.DerivePkgAddr("gno.land/r/demo/tamagotchi") // g1a3tu874agjlkr ```go func CoinDenom(pkgPath, coinName string) string ``` -Composes a qualified denomination string from the realm's `pkgPath` and the provided coin name, e.g. `/gno.land/r/demo/blog:ugnot`. This method should be used to get fully qualified denominations of coins when interacting with the `Banker` module. It can also be used as a method of the `Realm` object, see [Realm.CoinDenom](./realm.md#coindenom). +Composes a qualified denomination string from the realm's `pkgPath` and the provided coin name, e.g. `/gno.land/r/demo/blog:ugnot`. This method should be used to get fully qualified denominations of coins when interacting with the `Banker` module. It can also be used as a method of the `Realm` object, Read more[here](./realm.md#coindenom). #### Parameters - `pkgPath` **string** - package path of the realm From 63d820dc7fb6f93c7d432af677334699719b082b Mon Sep 17 00:00:00 2001 From: MikaelVallenet Date: Thu, 12 Dec 2024 09:45:30 +0100 Subject: [PATCH 33/37] docs: format --- docs/reference/stdlibs/std/chain.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/reference/stdlibs/std/chain.md b/docs/reference/stdlibs/std/chain.md index 671190fb3e7..e0c5bcda78c 100644 --- a/docs/reference/stdlibs/std/chain.md +++ b/docs/reference/stdlibs/std/chain.md @@ -162,7 +162,6 @@ Derives the Realm address from its `pkgpath` parameter. ```go realmAddr := std.DerivePkgAddr("gno.land/r/demo/tamagotchi") // g1a3tu874agjlkrpzt9x90xv3uzncapcn959yte4 ``` - --- ## CoinDenom From 3f50ba6653cbbf2542a15926f36303cea24b0686 Mon Sep 17 00:00:00 2001 From: Mikael VALLENET Date: Thu, 12 Dec 2024 14:14:51 +0100 Subject: [PATCH 34/37] Update docs/reference/stdlibs/std/chain.md Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com> --- docs/reference/stdlibs/std/chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/stdlibs/std/chain.md b/docs/reference/stdlibs/std/chain.md index e0c5bcda78c..c27a5795c6e 100644 --- a/docs/reference/stdlibs/std/chain.md +++ b/docs/reference/stdlibs/std/chain.md @@ -176,5 +176,5 @@ Composes a qualified denomination string from the realm's `pkgPath` and the prov #### Usage ```go -denom := std.CoinDenom("gno.land/r/demo/blog", "ugnot") +denom := std.CoinDenom("gno.land/r/demo/blog", "blgcoin") // /gno.land/r/demo/blog:blgcoin ``` From f58aba57b0ef3355e34f5ea145110bb98c70aaa0 Mon Sep 17 00:00:00 2001 From: Mikael VALLENET Date: Thu, 12 Dec 2024 14:15:00 +0100 Subject: [PATCH 35/37] Update docs/reference/stdlibs/std/realm.md Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com> --- docs/reference/stdlibs/std/realm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/stdlibs/std/realm.md b/docs/reference/stdlibs/std/realm.md index a315628bfe9..93a4df0404b 100644 --- a/docs/reference/stdlibs/std/realm.md +++ b/docs/reference/stdlibs/std/realm.md @@ -42,7 +42,7 @@ if r.IsUser() {...} ``` --- ## CoinDenom -Composes a qualified denomination string from the realm's `pkgPath` and the provided coin name, e.g. `/gno.land/r/demo/blog:ugnot`. This method should be used to get fully qualified denominations of coins when interacting with the `Banker` module. +Composes a qualified denomination string from the realm's `pkgPath` and the provided coin name, e.g. `/gno.land/r/demo/blog:blgcoin`. This method should be used to get fully qualified denominations of coins when interacting with the `Banker` module. #### Parameters - `coinName` **string** - The coin name used to build the qualified denomination. Must start with a lowercase letter, followed by 2–15 lowercase letters or digits. From fec2919b065707553b395a400d1abadf38365b69 Mon Sep 17 00:00:00 2001 From: Mikael VALLENET Date: Thu, 12 Dec 2024 14:15:11 +0100 Subject: [PATCH 36/37] Update docs/reference/stdlibs/std/realm.md Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com> --- docs/reference/stdlibs/std/realm.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/reference/stdlibs/std/realm.md b/docs/reference/stdlibs/std/realm.md index 93a4df0404b..f69cd874c75 100644 --- a/docs/reference/stdlibs/std/realm.md +++ b/docs/reference/stdlibs/std/realm.md @@ -49,5 +49,6 @@ Composes a qualified denomination string from the realm's `pkgPath` and the prov #### Usage ```go -denom := r.CoinDenom("ugnot") +// in "gno.land/r/gnoland/blog" +denom := r.CoinDenom("blgcoin") // /gno.land/r/gnoland/blog:blgcoin ``` From 12be3792e833550b2cba45a9bb3da6a5325c3f9e Mon Sep 17 00:00:00 2001 From: Mikael VALLENET Date: Thu, 12 Dec 2024 14:15:37 +0100 Subject: [PATCH 37/37] Update docs/reference/stdlibs/std/chain.md Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com> --- docs/reference/stdlibs/std/chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/stdlibs/std/chain.md b/docs/reference/stdlibs/std/chain.md index c27a5795c6e..6a1da6483fd 100644 --- a/docs/reference/stdlibs/std/chain.md +++ b/docs/reference/stdlibs/std/chain.md @@ -168,7 +168,7 @@ realmAddr := std.DerivePkgAddr("gno.land/r/demo/tamagotchi") // g1a3tu874agjlkr ```go func CoinDenom(pkgPath, coinName string) string ``` -Composes a qualified denomination string from the realm's `pkgPath` and the provided coin name, e.g. `/gno.land/r/demo/blog:ugnot`. This method should be used to get fully qualified denominations of coins when interacting with the `Banker` module. It can also be used as a method of the `Realm` object, Read more[here](./realm.md#coindenom). +Composes a qualified denomination string from the realm's `pkgPath` and the provided coin name, e.g. `/gno.land/r/demo/blog:blgcoin`. This method should be used to get fully qualified denominations of coins when interacting with the `Banker` module. It can also be used as a method of the `Realm` object, Read more[here](./realm.md#coindenom). #### Parameters - `pkgPath` **string** - package path of the realm