From aa6b8e8f9455e29071dd60d571648c5a703d85db Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Mon, 23 Dec 2024 15:41:24 -0500 Subject: [PATCH] feat(cosmos): Support arbitrary core eval builder arguments --- golang/cosmos/app/upgrade.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/golang/cosmos/app/upgrade.go b/golang/cosmos/app/upgrade.go index 0634bae8e5a..3a50385d61f 100644 --- a/golang/cosmos/app/upgrade.go +++ b/golang/cosmos/app/upgrade.go @@ -3,6 +3,7 @@ package gaia import ( "encoding/json" "fmt" + "reflect" "strings" "text/template" @@ -77,14 +78,24 @@ func isFirstTimeUpgradeOfThisVersion(app *GaiaApp, ctx sdk.Context) bool { return true } -func buildProposalStepWithArgs(moduleName string, entrypoint string, opts map[string]any) (vm.CoreProposalStep, error) { +func buildProposalStepWithArgs(moduleName string, entrypoint string, opts any) (vm.CoreProposalStep, error) { t := template.Must(template.New("").Parse(`{ - "module": "{{.moduleName}}", - "entrypoint": "{{.entrypoint}}", - "args": [ {{.optsArg}} ] - }`)) + "module": "{{.moduleName}}", + "entrypoint": "{{.entrypoint}}", + "args": {{.args}} +}`)) - optsArg, err := json.Marshal(opts) + var args []byte + var err error + if opts == nil { + args = []byte(`[]`) + } else if reflect.TypeOf(opts).Kind() == reflect.Slice { + args, err = json.Marshal(opts) + } else if reflect.TypeOf(opts).Kind() == reflect.Map && reflect.TypeOf(opts).Key().Kind() == reflect.String { + args, err = json.Marshal([]any{opts}) + } else { + return nil, fmt.Errorf("proposal opts must be nil, array, or string map, not %v", opts) + } if err != nil { return nil, err } @@ -93,7 +104,7 @@ func buildProposalStepWithArgs(moduleName string, entrypoint string, opts map[st err = t.Execute(&result, map[string]any{ "moduleName": moduleName, "entrypoint": entrypoint, - "optsArg": string(optsArg), + "args": string(args), }) if err != nil { return nil, err