Skip to content

Commit

Permalink
feat: add parse gov params command (#735)
Browse files Browse the repository at this point in the history
## Description

Closes: #XXXX
This PR adds parse gov params command for updating gov params easily
after the schema upgrade.

<!-- Add a description of the changes that this PR introduces and the
files that
are the most critical to review. -->

---

### 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)
  • Loading branch information
dadamu authored Jun 21, 2024
1 parent 09f92fa commit 868bbd5
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.idea/
build/
vendor/

# Configuration
*.toml
Expand Down
1 change: 1 addition & 0 deletions cmd/parse/gov/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func NewGovCmd(parseConfig *parsecmdtypes.Config) *cobra.Command {

cmd.AddCommand(
proposalCmd(parseConfig),
paramsCmd(parseConfig),
)

return cmd
Expand Down
52 changes: 52 additions & 0 deletions cmd/parse/gov/params.go
Original file line number Diff line number Diff line change
@@ -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)
},
}
}

0 comments on commit 868bbd5

Please sign in to comment.