Skip to content

Commit

Permalink
Root configs modified for client commands
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnukumavat committed Jun 2, 2023
1 parent 757febd commit 6745f92
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions cmd/comdex/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/cosmos/cosmos-sdk/client/config"
"github.com/prometheus/client_golang/prometheus"

"github.com/cosmos/cosmos-sdk/baseapp"
Expand Down Expand Up @@ -37,34 +38,41 @@ import (
)

func NewRootCmd() (*cobra.Command, comdex.EncodingConfig) {
var (
config = comdex.MakeEncodingConfig()
context = client.Context{}.
WithCodec(config.Marshaler).
WithInterfaceRegistry(config.InterfaceRegistry).
WithTxConfig(config.TxConfig).
WithLegacyAmino(config.Amino).
WithInput(os.Stdin).
WithAccountRetriever(authtypes.AccountRetriever{}).
WithBroadcastMode(flags.BroadcastBlock).
WithHomeDir(comdex.DefaultNodeHome)
)
encodingConfig := comdex.MakeEncodingConfig()
initClientCtx := client.Context{}.
WithCodec(encodingConfig.Marshaler).
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
WithTxConfig(encodingConfig.TxConfig).
WithLegacyAmino(encodingConfig.Amino).
WithInput(os.Stdin).
WithAccountRetriever(authtypes.AccountRetriever{}).
WithBroadcastMode(flags.BroadcastBlock).
WithHomeDir(comdex.DefaultNodeHome).
WithViper("")

cobra.EnableCommandSorting = false
root := &cobra.Command{
Use: "comdex",
Short: "Comdex - Decentralised Synthetic Asset Exchange",
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
if err := client.SetCmdClientContextHandler(context, cmd); err != nil {
initClientCtx, err := client.ReadPersistentCommandFlags(initClientCtx, cmd.Flags())
if err != nil {
return err
}
initClientCtx, err = config.ReadFromClientConfig(initClientCtx)
if err != nil {
return err
}
if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil {
return err
}

return server.InterceptConfigsPreRunHandler(cmd, "", nil)
},
}

initRootCmd(root, config)
return root, config
initRootCmd(root, encodingConfig)
return root, encodingConfig
}

func initRootCmd(rootCmd *cobra.Command, encoding comdex.EncodingConfig) {
Expand All @@ -78,6 +86,7 @@ func initRootCmd(rootCmd *cobra.Command, encoding comdex.EncodingConfig) {
tmcli.NewCompletionCmd(rootCmd, true),
testnetCmd(comdex.ModuleBasics, banktypes.GenesisBalancesIterator{}),
debug.Cmd(),
config.Cmd(),
)

server.AddCommands(rootCmd, comdex.DefaultNodeHome, appCreatorFunc, appExportFunc, addModuleInitFlags)
Expand Down

0 comments on commit 6745f92

Please sign in to comment.