Skip to content

Commit

Permalink
root configs modified for client cmds
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnukumavat committed Feb 23, 2023
1 parent 15484b9 commit 340ef0e
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 @@ -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 Down

0 comments on commit 340ef0e

Please sign in to comment.