Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/gno.land/r/sys/params/params.gno
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ func NewSysParamStringsPropRequestWithTitle(module, submodule, name, title strin
func NewSysParamStringsPropRequestAddWithTitle(module, submodule, name, title string, value []string) dao.ProposalRequest {
return newPropRequest(
syskey(module, submodule, name),
func() { prms.UpdateSysParamStrings(module, submodule, name, value, true) },
func() { prms.AddUniqueSysParamStrings(module, submodule, name, value) },
title,
)
}
func NewSysParamStringsPropRequestRemoveWithTitle(module, submodule, name, title string, value []string) dao.ProposalRequest {
return newPropRequest(
syskey(module, submodule, name),
func() { prms.UpdateSysParamStrings(module, submodule, name, value, false) },
func() { prms.RemoveSysParamStrings(module, submodule, name, value) },
title,
)
}
Expand Down
39 changes: 7 additions & 32 deletions gno.land/pkg/sdk/vm/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,40 +111,15 @@ func (prm *SDKParams) SetStrings(key string, value []string) {
}

func (prm *SDKParams) UpdateStrings(key string, vals []string, add bool) {
ss := &[]string{}
prm.pmk.GetStrings(prm.ctx, key, ss)

oldList := *ss
existing := make(map[string]struct{}, len(oldList))
// Temporary map for duplicate detection
for _, s := range oldList {
existing[s] = struct{}{}
}
prm.pmk.AddUniqueStrings(prm.ctx, key, vals)
}

if add {
// Append only non-duplicate values
for _, v := range vals {
if _, found := existing[v]; !found {
oldList = append(oldList, v)
existing[v] = struct{}{}
}
}
prm.SetStrings(key, oldList)
return
}
// Remove case
updatedList := oldList[:0] // reuse original memory
removeSet := make(map[string]struct{}, len(vals))
for _, v := range vals {
removeSet[v] = struct{}{}
}
func (prm *SDKParams) AddUniqueStrings(key string, vals []string) {
prm.pmk.AddUniqueStrings(prm.ctx, key, vals)
}

for _, s := range oldList {
if _, found := removeSet[s]; !found {
updatedList = append(updatedList, s)
}
}
prm.SetStrings(key, updatedList)
func (prm *SDKParams) RemoveStrings(key string, vals []string) {
prm.pmk.RemoveStrings(prm.ctx, key, vals)
}

func (prm *SDKParams) willSetKeeperParams(ctx sdk.Context, key string, value any) {
Expand Down
4 changes: 4 additions & 0 deletions gno.land/pkg/sdk/vm/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,7 @@ func (vm *VMKeeper) getSysNamesPkgParam(ctx sdk.Context) string {
func (vm *VMKeeper) WillSetParam(ctx sdk.Context, key string, value any) {
// XXX validate input?
}

func (vm *VMKeeper) WillUpdateParam(ctx sdk.Context, key string, value any, add bool) {
// XXX
}
11 changes: 6 additions & 5 deletions gnovm/cmd/gno/internal/fix/stdsplit.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ func makeSplitFuncs() {
"std.BankerTypeRealmSend": newSplitFunc("chain/banker.BankerTypeRealmSend"),
"std.BankerTypeRealmIssue": newSplitFunc("chain/banker.BankerTypeRealmIssue"),

"std.SetParamBool": newSplitFunc("chain/params.SetBool"),
"std.SetParamBytes": newSplitFunc("chain/params.SetBytes"),
"std.SetParamInt64": newSplitFunc("chain/params.SetInt64"),
"std.SetParamString": newSplitFunc("chain/params.SetString"),
"std.SetParamStrings": newSplitFunc("chain/params.SetStrings"),
"std.SetParamBool": newSplitFunc("chain/params.SetBool"),
"std.SetParamBytes": newSplitFunc("chain/params.SetBytes"),
"std.SetParamInt64": newSplitFunc("chain/params.SetInt64"),
"std.SetParamString": newSplitFunc("chain/params.SetString"),
"std.SetParamStrings": newSplitFunc("chain/params.SetStrings"),
// XXX
"std.UpdateParamStrings": newSplitFunc("chain/params.UpdateStrings"),
"std.SetParamUint64": newSplitFunc("chain/params.SetUint64"),

Expand Down
15 changes: 8 additions & 7 deletions gnovm/pkg/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,14 @@ func newTestParams() *testParams {
return &testParams{}
}

func (tp *testParams) SetBool(key string, val bool) { /* noop */ }
func (tp *testParams) SetBytes(key string, val []byte) { /* noop */ }
func (tp *testParams) SetInt64(key string, val int64) { /* noop */ }
func (tp *testParams) SetUint64(key string, val uint64) { /* noop */ }
func (tp *testParams) SetString(key string, val string) { /* noop */ }
func (tp *testParams) SetStrings(key string, val []string) { /* noop */ }
func (tp *testParams) UpdateStrings(key string, val []string, add bool) { /* noop */ }
func (tp *testParams) SetBool(key string, val bool) { /* noop */ }
func (tp *testParams) SetBytes(key string, val []byte) { /* noop */ }
func (tp *testParams) SetInt64(key string, val int64) { /* noop */ }
func (tp *testParams) SetUint64(key string, val uint64) { /* noop */ }
func (tp *testParams) SetString(key string, val string) { /* noop */ }
func (tp *testParams) SetStrings(key string, val []string) { /* noop */ }
func (tp *testParams) AddUniqueStrings(key string, val []string) { /* noop */ }
func (tp *testParams) RemoveStrings(key string, val []string) { /* noop */ }

// ----------------------------------------
// main test function
Expand Down
3 changes: 2 additions & 1 deletion gnovm/stdlibs/chain/params/params.gno
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ func SetInt64(key string, val int64)
func SetUint64(key string, val uint64)
func SetBytes(key string, val []byte)
func SetStrings(key string, val []string)
func UpdateParamStrings(key string, val []string, add bool)
func AddUniqueParamStrings(key string, val []string)
func RemoveParamStrings(key string, val []string)
9 changes: 7 additions & 2 deletions gnovm/stdlibs/chain/params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ func SetStrings(m *gno.Machine, key string, val []string) {
execctx.GetContext(m).Params.SetStrings(pk, val)
}

func UpdateParamStrings(m *gno.Machine, key string, val []string, add bool) {
func AddUniqueParamStrings(m *gno.Machine, key string, val []string) {
pk := pkey(m, key)
execctx.GetContext(m).Params.UpdateStrings(pk, val, add)
execctx.GetContext(m).Params.AddUniqueStrings(pk, val)
}

func RemoveParamStrings(m *gno.Machine, key string, val []string) {
pk := pkey(m, key)
execctx.GetContext(m).Params.RemoveStrings(pk, val)
}

// NOTE: further validation must happen by implementor of ParamsInterface.
Expand Down
96 changes: 78 additions & 18 deletions gnovm/stdlibs/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion gnovm/stdlibs/internal/execctx/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ type ParamsInterface interface {
SetUint64(key string, val uint64)
SetBytes(key string, val []byte)
SetStrings(key string, val []string)
UpdateStrings(key string, val []string, add bool)
AddUniqueStrings(key string, val []string)
RemoveStrings(key string, val []string)
}

type ExecContext struct {
Expand Down
14 changes: 11 additions & 3 deletions gnovm/stdlibs/sys/params/params.gno
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@ func SetSysParamStrings(module, submodule, name string, val []string) {
setSysParamStrings(module, submodule, name, val)
}

func UpdateSysParamStrings(module, submodule, name string, val []string, add bool) {
func AddUniqueSysParamStrings(module, submodule, name string, val []string) {
if val == nil {
val = []string{}
}
updateSysParamStrings(module, submodule, name, val, add)
addUniqueSysParamStrings(module, submodule, name, val)
}

func RemoveSysParamStrings(module, submodule, name string, val []string) {
if val == nil {
val = []string{}
}
removeSysParamStrings(module, submodule, name, val)
}

func setSysParamString(module, submodule, name string, val string)
Expand All @@ -44,4 +51,5 @@ func setSysParamInt64(module, submodule, name string, val int64)
func setSysParamUint64(module, submodule, name string, val uint64)
func setSysParamBytes(module, submodule, name string, val []byte)
func setSysParamStrings(module, submodule, name string, val []string)
func updateSysParamStrings(module, submodule, name string, val []string, add bool)
func addUniqueSysParamStrings(module, submodule, name string, val []string)
func removeSysParamStrings(module, submodule, name string, val []string)
10 changes: 8 additions & 2 deletions gnovm/stdlibs/sys/params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,16 @@ func X_setSysParamStrings(m *gno.Machine, module, submodule, name string, val []
execctx.GetContext(m).Params.SetStrings(pk, val)
}

func X_updateSysParamStrings(m *gno.Machine, module, submodule, name string, val []string, add bool) {
func X_addUniqueSysParamStrings(m *gno.Machine, module, submodule, name string, val []string) {
assertSysParamsRealm(m)
pk := prmkey(module, submodule, name)
execctx.GetContext(m).Params.UpdateStrings(pk, val, add)
execctx.GetContext(m).Params.AddUniqueStrings(pk, val)
}

func X_removeSysParamStrings(m *gno.Machine, module, submodule, name string, val []string) {
assertSysParamsRealm(m)
pk := prmkey(module, submodule, name)
execctx.GetContext(m).Params.RemoveStrings(pk, val)
}

func assertSysParamsRealm(m *gno.Machine) {
Expand Down
Loading
Loading