Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add keys cmd to covenant-signer #67

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
)
}
Loading