Skip to content

Commit

Permalink
refactor: make function more clean
Browse files Browse the repository at this point in the history
  • Loading branch information
renlulu committed Apr 29, 2024
1 parent 522ddf6 commit 895ac3d
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions chainio/clients/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ func BuildAll(
}
txMgr := txmgr.NewSimpleTxManager(pkWallet, ethHttpClient, logger, addr)

// creating EL clients: Reader, Writer and Subscriber
elChainReader, elChainWriter, avsRegistryContractBindings, elContractBindings, err := config.buildElClients(
// creating EL clients: Reader, Writer and EigenLayer Contract Bindings
elChainReader, elChainWriter, elContractBindings, err := config.BuildELClients(
ethHttpClient,
txMgr,
logger,
Expand All @@ -103,7 +103,7 @@ func BuildAll(
}

// creating AVS clients: Reader and Writer
avsRegistryChainReader, avsRegistryChainSubscriber, avsRegistryChainWriter, err := config.buildAvsClients(
avsRegistryChainReader, avsRegistryChainSubscriber, avsRegistryChainWriter, avsRegistryContractBindings, err := config.BuildAVSRegistryClients(
elChainReader,
ethHttpClient,
ethWsClient,
Expand All @@ -124,8 +124,8 @@ func BuildAll(
EthWsClient: ethWsClient,
Wallet: pkWallet,
TxManager: txMgr,
AvsRegistryContractBindings: avsRegistryContractBindings,
EigenlayerContractBindings: elContractBindings,
AvsRegistryContractBindings: avsRegistryContractBindings,
Metrics: eigenMetrics,
PrometheusRegistry: promReg,
}, nil
Expand Down Expand Up @@ -166,15 +166,15 @@ func (config *BuildAllConfig) buildEigenLayerContractBindings(
return elContractBindings, nil
}

func (config *BuildAllConfig) buildElClients(
func (config *BuildAllConfig) BuildELClients(
ethHttpClient eth.Client,
txMgr txmgr.TxManager,
logger logging.Logger,
eigenMetrics *metrics.EigenMetrics,
) (*elcontracts.ELChainReader, *elcontracts.ELChainWriter, *utils.AvsRegistryContractBindings, *utils.EigenlayerContractBindings, error) {
) (*elcontracts.ELChainReader, *elcontracts.ELChainWriter, *utils.EigenlayerContractBindings, error) {
avsRegistryContractBindings, err := config.buildAVSRegistryContractBindings(ethHttpClient, logger)
if err != nil {
return nil, nil, nil, nil, err
return nil, nil, nil, err
}

delegationManagerAddr, err := avsRegistryContractBindings.StakeRegistry.Delegation(&bind.CallOpts{})
Expand All @@ -193,7 +193,7 @@ func (config *BuildAllConfig) buildElClients(
logger,
)
if err != nil {
return nil, nil, nil, nil, err
return nil, nil, nil, err
}

// get the Reader for the EL contracts
Expand All @@ -218,16 +218,16 @@ func (config *BuildAllConfig) buildElClients(
txMgr,
)

return elChainReader, elChainWriter, avsRegistryContractBindings, elContractBindings, nil
return elChainReader, elChainWriter, elContractBindings, nil
}

func (config *BuildAllConfig) buildAvsClients(
func (config *BuildAllConfig) BuildAVSRegistryClients(
elReader elcontracts.ELReader,
ethHttpClient eth.Client,
ethWsClient eth.Client,
txMgr txmgr.TxManager,
logger logging.Logger,
) (*avsregistry.AvsRegistryChainReader, *avsregistry.AvsRegistryChainSubscriber, *avsregistry.AvsRegistryChainWriter, error) {
) (*avsregistry.AvsRegistryChainReader, *avsregistry.AvsRegistryChainSubscriber, *avsregistry.AvsRegistryChainWriter, *utils.AvsRegistryContractBindings, error) {

avsRegistryContractBindings, err := chainioutils.NewAVSRegistryContractBindings(
gethcommon.HexToAddress(config.RegistryCoordinatorAddr),
Expand All @@ -236,7 +236,7 @@ func (config *BuildAllConfig) buildAvsClients(
logger,
)
if err != nil {
return nil, nil, nil, types.WrapError(errors.New("Failed to create AVSRegistryContractBindings"), err)
return nil, nil, nil, nil, types.WrapError(errors.New("Failed to create AVSRegistryContractBindings"), err)
}

avsRegistryChainReader := avsregistry.NewAvsRegistryChainReader(
Expand All @@ -261,7 +261,7 @@ func (config *BuildAllConfig) buildAvsClients(
txMgr,
)
if err != nil {
return nil, nil, nil, types.WrapError(errors.New("Failed to create AVSRegistryChainWriter"), err)
return nil, nil, nil, nil, types.WrapError(errors.New("Failed to create AVSRegistryChainWriter"), err)
}

// get the Subscriber for Avs Registry contracts
Expand All @@ -272,10 +272,10 @@ func (config *BuildAllConfig) buildAvsClients(
logger,
)
if err != nil {
return nil, nil, nil, types.WrapError(errors.New("Failed to create ELChainSubscriber"), err)
return nil, nil, nil, nil, types.WrapError(errors.New("Failed to create ELChainSubscriber"), err)
}

return avsRegistryChainReader, avsRegistrySubscriber, avsRegistryChainWriter, nil
return avsRegistryChainReader, avsRegistrySubscriber, avsRegistryChainWriter, avsRegistryContractBindings, nil
}

// Very basic validation that makes sure all fields are nonempty
Expand Down

0 comments on commit 895ac3d

Please sign in to comment.