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: manually trigger periodic task #492

Merged
merged 26 commits into from
Nov 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
331b1e6
complete x/bank
huichiaotsou Nov 1, 2022
0f8fc20
x/distribution; rename refresh to periodictask
huichiaotsou Nov 1, 2022
3a95f6a
x/mint; rephrase cmd description
huichiaotsou Nov 1, 2022
1ede48f
same as prev commit
huichiaotsou Nov 1, 2022
0ce4cf0
add pricefeed
huichiaotsou Nov 1, 2022
f8e1ede
x/staking
huichiaotsou Nov 1, 2022
b44fae7
getAddressesParser
huichiaotsou Nov 1, 2022
0a100ba
add change log
huichiaotsou Nov 1, 2022
45e6ddb
abort msg parser in bank.NewModule
huichiaotsou Nov 1, 2022
dd857b7
add bdjuno parse mint inflation
huichiaotsou Nov 7, 2022
f94425f
add bdjuno parse bank supply
huichiaotsou Nov 7, 2022
b394a64
rm bank from periodictask
huichiaotsou Nov 7, 2022
af87e83
add bdjuno parse distribution community-pool
huichiaotsou Nov 7, 2022
3575fe3
add bdjuno parse pricefeed price/price-history
huichiaotsou Nov 7, 2022
14b76e9
add bdjuno parse staking pool
huichiaotsou Nov 7, 2022
9745f69
fix NewPricefeedCmd description
huichiaotsou Nov 7, 2022
1ade7fa
update change log
huichiaotsou Nov 7, 2022
4556542
Update cmd/parse/mint/inflation.go
huichiaotsou Nov 8, 2022
c38e2ec
Update cmd/parse/mint/inflation.go
huichiaotsou Nov 8, 2022
1d587da
Update cmd/parse/staking/staking.go
huichiaotsou Nov 8, 2022
a61972f
Update cmd/parse/mint/inflation.go
huichiaotsou Nov 8, 2022
71ab94f
Update cmd/parse/distribution/communitypool.go
huichiaotsou Nov 8, 2022
a73168a
Update modules/bank/handle_periodic_operations.go
huichiaotsou Nov 8, 2022
6660a5a
Update modules/pricefeed/handle_periodic_operations.go
huichiaotsou Nov 8, 2022
e14fd0e
add import
huichiaotsou Nov 9, 2022
90d4f6c
Merge branch 'cosmos/v0.44.x' into aaron/manual_periodic_task
mergify[bot] Nov 13, 2022
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
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