Skip to content

Commit

Permalink
Adapt signer to phase-2
Browse files Browse the repository at this point in the history
  • Loading branch information
KonradStaniec committed Nov 20, 2024
1 parent 5ceac16 commit ed6bb0b
Show file tree
Hide file tree
Showing 20 changed files with 584 additions and 1,408 deletions.
33 changes: 5 additions & 28 deletions covenant-signer/cmd/signerCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package cmd
import (
"fmt"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/spf13/cobra"

"github.com/babylonlabs-io/covenant-emulator/covenant-signer/btcclient"
"github.com/babylonlabs-io/covenant-emulator/covenant-signer/config"
m "github.com/babylonlabs-io/covenant-emulator/covenant-signer/observability/metrics"
"github.com/babylonlabs-io/covenant-emulator/covenant-signer/signerapp"
Expand Down Expand Up @@ -35,40 +35,17 @@ var runSignerCmd = &cobra.Command{
return err
}

parsedGlobalParams, err := signerapp.NewVersionedParamsRetriever(globalParamPath)
privKey, err := btcec.NewPrivateKey()

if err != nil {
return err
}

fullNodeClient, err := btcclient.NewBtcClient(parsedConfig.BtcNodeConfig)

if err != nil {
return err
}

chainInfo := signerapp.NewBitcoindChainInfo(fullNodeClient)

signerClient, err := btcclient.NewBtcClient(parsedConfig.BtcSignerConfig.ToBtcConfig())

if err != nil {
return err
}

var signer signerapp.ExternalBtcSigner
if parsedConfig.BtcSignerConfig.SignerType == config.PsbtSigner {
fmt.Println("using psbt signer")
signer = signerapp.NewPsbtSigner(signerClient)
} else if parsedConfig.BtcSignerConfig.SignerType == config.PrivKeySigner {
fmt.Println("using privkey signer")
signer = signerapp.NewPrivKeySigner(signerClient)
}
// TODO: Implement other approach to store keys
prk := signerapp.NewHardcodedPrivKeyRetriever(privKey)

app := signerapp.NewSignerApp(
signer,
chainInfo,
parsedGlobalParams,
parsedConfig.BtcNodeConfig.Network,
prk,
)

metrics := m.NewCovenantSignerMetrics()
Expand Down
64 changes: 8 additions & 56 deletions covenant-signer/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,23 @@ const (
)

type Config struct {
BtcNodeConfig BtcConfig `mapstructure:"btc-config"`
BtcSignerConfig BtcSignerConfig `mapstructure:"btc-signer-config"`
Server ServerConfig `mapstructure:"server-config"`
Metrics MetricsConfig `mapstructure:"metrics"`
Server ServerConfig `mapstructure:"server-config"`
Metrics MetricsConfig `mapstructure:"metrics"`
}

func DefaultConfig() *Config {
return &Config{
BtcNodeConfig: *DefaultBtcConfig(),
BtcSignerConfig: *DefaultBtcSignerConfig(),
Server: *DefaultServerConfig(),
Metrics: *DefaultMetricsConfig(),
Server: *DefaultServerConfig(),
Metrics: *DefaultMetricsConfig(),
}
}

type ParsedConfig struct {
BtcNodeConfig *ParsedBtcConfig
BtcSignerConfig *ParsedBtcSignerConfig
ServerConfig *ParsedServerConfig
MetricsConfig *ParsedMetricsConfig
ServerConfig *ParsedServerConfig
MetricsConfig *ParsedMetricsConfig
}

func (cfg *Config) Parse() (*ParsedConfig, error) {
btcConfig, err := cfg.BtcNodeConfig.Parse()
if err != nil {
return nil, err
}

btcSignerConfig, err := cfg.BtcSignerConfig.Parse()

if err != nil {
return nil, err
}

serverConfig, err := cfg.Server.Parse()

if err != nil {
Expand All @@ -63,45 +46,14 @@ func (cfg *Config) Parse() (*ParsedConfig, error) {
}

return &ParsedConfig{
BtcNodeConfig: btcConfig,
BtcSignerConfig: btcSignerConfig,
ServerConfig: serverConfig,
MetricsConfig: metricsConfig,
ServerConfig: serverConfig,
MetricsConfig: metricsConfig,
}, nil
}

const defaultConfigTemplate = `# This is a TOML config file.
# For more information, see https://github.com/toml-lang/toml
# There are two btc related configs
# 1. [btc-config] is config for btc full node which should have transaction indexing
# enabled. This node should be synced and can be open to the public.
# 2. [btc-signer-config] is config for bitcoind daemon which should have only
# wallet functionality, it should run in separate network. This bitcoind instance
# will be used to sign psbt's
[btc-config]
# Btc node host
host = "{{ .BtcNodeConfig.Host }}"
# Btc node user
user = "{{ .BtcNodeConfig.User }}"
# Btc node password
pass = "{{ .BtcNodeConfig.Pass }}"
# Btc network (testnet3|mainnet|regtest|simnet|signet)
network = "{{ .BtcNodeConfig.Network }}"
[btc-signer-config]
# Btc node host
host = "{{ .BtcSignerConfig.Host }}"
# TODO: consider reading user/pass from command line
# Btc node user
user = "{{ .BtcSignerConfig.User }}"
# Btc node password
pass = "{{ .BtcSignerConfig.Pass }}"
# Btc network (testnet3|mainnet|regtest|simnet|signet)
network = "{{ .BtcSignerConfig.Network }}"
# Signer type (psbt|privkey)
signer-type = "{{ .BtcSignerConfig.SignerType }}"
[server-config]
# The address to listen on
host = "{{ .Server.Host }}"
Expand Down
3 changes: 1 addition & 2 deletions covenant-signer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ require (
)

require (
cosmossdk.io/math v1.3.0
github.com/babylonlabs-io/babylon v0.12.1
github.com/babylonlabs-io/networks/parameters v0.2.2
github.com/btcsuite/btcd/btcutil/psbt v1.1.8
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0
github.com/btcsuite/btcwallet/wallet/txauthor v1.3.4
Expand All @@ -67,7 +67,6 @@ require (
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/errors v1.0.1 // indirect
cosmossdk.io/log v1.3.1 // indirect
cosmossdk.io/math v1.3.0 // indirect
cosmossdk.io/store v1.1.0 // indirect
cosmossdk.io/x/circuit v0.1.0 // indirect
cosmossdk.io/x/evidence v0.1.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions covenant-signer/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,6 @@ github.com/aws/aws-sdk-go v1.44.312/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/babylonlabs-io/babylon v0.12.1 h1:Qfmrq3pdDEZGq6DtMXxwiQjx0HD+t+U0cXQzsJfX15U=
github.com/babylonlabs-io/babylon v0.12.1/go.mod h1:ZOrTde9vs2xoqGTFw4xhupu2CMulnpywiuk0eh4kPOw=
github.com/babylonlabs-io/networks/parameters v0.2.2 h1:TCu39fZvjX5f6ZZrjhYe54M6wWxglNewuKu56yE+zrc=
github.com/babylonlabs-io/networks/parameters v0.2.2/go.mod h1:iEJVOzaLsE33vpP7J4u+CRGfkSIfErUAwRmgCFCBpyI=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
Expand Down
Loading

0 comments on commit ed6bb0b

Please sign in to comment.