@@ -6,51 +6,56 @@ import (
66 "errors"
77
88 "github.com/rs/zerolog"
9- "github.com/smartcontractkit/chainlink-testing-framework/sentinel/internal "
9+ "github.com/smartcontractkit/chainlink-testing-framework/sentinel/api "
1010)
1111
1212// ChainPollerConfig holds the configuration for the ChainPoller.
1313type ChainPollerConfig struct {
14- BlockchainClient internal .BlockchainClient
15- Logger zerolog.Logger
14+ BlockchainClient api .BlockchainClient
15+ Logger * zerolog.Logger
1616 ChainID int64
1717}
1818
1919// ChainPoller is responsible for polling logs from the blockchain.
2020type ChainPoller struct {
21- Config ChainPollerConfig
21+ blockchainClient api.BlockchainClient
22+ logger zerolog.Logger
23+ chainID int64
2224}
2325
2426// NewChainPoller initializes a new ChainPoller.
2527func NewChainPoller (cfg ChainPollerConfig ) (* ChainPoller , error ) {
2628 if cfg .BlockchainClient == nil {
2729 return nil , errors .New ("blockchain client cannot be nil" )
2830 }
29- if cfg .Logger .GetLevel () == zerolog .NoLevel {
30- return nil , errors .New ("logger cannot be nil" )
31+ if cfg .Logger == nil {
32+ return nil , errors .New ("no logger passed" )
33+ }
34+ if cfg .ChainID < 1 {
35+ return nil , errors .New ("chain ID not set" )
3136 }
3237
33- cfg . Logger = cfg .Logger .With ().Str ("component" , "ChainPoller" ).Logger ().With ().Int64 ("ChainID" , cfg .ChainID ).Logger ()
38+ logger : = cfg .Logger .With ().Str ("component" , "ChainPoller" ).Logger ().With ().Int64 ("ChainID" , cfg .ChainID ).Logger ()
3439
3540 return & ChainPoller {
36- Config : cfg ,
41+ blockchainClient : cfg .BlockchainClient ,
42+ logger : logger ,
43+ chainID : cfg .ChainID ,
3744 }, nil
3845}
3946
4047// Poll fetches logs from the blockchain based on the provided filter queries.
41- func (cp * ChainPoller ) Poll (ctx context.Context , filterQueries []internal .FilterQuery ) ([]internal .Log , error ) {
42- var allLogs []internal .Log
48+ func (cp * ChainPoller ) FilterLogs (ctx context.Context , filterQueries []api .FilterQuery ) ([]api .Log , error ) {
49+ var allLogs []api .Log
4350
4451 for _ , query := range filterQueries {
45- logs , err := cp .Config . BlockchainClient .FilterLogs (ctx , query )
52+ logs , err := cp .blockchainClient .FilterLogs (ctx , query )
4653 if err != nil {
47- cp .Config . Logger .Error ().Err (err ).Interface ("query" , query ).Msg ("Failed to filter logs" )
54+ cp .logger .Error ().Err (err ).Interface ("query" , query ).Msg ("Failed to filter logs" )
4855 continue
4956 }
5057 allLogs = append (allLogs , logs ... )
5158 }
5259
5360 return allLogs , nil
5461}
55-
56- var _ ChainPollerInterface = (* ChainPoller )(nil )
0 commit comments