Skip to content

Commit

Permalink
feat(cosmos): Support arbitrary core eval builder arguments (#10767)
Browse files Browse the repository at this point in the history
## Description
Extracted from and supports #10752 by allowing builder arguments other than a single options record.

### Security Considerations
None known.

### Scaling Considerations
None.

### Documentation Considerations
n/a

### Testing Considerations
Covered by use in #10752.

### Upgrade Considerations
n/a
  • Loading branch information
gibson042 authored Dec 23, 2024
1 parent 39d8f59 commit a944f4c
Showing 1 changed file with 21 additions and 7 deletions.
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

0 comments on commit a944f4c

Please sign in to comment.