Skip to content

Commit

Permalink
Merge branch 'main' into sam/docs-import
Browse files Browse the repository at this point in the history
  • Loading branch information
samricotta authored Dec 17, 2024
2 parents 4c1ed11 + 6919f4a commit 9068a22
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 9 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ This flow ensures that all private key operations remain isolated within the
secure Covenant Signer while the emulator handles the blockchain interaction
and validation logic.

![Covenant Architecture](./static/covenant.png)
![Covenant Architecture](./static/covenant.png)
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 9068a22

Please sign in to comment.