-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
66 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/babylonlabs-io/babylon/app/params" | ||
bstypes "github.com/babylonlabs-io/babylon/x/btcstaking/types" | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/std" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// PersistClientCtx persist some vars from the cmd or config to the client context. | ||
// It gives preferences to flags over the values in the config. If the flag is not set | ||
// and exists a value in the config that could be used, it will be set in the ctx. | ||
func PersistClientCtx(ctx client.Context) func(cmd *cobra.Command, _ []string) error { | ||
return func(cmd *cobra.Command, _ []string) error { | ||
encCfg := params.DefaultEncodingConfig() | ||
std.RegisterInterfaces(encCfg.InterfaceRegistry) | ||
bstypes.RegisterInterfaces(encCfg.InterfaceRegistry) | ||
|
||
ctx = ctx. | ||
WithCodec(encCfg.Codec). | ||
WithInterfaceRegistry(encCfg.InterfaceRegistry). | ||
WithTxConfig(encCfg.TxConfig). | ||
WithLegacyAmino(encCfg.Amino). | ||
WithInput(os.Stdin) | ||
|
||
// set the default command outputs | ||
cmd.SetOut(cmd.OutOrStdout()) | ||
cmd.SetErr(cmd.ErrOrStderr()) | ||
|
||
if err := client.SetCmdClientContextHandler(ctx, cmd); err != nil { | ||
return err | ||
} | ||
|
||
ctx = client.GetClientContextFromCmd(cmd) | ||
|
||
// updates the ctx in the cmd in case something was modified bt the config | ||
return client.SetCmdClientContext(cmd, ctx) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/client/keys" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(keys.Commands()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters