@@ -135,6 +135,32 @@ func (b *BatchPollConnector) SubscribeForBlocks(ctx context.Context, errC chan e
135135 return headerSubscription , nil
136136}
137137
138+ func (b * BatchPollConnector ) GetLatest (ctx context.Context ) (latest , finalized , safe uint64 , err error ) {
139+ block , err := GetBlockByFinality (ctx , b .Connector , Latest )
140+ if err != nil {
141+ return 0 , 0 , 0 , fmt .Errorf ("failed to get latest block: %w" , err )
142+ }
143+ latest = block .Number .Uint64 ()
144+
145+ block , err = GetBlockByFinality (ctx , b .Connector , Finalized )
146+ if err != nil {
147+ return 0 , 0 , 0 , fmt .Errorf ("failed to get finalized block: %w" , err )
148+ }
149+ finalized = block .Number .Uint64 ()
150+
151+ if b .generateSafe {
152+ safe = finalized
153+ } else {
154+ block , err = GetBlockByFinality (ctx , b .Connector , Safe )
155+ if err != nil {
156+ return 0 , 0 , 0 , fmt .Errorf ("failed to get safe block: %w" , err )
157+ }
158+ safe = block .Number .Uint64 ()
159+ }
160+
161+ return
162+ }
163+
138164// pollBlocks polls for the latest blocks (finalized, safe and latest), compares them to the last ones, and publishes any new ones.
139165// In the case of an error, it returns the last blocks that were passed in, otherwise it returns the new blocks.
140166func (b * BatchPollConnector ) pollBlocks (ctx context.Context , sink chan <- * NewBlock , prevBlocks Blocks ) (Blocks , error ) {
0 commit comments