Skip to content

Commit

Permalink
initialize dataapi geth client with address
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-shim committed May 10, 2024
1 parent 2988edc commit 62cf92b
Showing 1 changed file with 41 additions and 37 deletions.
78 changes: 41 additions & 37 deletions disperser/cmd/dataapi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

0 comments on commit 62cf92b

Please sign in to comment.