Skip to content

Commit

Permalink
use BuildModules
Browse files Browse the repository at this point in the history
  • Loading branch information
huichiaotsou committed Jun 20, 2022
1 parent 4c1c434 commit 91e3c30
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
4 changes: 2 additions & 2 deletions cmd/bdjuno/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func main() {
parseCfg := parsetypes.NewConfig().
WithDBBuilder(database.Builder).
WithEncodingConfigBuilder(config.MakeEncodingConfig(getBasicManagers())).
WithRegistrar(modules.NewRegistrar(getAddressesParser()))
WithRegistrar(modules.NewRegistrar(GetAddressesParser()))

cfg := cmd.NewConfig("bdjuno").
WithInitConfig(initCfg).
Expand Down Expand Up @@ -62,7 +62,7 @@ func getBasicManagers() []module.BasicManager {
// getAddressesParser returns the messages parser that should be used to get the users involved in
// a specific message.
// This should be edited by custom implementations if needed.
func getAddressesParser() messages.MessageAddressesParser {
func GetAddressesParser() messages.MessageAddressesParser {
return messages.JoinMessageParsers(
messages.CosmosMessageAddressesParser,
)
Expand Down
44 changes: 25 additions & 19 deletions cmd/parse/gov/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@ package gov
import (
"encoding/hex"
"fmt"
"reflect"
"strconv"

modulestypes "github.com/forbole/bdjuno/v3/modules/types"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/rs/zerolog/log"

govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types"
modsregistrar "github.com/forbole/juno/v3/modules/registrar"
"github.com/forbole/juno/v3/types/config"
"github.com/spf13/cobra"

"github.com/forbole/juno/v3/parser"

"github.com/forbole/bdjuno/v3/database"
"github.com/forbole/bdjuno/v3/modules/distribution"
"github.com/forbole/bdjuno/v3/modules/gov"
"github.com/forbole/bdjuno/v3/modules/mint"
"github.com/forbole/bdjuno/v3/modules/slashing"
"github.com/forbole/bdjuno/v3/modules/staking"
"github.com/forbole/bdjuno/v3/utils"
)

Expand All @@ -40,24 +39,31 @@ func proposalCmd(parseConfig *parsecmdtypes.Config) *cobra.Command {
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 for handleParamChangeProposal
distrModule := distribution.NewModule(sources.DistrSource, parseCtx.EncodingConfig.Marshaler, db)
mintModule := mint.NewModule(sources.MintSource, parseCtx.EncodingConfig.Marshaler, db)
slashingModule := slashing.NewModule(sources.SlashingSource, parseCtx.EncodingConfig.Marshaler, db)
stakingModule := staking.NewModule(sources.StakingSource, slashingModule, parseCtx.EncodingConfig.Marshaler, db)
// Get sdk config instance either it's sealed or not
sdkConfig := sdk.GetConfig()
fv := reflect.ValueOf(sdkConfig).Elem().FieldByName("sealed")
if !fv.Bool() {
parseConfig.GetSetupConfig()(config.Cfg, sdkConfig)
sdkConfig.Seal()
}

// Build modules
context := modsregistrar.NewContext(config.Cfg, sdkConfig, parseCtx.EncodingConfig, db, parseCtx.Node, parseConfig.GetLogger())
modules := parseConfig.GetRegistrar().BuildModules(context)

// Build the gov module
govModule := gov.NewModule(
sources.GovSource, nil, distrModule, mintModule, slashingModule, stakingModule, parseCtx.EncodingConfig.Marshaler, db,
)
// Find module
moduleI, found := modules.FindByName(govtypes.ModuleName)
if !found {
return fmt.Errorf("module not found: %s", govtypes.ModuleName)
}

govModule, ok := moduleI.(*gov.Module)
if !ok {
return fmt.Errorf("error while type asserting gov module")
}

err = refreshProposalDetails(parseCtx, proposalID, govModule)
if err != nil {
Expand Down

0 comments on commit 91e3c30

Please sign in to comment.