Skip to content

Commit

Permalink
Merge pull request #691 from comdex-official/cfix
Browse files Browse the repository at this point in the history
Root configs modified for client commands
  • Loading branch information
dheerajkd30 authored Mar 6, 2023
2 parents 6de8ed8 + 2106afb commit b23b126
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions cmd/comdex/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/config"
"github.com/cosmos/cosmos-sdk/client/debug"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/keys"
Expand All @@ -37,34 +38,42 @@ 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 +87,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 b23b126

Please sign in to comment.