Skip to content

Commit

Permalink
add keys cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
gitferry committed Dec 13, 2024
1 parent b7bccc5 commit 48811bb
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 5 deletions.
42 changes: 42 additions & 0 deletions covenant-signer/cmd/helper.go
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)
}
}
9 changes: 9 additions & 0 deletions covenant-signer/cmd/keys.go
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())
}
20 changes: 15 additions & 5 deletions covenant-signer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"path/filepath"

"github.com/btcsuite/btcd/btcutil"
"github.com/cosmos/cosmos-sdk/client"
"github.com/spf13/cobra"
)

Expand All @@ -12,18 +13,27 @@ var (
configPath string
configPathKey = "config"

rootCmd = &cobra.Command{
Use: "covenant-signer",
Short: "remote signing serivce to perform covenant duties",
}

// C:\Users\<username>\AppData\Local\signer on Windows
// ~/.signer on Linux
// ~/Library/Application Support/signer on MacOS
dafaultConfigDir = btcutil.AppDataDir("signer", false)
dafaultConfigPath = filepath.Join(dafaultConfigDir, "config.toml")

rootCmd = NewRootCmd()
)

// NewRootCmd creates a new root command for fpd. It is called once in the main function.
func NewRootCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "covenant-signer",
Short: "remote signing service to perform covenant duties",
SilenceErrors: false,
PersistentPreRunE: PersistClientCtx(client.Context{}),
}

return cmd
}

// Execute executes the root command.
func Execute() error {
return rootCmd.Execute()
Expand Down

0 comments on commit 48811bb

Please sign in to comment.