From 868bbd5cbb8804f25102b9042b8974c7dc71ce52 Mon Sep 17 00:00:00 2001 From: Paul Chen Date: Fri, 21 Jun 2024 13:49:43 +0800 Subject: [PATCH] feat: add parse gov params command (#735) ## Description Closes: #XXXX This PR adds parse gov params command for updating gov params easily after the schema upgrade. --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch - [ ] provided a link to the relevant issue or specification - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) --- .gitignore | 1 + cmd/parse/gov/cmd.go | 1 + cmd/parse/gov/params.go | 52 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 cmd/parse/gov/params.go diff --git a/.gitignore b/.gitignore index 8034ed4a2..4123aebe2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .idea/ build/ +vendor/ # Configuration *.toml diff --git a/cmd/parse/gov/cmd.go b/cmd/parse/gov/cmd.go index f86d8ca1e..d1536a7ef 100644 --- a/cmd/parse/gov/cmd.go +++ b/cmd/parse/gov/cmd.go @@ -14,6 +14,7 @@ func NewGovCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { cmd.AddCommand( proposalCmd(parseConfig), + paramsCmd(parseConfig), ) return cmd diff --git a/cmd/parse/gov/params.go b/cmd/parse/gov/params.go new file mode 100644 index 000000000..55edda0d8 --- /dev/null +++ b/cmd/parse/gov/params.go @@ -0,0 +1,52 @@ +package gov + +import ( + "github.com/spf13/cobra" + + "github.com/forbole/callisto/v4/database" + "github.com/forbole/callisto/v4/modules/distribution" + "github.com/forbole/callisto/v4/modules/gov" + "github.com/forbole/callisto/v4/modules/mint" + "github.com/forbole/callisto/v4/modules/slashing" + "github.com/forbole/callisto/v4/modules/staking" + modulestypes "github.com/forbole/callisto/v4/modules/types" + parsecmdtypes "github.com/forbole/juno/v5/cmd/parse/types" + "github.com/forbole/juno/v5/types/config" +) + +func paramsCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + return &cobra.Command{ + Use: "params", + Short: "Get the current parameters of the gov module", + RunE: func(cmd *cobra.Command, args []string) error { + parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) + if err != nil { + return err + } + + sources, err := modulestypes.BuildSources(config.Cfg.Node, parseCtx.EncodingConfig) + if err != nil { + return err + } + + // Get the database + db := database.Cast(parseCtx.Database) + + // Build expected modules of gov modules + distrModule := distribution.NewModule(sources.DistrSource, parseCtx.EncodingConfig.Codec, db) + mintModule := mint.NewModule(sources.MintSource, parseCtx.EncodingConfig.Codec, db) + slashingModule := slashing.NewModule(sources.SlashingSource, parseCtx.EncodingConfig.Codec, db) + stakingModule := staking.NewModule(sources.StakingSource, parseCtx.EncodingConfig.Codec, db) + + // Build the gov module + govModule := gov.NewModule(sources.GovSource, distrModule, mintModule, slashingModule, stakingModule, parseCtx.EncodingConfig.Codec, db) + + height, err := parseCtx.Node.LatestHeight() + if err != nil { + return err + } + + return govModule.UpdateParams(height) + }, + } +}