From 608889dce768fb0d867b7aa6bf40cc7f8fe0a2ba Mon Sep 17 00:00:00 2001 From: Samuel Laferriere <samlaf92@gmail.com> Date: Mon, 2 Oct 2023 21:33:56 -0700 Subject: [PATCH] added example dial constructor for elchainreader --- chainio/elcontracts/reader.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/chainio/elcontracts/reader.go b/chainio/elcontracts/reader.go index 43b238b9..5f54c782 100644 --- a/chainio/elcontracts/reader.go +++ b/chainio/elcontracts/reader.go @@ -80,6 +80,30 @@ func NewELChainReader( }, nil } +// Dial follows the geth constructor name convention, and is a low level contructor that +// builds a new ELChainReader from config values as opposed to other data types +func Dial( + rpcHttpUrl string, + rpcWsUrl string, + slasherAddr gethcommon.Address, + blsPubKeyCompendiumAddr gethcommon.Address, + logger logging.Logger, +) (*ELChainReader, error) { + ethHttpClient, err := eth.NewClient(rpcHttpUrl) + if err != nil { + panic(err) + } + ethWsClient, err := eth.NewClient(rpcWsUrl) + if err != nil { + panic(err) + } + elContractsClient, err := clients.NewELContractsChainClient(slasherAddr, blsPubKeyCompendiumAddr, ethHttpClient, ethWsClient, logger) + if err != nil { + panic(err) + } + return NewELChainReader(elContractsClient, logger, ethHttpClient) +} + func (r *ELChainReader) IsOperatorRegistered(ctx context.Context, operator types.Operator) (bool, error) { isOperator, err := r.elContractsClient.IsOperator( &bind.CallOpts{},