Skip to content

Commit

Permalink
feat: manually trigger periodic task (#492)
Browse files Browse the repository at this point in the history
## Description

Closes: #415 



---

### 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...

- [x] 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
- [x] targeted the correct branch
- [x] provided a link to the relevant issue or specification
- [x] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [x] 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
huichiaotsou authored Nov 13, 2022
1 parent 1147d3b commit a7aa04d
Show file tree
Hide file tree
Showing 18 changed files with 390 additions and 24 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## Unreleased
### Changes

#### Parse Command
- ([\#492](https://github.com/forbole/bdjuno/pull/492)) Add parse command for periodic tasks: `x/bank` total supply, `x/distribution` community pool, `x/mint` inflation, `pricefeed` token price and price history, `x/staking` staking pool

#### Upgrade Module
- ([\#467](https://github.com/forbole/bdjuno/pull/467)) Store software upgrade plan and refresh data at upgrade height

Expand Down
20 changes: 20 additions & 0 deletions cmd/parse/bank/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package bank

import (
parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types"
"github.com/spf13/cobra"
)

// NewBankCmd returns the Cobra command allowing to fix various things related to the x/bank module
func NewBankCmd(parseConfig *parsecmdtypes.Config) *cobra.Command {
cmd := &cobra.Command{
Use: "bank",
Short: "Fix things related to the x/bank module",
}

cmd.AddCommand(
supplyCmd(parseConfig),
)

return cmd
}
46 changes: 46 additions & 0 deletions cmd/parse/bank/supply.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package bank

import (
"fmt"

modulestypes "github.com/forbole/bdjuno/v3/modules/types"

parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types"
"github.com/forbole/juno/v3/types/config"
"github.com/spf13/cobra"

"github.com/forbole/bdjuno/v3/database"
"github.com/forbole/bdjuno/v3/modules/bank"
)

// supplyCmd returns the Cobra command allowing to refresh x/bank total supply
func supplyCmd(parseConfig *parsecmdtypes.Config) *cobra.Command {
return &cobra.Command{
Use: "supply",
Short: "Refresh total supply",
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 bank module
bankModule := bank.NewModule(nil, sources.BankSource, parseCtx.EncodingConfig.Marshaler, db)

err = bankModule.UpdateSupply()
if err != nil {
return fmt.Errorf("error while getting latest bank supply: %s", err)
}

return nil
},
}
}
20 changes: 20 additions & 0 deletions cmd/parse/distribution/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package distribution

import (
parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types"
"github.com/spf13/cobra"
)

// NewDistributionCmd returns the Cobra command allowing to fix various things related to the x/distribution module
func NewDistributionCmd(parseConfig *parsecmdtypes.Config) *cobra.Command {
cmd := &cobra.Command{
Use: "distribution",
Short: "Fix things related to the x/distribution module",
}

cmd.AddCommand(
communityPoolCmd(parseConfig),
)

return cmd
}
45 changes: 45 additions & 0 deletions cmd/parse/distribution/communitypool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package distribution

import (
"fmt"

parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types"
"github.com/forbole/juno/v3/types/config"
"github.com/spf13/cobra"

"github.com/forbole/bdjuno/v3/database"
"github.com/forbole/bdjuno/v3/modules/distribution"
modulestypes "github.com/forbole/bdjuno/v3/modules/types"
)

// communityPoolCmd returns the Cobra command allowing to refresh community pool
func communityPoolCmd(parseConfig *parsecmdtypes.Config) *cobra.Command {
return &cobra.Command{
Use: "community-pool",
Short: "Refresh community pool",
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 distribution module
distrModule := distribution.NewModule(sources.DistrSource, parseCtx.EncodingConfig.Marshaler, db)

err = distrModule.GetLatestCommunityPool()
if err != nil {
return fmt.Errorf("error while updating community pool: %s", err)
}

return nil
},
}
}
20 changes: 20 additions & 0 deletions cmd/parse/mint/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package mint

import (
parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types"
"github.com/spf13/cobra"
)

// NewMintCmd returns the Cobra command allowing to fix various things related to the x/mint module
func NewMintCmd(parseConfig *parsecmdtypes.Config) *cobra.Command {
cmd := &cobra.Command{
Use: "mint",
Short: "Fix things related to the x/mint module",
}

cmd.AddCommand(
inflationCmd(parseConfig),
)

return cmd
}
45 changes: 45 additions & 0 deletions cmd/parse/mint/inflation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package mint

import (
"fmt"

parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types"
"github.com/forbole/juno/v3/types/config"
"github.com/spf13/cobra"

"github.com/forbole/bdjuno/v3/database"
"github.com/forbole/bdjuno/v3/modules/mint"
modulestypes "github.com/forbole/bdjuno/v3/modules/types"
)

// inflationCmd returns the Cobra command allowing to refresh x/mint inflation
func inflationCmd(parseConfig *parsecmdtypes.Config) *cobra.Command {
return &cobra.Command{
Use: "inflation",
Short: "Refresh inflation",
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 mint module
mintModule := mint.NewModule(sources.MintSource, parseCtx.EncodingConfig.Marshaler, db)

err = mintModule.UpdateInflation()
if err != nil {
return fmt.Errorf("error while updating inflation: %s", err)
}

return nil
},
}
}
8 changes: 8 additions & 0 deletions cmd/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ import (
parsegenesis "github.com/forbole/juno/v3/cmd/parse/genesis"

parseauth "github.com/forbole/bdjuno/v3/cmd/parse/auth"
parsebank "github.com/forbole/bdjuno/v3/cmd/parse/bank"
parsedistribution "github.com/forbole/bdjuno/v3/cmd/parse/distribution"
parsefeegrant "github.com/forbole/bdjuno/v3/cmd/parse/feegrant"
parsegov "github.com/forbole/bdjuno/v3/cmd/parse/gov"
parsemint "github.com/forbole/bdjuno/v3/cmd/parse/mint"
parsepricefeed "github.com/forbole/bdjuno/v3/cmd/parse/pricefeed"
parsestaking "github.com/forbole/bdjuno/v3/cmd/parse/staking"
parsetransaction "github.com/forbole/juno/v3/cmd/parse/transactions"
)
Expand All @@ -25,10 +29,14 @@ func NewParseCmd(parseCfg *parse.Config) *cobra.Command {

cmd.AddCommand(
parseauth.NewAuthCmd(parseCfg),
parsebank.NewBankCmd(parseCfg),
parseblocks.NewBlocksCmd(parseCfg),
parsedistribution.NewDistributionCmd(parseCfg),
parsefeegrant.NewFeegrantCmd(parseCfg),
parsegenesis.NewGenesisCmd(parseCfg),
parsegov.NewGovCmd(parseCfg),
parsemint.NewMintCmd(parseCfg),
parsepricefeed.NewPricefeedCmd(parseCfg),
parsestaking.NewStakingCmd(parseCfg),
parsetransaction.NewTransactionsCmd(parseCfg),
)
Expand Down
21 changes: 21 additions & 0 deletions cmd/parse/pricefeed/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package pricefeed

import (
parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types"
"github.com/spf13/cobra"
)

// NewPricefeedCmd returns the Cobra command allowing to refresh pricefeed
func NewPricefeedCmd(parseConfig *parsecmdtypes.Config) *cobra.Command {
cmd := &cobra.Command{
Use: "pricefeed",
Short: "Fix things related to the pricefeed module",
}

cmd.AddCommand(
priceCmd(parseConfig),
priceHistoryCmd(parseConfig),
)

return cmd
}
44 changes: 44 additions & 0 deletions cmd/parse/pricefeed/price.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package pricefeed

import (
"fmt"

parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types"
"github.com/forbole/juno/v3/types/config"
"github.com/spf13/cobra"

"github.com/forbole/bdjuno/v3/database"
"github.com/forbole/bdjuno/v3/modules/pricefeed"
)

// priceCmd returns the Cobra command allowing to refresh token price
func priceCmd(parseConfig *parsecmdtypes.Config) *cobra.Command {
return &cobra.Command{
Use: "price",
Short: "Refresh token price",
RunE: func(cmd *cobra.Command, args []string) error {
parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig)
if err != nil {
return err
}

// Get the database
db := database.Cast(parseCtx.Database)

// Build pricefeed module
pricefeedModule := pricefeed.NewModule(config.Cfg, parseCtx.EncodingConfig.Marshaler, db)

err = pricefeedModule.RunAdditionalOperations()
if err != nil {
return fmt.Errorf("error while storing tokens: %s", err)
}

err = pricefeedModule.UpdatePrice()
if err != nil {
return fmt.Errorf("error while updating price: %s", err)
}

return nil
},
}
}
44 changes: 44 additions & 0 deletions cmd/parse/pricefeed/pricehistory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package pricefeed

import (
"fmt"

parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types"
"github.com/forbole/juno/v3/types/config"
"github.com/spf13/cobra"

"github.com/forbole/bdjuno/v3/database"
"github.com/forbole/bdjuno/v3/modules/pricefeed"
)

// priceHistoryCmd returns the Cobra command allowing to store token price history
func priceHistoryCmd(parseConfig *parsecmdtypes.Config) *cobra.Command {
return &cobra.Command{
Use: "history",
Short: "Store token price history",
RunE: func(cmd *cobra.Command, args []string) error {
parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig)
if err != nil {
return err
}

// Get the database
db := database.Cast(parseCtx.Database)

// Build pricefeed module
pricefeedModule := pricefeed.NewModule(config.Cfg, parseCtx.EncodingConfig.Marshaler, db)

err = pricefeedModule.RunAdditionalOperations()
if err != nil {
return fmt.Errorf("error while storing tokens: %s", err)
}

err = pricefeedModule.UpdatePricesHistory()
if err != nil {
return fmt.Errorf("error while updating price history: %s", err)
}

return nil
},
}
}
1 change: 1 addition & 0 deletions cmd/parse/staking/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func NewStakingCmd(parseConfig *parsecmdtypes.Config) *cobra.Command {
}

cmd.AddCommand(
poolCmd(parseConfig),
validatorsCmd(parseConfig),
)

Expand Down
Loading

0 comments on commit a7aa04d

Please sign in to comment.