Skip to content

Commit

Permalink
chore: Add keys cmd to covenant-signer (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
gitferry authored Dec 16, 2024
1 parent b7bccc5 commit 6919f4a
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

* [#63](https://github.com/babylonlabs-io/covenant-emulator/pull/63) Add babylon
address to keys command output and fix casing in dockerfile
* [#67](https://github.com/babylonlabs-io/covenant-emulator/pull/67) Add keys cmd to covenant-signer

## v0.10.0

Expand Down
39 changes: 39 additions & 0 deletions covenant-signer/cmd/helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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"
)

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())
}
28 changes: 20 additions & 8 deletions covenant-signer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"path/filepath"

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

Expand All @@ -12,18 +14,28 @@ 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")
defaultConfigDir = btcutil.AppDataDir("signer", false)
defaultConfigPath = filepath.Join(defaultConfigDir, "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{}),
}

cmd.PersistentFlags().String(flags.FlagHome, defaultConfigDir, "The application home directory")
return cmd
}

// Execute executes the root command.
func Execute() error {
return rootCmd.Execute()
Expand All @@ -33,7 +45,7 @@ func init() {
rootCmd.PersistentFlags().StringVar(
&configPath,
configPathKey,
dafaultConfigPath,
defaultConfigPath,
"path to the configuration file",
)
}

0 comments on commit 6919f4a

Please sign in to comment.