Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cosmos): Support arbitrary core eval builder arguments #10767

Merged
Merged
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
28 changes: 21 additions & 7 deletions golang/cosmos/app/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gaia
import (
"encoding/json"
"fmt"
"reflect"
"strings"
"text/template"

Expand Down Expand Up @@ -77,14 +78,27 @@ 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, extra 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 extra == nil {
// The specified entrypoint will be called with no extra arguments after powers.
args = []byte(`[]`)
} else if reflect.TypeOf(extra).Kind() == reflect.Map && reflect.TypeOf(extra).Key().Kind() == reflect.String {
// The specified entrypoint will be called with this options argument after powers.
args, err = json.Marshal([]any{extra})
} else if reflect.TypeOf(extra).Kind() == reflect.Slice {
// The specified entrypoint will be called with each of these arguments after powers.
args, err = json.Marshal(extra)
} else {
return nil, fmt.Errorf("proposal extra must be nil, array, or string map, not %v", extra)
}
if err != nil {
return nil, err
}
Expand All @@ -93,7 +107,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
Expand Down
Loading