Commit bb56249f authored by Sabnock01's avatar Sabnock01

chore: move SignerCLIConfig into op-service

parent a7ff5a81
...@@ -18,6 +18,7 @@ import ( ...@@ -18,6 +18,7 @@ import (
hdwallet "github.com/ethereum-optimism/go-ethereum-hdwallet" hdwallet "github.com/ethereum-optimism/go-ethereum-hdwallet"
opsigner "github.com/ethereum-optimism/optimism/op-signer/client" opsigner "github.com/ethereum-optimism/optimism/op-signer/client"
optls "github.com/ethereum-optimism/optimism/op-service/tls"
) )
func PrivateKeySignerFn(key *ecdsa.PrivateKey, chainID *big.Int) bind.SignerFn { func PrivateKeySignerFn(key *ecdsa.PrivateKey, chainID *big.Int) bind.SignerFn {
...@@ -43,9 +44,9 @@ type SignerFn func(context.Context, common.Address, *types.Transaction) (*types. ...@@ -43,9 +44,9 @@ type SignerFn func(context.Context, common.Address, *types.Transaction) (*types.
type SignerFactory func(chainID *big.Int) SignerFn type SignerFactory func(chainID *big.Int) SignerFn
// SignerFactoryFromConfig considers three ways that signers are created & then creates single factory from those config options. // SignerFactoryFromConfig considers three ways that signers are created & then creates single factory from those config options.
// It can either take a remote signer (via opsigner.CLIConfig) or it can be provided either a mnemonic + derivation path or a private key. // It can either take a remote signer (via optls.SignerCLIConfig) or it can be provided either a mnemonic + derivation path or a private key.
// It prefers the remote signer, then the mnemonic or private key (only one of which can be provided). // It prefers the remote signer, then the mnemonic or private key (only one of which can be provided).
func SignerFactoryFromConfig(l log.Logger, privateKey, mnemonic, hdPath string, signerConfig opsigner.CLIConfig) (SignerFactory, common.Address, error) { func SignerFactoryFromConfig(l log.Logger, privateKey, mnemonic, hdPath string, signerConfig optls.SignerCLIConfig) (SignerFactory, common.Address, error) {
var signer SignerFactory var signer SignerFactory
var fromAddress common.Address var fromAddress common.Address
if signerConfig.Enabled() { if signerConfig.Enabled() {
......
...@@ -108,3 +108,26 @@ func ReadCLIConfigWithPrefix(ctx *cli.Context, flagPrefix string) CLIConfig { ...@@ -108,3 +108,26 @@ func ReadCLIConfigWithPrefix(ctx *cli.Context, flagPrefix string) CLIConfig {
TLSKey: ctx.String(prefixFunc(TLSKeyFlagName)), TLSKey: ctx.String(prefixFunc(TLSKeyFlagName)),
} }
} }
type SignerCLIConfig struct {
Endpoint string
Address string
TLSConfig CLIConfig
}
func (c SignerCLIConfig) Check() error {
if err := c.TLSConfig.Check(); err != nil {
return err
}
if !((c.Endpoint == "" && c.Address == "") || (c.Endpoint != "" && c.Address != "")) {
return errors.New("signer endpoint and address must both be set or not set")
}
return nil
}
func (c SignerCLIConfig) Enabled() bool {
if c.Endpoint != "" && c.Address != "" {
return true
}
return false
}
...@@ -78,7 +78,7 @@ func NewSignerClient(logger log.Logger, endpoint string, tlsConfig optls.CLIConf ...@@ -78,7 +78,7 @@ func NewSignerClient(logger log.Logger, endpoint string, tlsConfig optls.CLIConf
return signer, nil return signer, nil
} }
func NewSignerClientFromConfig(logger log.Logger, config CLIConfig) (*SignerClient, error) { func NewSignerClientFromConfig(logger log.Logger, config optls.SignerCLIConfig) (*SignerClient, error) {
return NewSignerClient(logger, config.Endpoint, config.TLSConfig) return NewSignerClient(logger, config.Endpoint, config.TLSConfig)
} }
......
package client package client
import ( import (
"errors"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
opservice "github.com/ethereum-optimism/optimism/op-service" opservice "github.com/ethereum-optimism/optimism/op-service"
...@@ -32,37 +30,15 @@ func CLIFlags(envPrefix string) []cli.Flag { ...@@ -32,37 +30,15 @@ func CLIFlags(envPrefix string) []cli.Flag {
return flags return flags
} }
type CLIConfig struct { func NewCLIConfig() optls.SignerCLIConfig {
Endpoint string return optls.SignerCLIConfig{
Address string
TLSConfig optls.CLIConfig
}
func NewCLIConfig() CLIConfig {
return CLIConfig{
TLSConfig: optls.NewCLIConfig(), TLSConfig: optls.NewCLIConfig(),
} }
} }
func (c CLIConfig) Check() error {
if err := c.TLSConfig.Check(); err != nil {
return err
}
if !((c.Endpoint == "" && c.Address == "") || (c.Endpoint != "" && c.Address != "")) {
return errors.New("signer endpoint and address must both be set or not set")
}
return nil
}
func (c CLIConfig) Enabled() bool {
if c.Endpoint != "" && c.Address != "" {
return true
}
return false
}
func ReadCLIConfig(ctx *cli.Context) CLIConfig { func ReadCLIConfig(ctx *cli.Context) optls.SignerCLIConfig {
cfg := CLIConfig{ cfg := optls.SignerCLIConfig{
Endpoint: ctx.String(EndpointFlagName), Endpoint: ctx.String(EndpointFlagName),
Address: ctx.String(AddressFlagName), Address: ctx.String(AddressFlagName),
TLSConfig: optls.ReadCLIConfigWithPrefix(ctx, "signer"), TLSConfig: optls.ReadCLIConfigWithPrefix(ctx, "signer"),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment