Skip to content

Commit

Permalink
Update config, add function to get backend by type
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcgary committed May 22, 2024
1 parent fd69b88 commit 391355c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
14 changes: 6 additions & 8 deletions cmd/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/Layr-Labs/eigenlayer-payment-updater/pkg/chainClient"
"github.com/Layr-Labs/eigenlayer-payment-updater/pkg/config"
"github.com/Layr-Labs/eigenlayer-payment-updater/pkg/proofDataFetcher/httpProofDataFetcher"
"github.com/Layr-Labs/eigenlayer-payment-updater/pkg/signer/ledger"
"github.com/Layr-Labs/eigenlayer-payment-updater/pkg/signer"
"github.com/Layr-Labs/eigenlayer-payment-updater/pkg/transactor"
"github.com/Layr-Labs/eigenlayer-payment-updater/pkg/updater"
gethcommon "github.com/ethereum/go-ethereum/common"
Expand All @@ -30,13 +30,12 @@ func runUpdater(cfg *config.UpdaterConfig, l *zap.Logger) error {
return err
}

// signer, err := privateKey.NewPrivateKeySigner(cfg.PrivateKey)
signer, err := ledger.NewLedgerSigner(gethcommon.HexToAddress("0xcbe8C3C3c1d60C328ECa0868A607BdbBA9902Abb"))
s, err := signer.GetSignerForBackend(cfg)
if err != nil {
l.Sugar().Error("Failed to create new private key signer", zap.Error(err))
l.Sugar().Fatal("Failed to get signing backend", zap.Error(err))
}

chainClient, err := chainClient.NewChainClient(ethClient, signer, l)
chainClient, err := chainClient.NewChainClient(ethClient, s, l)
if err != nil {
l.Sugar().Errorf("Failed to create new chain client with private key", zap.Error(err))
return err
Expand Down Expand Up @@ -97,9 +96,8 @@ func init() {
updaterCmd.Flags().String("network", "localnet", "Which network to use")
updaterCmd.Flags().String("rpc-url", "", "https://ethereum-holesky-rpc.publicnode.com")
updaterCmd.Flags().String("private-key", "", "An ethereum private key")
updaterCmd.Flags().String("aws-access-key-id", "", "AWS access key ID")
updaterCmd.Flags().String("aws-secret-access-key", "", "AWS secret access key")
updaterCmd.Flags().String("aws-region", "us-east-1", "us-east-1")
updaterCmd.Flags().String("ledger-address", "", "The address of the ledger")
updaterCmd.Flags().String("signing-backend", "", "The signing backend to use")
updaterCmd.Flags().String("s3-output-bucket", "", "s3://<bucket name and path>")
updaterCmd.Flags().String("payment-coordinator-address", "0x56c119bD92Af45eb74443ab14D4e93B7f5C67896", "Ethereum address of the payment coordinator contract")
updaterCmd.Flags().String("proof-store-base-url", "", "HTTP base url where data is stored")
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type UpdaterConfig struct {
RPCUrl string `mapstructure:"rpc_url"`
SigningBackend SigningBackendKind `mapstructure:"signing_backend"`
PrivateKey string `mapstructure:"private_key"`
LedgerAddress string `mapstructure:"ledger_address"`
PaymentCoordinatorAddress string `mapstructure:"payment_coordinator_address"`
ProofStoreBaseUrl string `mapstructure:"proof_store_base_url"`
}
Expand Down Expand Up @@ -129,6 +130,7 @@ func NewUpdaterConfig() *UpdaterConfig {
Network: viper.GetString("network"),
RPCUrl: viper.GetString("rpc_url"),
SigningBackend: parseSigningBackend(viper.GetString("signing_backend")),
LedgerAddress: viper.GetString("ledger_address"),
PrivateKey: viper.GetString("private_key"),
PaymentCoordinatorAddress: viper.GetString("payment_coordinator_address"),
ProofStoreBaseUrl: viper.GetString("proof_store_base_url"),
Expand Down
5 changes: 3 additions & 2 deletions pkg/signer/ledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ type LedgerSigner struct {
address common.Address
}

func NewLedgerSigner(address common.Address) (*LedgerSigner, error) {
func NewLedgerSigner(address string) (*LedgerSigner, error) {
addressParsed := common.HexToAddress(address)
return &LedgerSigner{
address: address,
address: addressParsed,
}, nil
}

Expand Down
14 changes: 14 additions & 0 deletions pkg/signer/signer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package signer

import (
"fmt"
"github.com/Layr-Labs/eigenlayer-payment-updater/pkg/config"
"github.com/Layr-Labs/eigenlayer-payment-updater/pkg/signer/ledger"
"github.com/Layr-Labs/eigenlayer-payment-updater/pkg/signer/privateKey"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"math/big"
Expand All @@ -10,3 +14,13 @@ type Signer interface {
GetTransactOpts(chainId *big.Int) (*bind.TransactOpts, error)
GetAddress() common.Address
}

func GetSignerForBackend(cfg *config.UpdaterConfig) (Signer, error) {
switch cfg.SigningBackend {
case config.SigningBackendKind_PrivateKey:
return privateKey.NewPrivateKeySigner(cfg.PrivateKey)
case config.SigningBackendKind_Ledger:
return ledger.NewLedgerSigner(cfg.LedgerAddress)
}
return nil, fmt.Errorf("unsupported signing backend: %s", cfg.SigningBackend)

Check failure on line 25 in pkg/signer/signer.go

View workflow job for this annotation

GitHub Actions / test

fmt.Errorf format %s has arg cfg.SigningBackend of wrong type github.com/Layr-Labs/eigenlayer-payment-updater/pkg/config.SigningBackendKind
}

0 comments on commit 391355c

Please sign in to comment.