From 62cf92bb461877e390c6e8a5e290c264e142220a Mon Sep 17 00:00:00 2001 From: Ian Shim Date: Fri, 10 May 2024 16:30:22 -0700 Subject: [PATCH] initialize dataapi geth client with address --- disperser/cmd/dataapi/main.go | 78 ++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/disperser/cmd/dataapi/main.go b/disperser/cmd/dataapi/main.go index 5dd318bc38..2bd6d1cc78 100644 --- a/disperser/cmd/dataapi/main.go +++ b/disperser/cmd/dataapi/main.go @@ -20,7 +20,6 @@ import ( "github.com/Layr-Labs/eigenda/disperser/dataapi/prometheus" "github.com/Layr-Labs/eigenda/disperser/dataapi/subgraph" walletsdk "github.com/Layr-Labs/eigensdk-go/chainio/clients/wallet" - "github.com/Layr-Labs/eigensdk-go/logging" "github.com/Layr-Labs/eigensdk-go/signerv2" gethcommon "github.com/ethereum/go-ethereum/common" @@ -82,17 +81,51 @@ func RunDataApi(ctx *cli.Context) error { return err } - client, err := geth.NewMultiHomingClient(config.EthClientConfig, gethcommon.HexToAddress(config.FireblocksConfig.WalletAddress), logger) - if err != nil { - return err + var wallet walletsdk.Wallet + var client common.EthClient + if !config.FireblocksConfig.Disable { + client, err = geth.NewMultiHomingClient(config.EthClientConfig, gethcommon.HexToAddress(config.FireblocksConfig.WalletAddress), logger) + if err != nil { + return fmt.Errorf("failed to create multi-homing client: %w", err) + } + wallet, err = common.NewFireblocksWallet(&config.FireblocksConfig, client, logger) + if err != nil { + return fmt.Errorf("failed to create Fireblocks wallet: %w", err) + } + } else if len(config.EthClientConfig.PrivateKeyString) > 0 { + privateKey, err := crypto.HexToECDSA(config.EthClientConfig.PrivateKeyString) + if err != nil { + return fmt.Errorf("failed to parse private key: %w", err) + } + client, err = geth.NewMultiHomingClient(config.EthClientConfig, gethcommon.HexToAddress(config.FireblocksConfig.WalletAddress), logger) + if err != nil { + return fmt.Errorf("failed to create multi-homing client: %w", err) + } + chainID, err := client.ChainID(context.Background()) + if err != nil { + return fmt.Errorf("failed to get chain ID: %w", err) + } + signerV2, address, err := signerv2.SignerFromConfig(signerv2.Config{PrivateKey: privateKey}, chainID) + if err != nil { + return err + } + wallet, err = walletsdk.NewPrivateKeyWallet(client, signerV2, address, logger.With("component", "PrivateKeyWallet")) + if err != nil { + return err + } + logger.Info("Initialized PrivateKey wallet", "address", address.Hex()) + } else { + return errors.New("no wallet is configured. Either Fireblocks or PrivateKey wallet should be configured") } - tx, err := coreeth.NewTransactor(logger, client, config.BLSOperatorStateRetrieverAddr, config.EigenDAServiceManagerAddr) - if err != nil { - return err + if wallet == nil { + return errors.New("wallet is nil") + } + if client == nil { + return errors.New("client is nil") } - wallet, err := getWallet(config, client, logger) + tx, err := coreeth.NewTransactor(logger, client, config.BLSOperatorStateRetrieverAddr, config.EigenDAServiceManagerAddr) if err != nil { return err } @@ -158,32 +191,3 @@ func RunDataApi(ctx *cli.Context) error { return err } - -func getWallet(config Config, ethClient common.EthClient, logger logging.Logger) (walletsdk.Wallet, error) { - var wallet walletsdk.Wallet - if !config.FireblocksConfig.Disable { - return common.NewFireblocksWallet(&config.FireblocksConfig, ethClient, logger) - } else if len(config.EthClientConfig.PrivateKeyString) > 0 { - privateKey, err := crypto.HexToECDSA(config.EthClientConfig.PrivateKeyString) - if err != nil { - return nil, fmt.Errorf("failed to parse private key: %w", err) - } - chainID, err := ethClient.ChainID(context.Background()) - if err != nil { - return nil, fmt.Errorf("failed to get chain ID: %w", err) - } - signerV2, address, err := signerv2.SignerFromConfig(signerv2.Config{PrivateKey: privateKey}, chainID) - if err != nil { - return nil, err - } - wallet, err = walletsdk.NewPrivateKeyWallet(ethClient, signerV2, address, logger.With("component", "PrivateKeyWallet")) - if err != nil { - return nil, err - } - logger.Info("Initialized PrivateKey wallet", "address", address.Hex()) - } else { - return nil, errors.New("no wallet is configured. Either Fireblocks or PrivateKey wallet should be configured") - } - - return wallet, nil -}