@@ -24,15 +24,15 @@ import (
2424 "github.com/smartcontractkit/timelock-worker/pkg/isclosed"
2525)
2626
27- // Worker represents a worker instance.
28- // address is an array of addresses as expected by ethereum.FilterQuery,
29- // but it's enforced only to one address in the logic.
30- type Worker struct {
27+ // WorkerEVM represents an EVM worker instance.
28+ // addresses is an array of addresses as expected by ethereum.FilterQuery,
29+ // but it's enforced only to one addresses in the logic.
30+ type WorkerEVM struct {
3131 ethClient * ethclient.Client
3232 contract * contracts.RBACTimelock
3333 executeContract * contracts.RBACTimelock
3434 abi * abi.ABI
35- address []common.Address
35+ addresses []common.Address
3636 fromBlock * big.Int
3737 pollPeriod int64
3838 listenerPollPeriod int64
@@ -47,12 +47,12 @@ var httpSchemes = []string{"http", "https"}
4747
4848var validNodeUrlSchemes = []string {"http" , "https" , "ws" , "wss" }
4949
50- // NewTimelockWorker initializes and returns a timelockWorker.
50+ // NewTimelockWorkerEVM initializes and returns a timelockWorker.
5151// It's a singleton, so further executions will retrieve the same timelockWorker.
52- func NewTimelockWorker (
52+ func NewTimelockWorkerEVM (
5353 nodeURL , timelockAddress , callProxyAddress , privateKey string , fromBlock * big.Int ,
5454 pollPeriod int64 , listenerPollPeriod int64 , pollSize uint64 , dryRun bool , logger * zap.SugaredLogger ,
55- ) (* Worker , error ) {
55+ ) (* WorkerEVM , error ) {
5656 // Sanity check on each provided variable before allocating more resources.
5757 u , err := url .ParseRequestURI (nodeURL )
5858 if err != nil {
@@ -64,11 +64,11 @@ func NewTimelockWorker(
6464 }
6565
6666 if ! common .IsHexAddress (timelockAddress ) {
67- return nil , fmt .Errorf ("timelock address provided is not valid: %s" , timelockAddress )
67+ return nil , fmt .Errorf ("timelock addresses provided is not valid: %s" , timelockAddress )
6868 }
6969
7070 if ! common .IsHexAddress (callProxyAddress ) {
71- return nil , fmt .Errorf ("call proxy address provided is not valid: %s" , callProxyAddress )
71+ return nil , fmt .Errorf ("call proxy addresses provided is not valid: %s" , callProxyAddress )
7272 }
7373
7474 if pollPeriod <= 0 {
@@ -105,7 +105,7 @@ func NewTimelockWorker(
105105 }
106106
107107 // The contract ABI give grants capabilities such as parsing events and accessing to fields.
108- // As NewTimelock only accepts one contract, hardcode it to address [0].
108+ // As NewTimelock only accepts one contract, hardcode it to addresses [0].
109109 timelockContract , err := contracts .NewRBACTimelock (common .HexToAddress (timelockAddress ), ethClient )
110110 if err != nil {
111111 return nil , err
@@ -123,12 +123,12 @@ func NewTimelockWorker(
123123 return nil , err
124124 }
125125
126- tWorker := & Worker {
126+ tWorker := & WorkerEVM {
127127 ethClient : ethClient ,
128128 contract : timelockContract ,
129129 executeContract : executeContract ,
130130 abi : timelockABI ,
131- address : []common.Address {common .HexToAddress (timelockAddress )},
131+ addresses : []common.Address {common .HexToAddress (timelockAddress )},
132132 fromBlock : fromBlock ,
133133 pollPeriod : pollPeriod ,
134134 listenerPollPeriod : listenerPollPeriod ,
@@ -147,9 +147,9 @@ func NewTimelockWorker(
147147 return tWorker , nil
148148}
149149
150- // Listen is the main function of a Timelock Worker .
150+ // Listen is the main function of a Timelock WorkerEVM .
151151// It handles the retrieval of old and new events, contexts and cancellations.
152- func (tw * Worker ) Listen (ctx context.Context ) error {
152+ func (tw * WorkerEVM ) Listen (ctx context.Context ) error {
153153 ctxwc , cancel := signal .NotifyContext (ctx , syscall .SIGINT , syscall .SIGTERM )
154154
155155 // Log timelock-worker configuration.
@@ -199,9 +199,9 @@ func (tw *Worker) Listen(ctx context.Context) error {
199199}
200200
201201// setupFilterQuery returns an ethereum.FilterQuery initialized to watch the Timelock contract.
202- func (tw * Worker ) setupFilterQuery (fromBlock , toBlock * big.Int ) ethereum.FilterQuery {
202+ func (tw * WorkerEVM ) setupFilterQuery (fromBlock , toBlock * big.Int ) ethereum.FilterQuery {
203203 return ethereum.FilterQuery {
204- Addresses : tw .address ,
204+ Addresses : tw .addresses ,
205205 FromBlock : fromBlock ,
206206 ToBlock : toBlock ,
207207 Topics : [][]common.Hash {},
@@ -214,7 +214,7 @@ func (tw *Worker) setupFilterQuery(fromBlock, toBlock *big.Int) ethereum.FilterQ
214214// The actual retrieval is performed by either `subscribeNewLogs`, if the node connection
215215// supports subscriptions, or `pollNewLogs` otherwise. In practice, the ethclient library
216216// simply checks if the given node URL is "http(s)" or not.
217- func (tw * Worker ) retrieveNewLogs (ctx context.Context ) (<- chan struct {}, <- chan types.Log , error ) {
217+ func (tw * WorkerEVM ) retrieveNewLogs (ctx context.Context ) (<- chan struct {}, <- chan types.Log , error ) {
218218 if tw .ethClient .Client ().SupportsSubscriptions () {
219219 return tw .subscribeNewLogs (ctx )
220220 }
@@ -223,7 +223,7 @@ func (tw *Worker) retrieveNewLogs(ctx context.Context) (<-chan struct{}, <-chan
223223}
224224
225225// subscribeNewLogs subscribes to a Timelock contract and emit logs through the channel it returns.
226- func (tw * Worker ) subscribeNewLogs (ctx context.Context ) (<- chan struct {}, <- chan types.Log , error ) {
226+ func (tw * WorkerEVM ) subscribeNewLogs (ctx context.Context ) (<- chan struct {}, <- chan types.Log , error ) {
227227 query := tw .setupFilterQuery (tw .fromBlock , nil )
228228 logCh := make (chan types.Log )
229229 done := make (chan struct {})
@@ -285,7 +285,7 @@ func (tw *Worker) subscribeNewLogs(ctx context.Context) (<-chan struct{}, <-chan
285285}
286286
287287// pollNewLogs periodically retrieves logs from the Timelock and emit them through the channel it returns.
288- func (tw * Worker ) pollNewLogs (ctx context.Context ) (<- chan struct {}, <- chan types.Log , error ) {
288+ func (tw * WorkerEVM ) pollNewLogs (ctx context.Context ) (<- chan struct {}, <- chan types.Log , error ) {
289289 lastBlock := tw .fromBlock
290290 logCh := make (chan types.Log )
291291 done := make (chan struct {})
@@ -318,7 +318,7 @@ func (tw *Worker) pollNewLogs(ctx context.Context) (<-chan struct{}, <-chan type
318318
319319// retrieveHistoricalLogs returns a types.Log channel and retrieves all the historical events of a given contract.
320320// Once all the logs have been sent into the channel the function returns and the channel is closed.
321- func (tw * Worker ) retrieveHistoricalLogs (ctx context.Context ) (<- chan struct {}, <- chan types.Log , error ) {
321+ func (tw * WorkerEVM ) retrieveHistoricalLogs (ctx context.Context ) (<- chan struct {}, <- chan types.Log , error ) {
322322 query := tw .setupFilterQuery (tw .fromBlock , nil )
323323 logCh := make (chan types.Log )
324324 done := make (chan struct {})
@@ -360,7 +360,7 @@ func (tw *Worker) retrieveHistoricalLogs(ctx context.Context) (<-chan struct{},
360360 return done , logCh , nil
361361}
362362
363- func (tw * Worker ) fetchAndDispatchLogs (
363+ func (tw * WorkerEVM ) fetchAndDispatchLogs (
364364 ctx context.Context , logCh chan types.Log , fromBlock , currentChainBlock * big.Int ,
365365) * big.Int {
366366 if currentChainBlock == nil {
@@ -411,7 +411,7 @@ func (tw *Worker) fetchAndDispatchLogs(
411411
412412// processLogs is implemented as a fan-in for all the logs channels, merging all the data and handling logs sequentially.
413413// This function is thread safe.
414- func (tw * Worker ) processLogs (ctx context.Context , oldLog , newLog <- chan types.Log ) <- chan struct {} {
414+ func (tw * WorkerEVM ) processLogs (ctx context.Context , oldLog , newLog <- chan types.Log ) <- chan struct {} {
415415 var (
416416 done , newDone , oldDone = make (chan struct {}), make (chan struct {}), make (chan struct {})
417417 ctxwc , cancel = context .WithCancel (ctx )
@@ -468,7 +468,7 @@ func (tw *Worker) processLogs(ctx context.Context, oldLog, newLog <-chan types.L
468468// handleLog handles the logic of parsing every event, its type and actions associated to each one.
469469// CallScheduled events have to be added to the scheduler.
470470// CallExecuted and CallCanceled signals an event that has to be removed from the scheduler.
471- func (tw * Worker ) handleLog (ctx context.Context , log types.Log ) error {
471+ func (tw * WorkerEVM ) handleLog (ctx context.Context , log types.Log ) error {
472472 // Ignore logs with no topics.
473473 if len (log .Topics ) == 0 {
474474 return nil
@@ -499,7 +499,7 @@ func (tw *Worker) handleLog(ctx context.Context, log types.Log) error {
499499
500500// A CallScheduled event should be added to an scheduler only if it's not already done
501501// and it's a valid Operation.
502- func (tw * Worker ) handleEventScheduled (ctx context.Context , log types.Log ) error {
502+ func (tw * WorkerEVM ) handleEventScheduled (ctx context.Context , log types.Log ) error {
503503 cs , err := tw .contract .ParseCallScheduled (log )
504504 if err != nil {
505505 return fmt .Errorf ("failed to parse CallScheduled log: %w" , err )
@@ -532,7 +532,7 @@ func (tw *Worker) handleEventScheduled(ctx context.Context, log types.Log) error
532532}
533533
534534// A CallExecuted which is in Done status should delete the task in the scheduler store.
535- func (tw * Worker ) handleEventExecuted (ctx context.Context , log types.Log ) error {
535+ func (tw * WorkerEVM ) handleEventExecuted (ctx context.Context , log types.Log ) error {
536536 cs , err := tw .contract .ParseCallExecuted (log )
537537 if err != nil {
538538 return fmt .Errorf ("failed to parse CallExecuted log: %w" , err )
@@ -558,7 +558,7 @@ func (tw *Worker) handleEventExecuted(ctx context.Context, log types.Log) error
558558}
559559
560560// A Cancelled which is in Done status should delete the task in the scheduler store.
561- func (tw * Worker ) handleEventCancelled (_ context.Context , log types.Log ) error {
561+ func (tw * WorkerEVM ) handleEventCancelled (_ context.Context , log types.Log ) error {
562562 cs , err := tw .contract .ParseCancelled (log )
563563 if err != nil {
564564 return fmt .Errorf ("failed to parse Cancelled log: %w" , err )
@@ -574,16 +574,16 @@ func (tw *Worker) handleEventCancelled(_ context.Context, log types.Log) error {
574574}
575575
576576// startLog prints the timelock-worker configuration.
577- func (tw * Worker ) startLog () {
577+ func (tw * WorkerEVM ) startLog () {
578578 tw .logger .Info ("timelock-worker started" )
579- tw .logger .Infof ("\t Timelock contract address : %v" , tw .address [0 ])
579+ tw .logger .Infof ("\t Timelock contract addresses : %v" , tw .addresses [0 ])
580580
581581 wallet , err := privateKeyToAddress (tw .privateKey )
582582 if err != nil {
583- tw .logger .Fatal ("\t EOA address : unable to determine" )
583+ tw .logger .Fatal ("\t EOA addresses : unable to determine" )
584584 }
585585
586- tw .logger .Infof ("\t EOA address : %v" , wallet )
586+ tw .logger .Infof ("\t EOA addresses : %v" , wallet )
587587 tw .logger .Infof ("\t Starting from block: %v" , tw .fromBlock )
588588 tw .logger .Infof ("\t Poll Period: %v" , time .Duration (tw .pollPeriod * int64 (time .Second )).String ())
589589 tw .logger .Infof ("\t Event Listener Poll Period: %v" , time .Duration (tw .listenerPollPeriod * int64 (time .Second )).String ())
0 commit comments