From 4a1c0bbbd34ccbe61d94ea19aebc594c7fa576e5 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Tue, 22 Oct 2024 13:08:10 -0500 Subject: [PATCH] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gno.land/cmd/gnoland/testdata/params.txtar | 6 +++--- gnovm/stdlibs/std/params.go | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/params.txtar b/gno.land/cmd/gnoland/testdata/params.txtar index 817c616b76d..7f728e14003 100644 --- a/gno.land/cmd/gnoland/testdata/params.txtar +++ b/gno.land/cmd/gnoland/testdata/params.txtar @@ -60,6 +60,6 @@ import ( "std" ) -func SetFoo(newFoo string) { std.SetParam("foo", newFoo) } -func SetBar(newBar bool) { std.SetParam("bar", newBar) } -func SetBaz(newBaz int64) { std.SetParam("baz", newBaz) } +func SetFoo(newFoo string) { std.SetParam("foo.string", newFoo) } +func SetBar(newBar bool) { std.SetParam("bar.bool", newBar) } +func SetBaz(newBaz int64) { std.SetParam("baz.int64", newBaz) } diff --git a/gnovm/stdlibs/std/params.go b/gnovm/stdlibs/std/params.go index f4cd8f7e245..e21bd9912dd 100644 --- a/gnovm/stdlibs/std/params.go +++ b/gnovm/stdlibs/std/params.go @@ -2,6 +2,7 @@ package std import ( "fmt" + "strings" "unicode" gno "github.com/gnolang/gno/gnovm/pkg/gnolang" @@ -47,6 +48,11 @@ func X_setParamBytes(m *gno.Machine, key string, val []byte) { func pkey(m *gno.Machine, key string, kind string) string { // validate key. + untypedKey := strings.TrimSuffix(key, "."+kind) + if key == untypedKey { + m.Panic(typedString("invalid param key: " + key)) + } + if len(key) == 0 { m.Panic(typedString("empty param key")) } @@ -54,7 +60,7 @@ func pkey(m *gno.Machine, key string, kind string) string { if !unicode.IsLetter(first) && first != '_' { m.Panic(typedString("invalid param key: " + key)) } - for _, char := range key[1:] { + for _, char := range untypedKey[1:] { if !unicode.IsLetter(char) && !unicode.IsDigit(char) && char != '_' { m.Panic(typedString("invalid param key: " + key)) } @@ -62,5 +68,5 @@ func pkey(m *gno.Machine, key string, kind string) string { // decorate key with realm and type. _, rlmPath := currentRealm(m) - return fmt.Sprintf("%s.%s.%s", rlmPath, key, kind) + return fmt.Sprintf("%s.%s", rlmPath, key) }