@@ -128,7 +128,7 @@ func (tr *Transformer) Init() error {
128
128
firstBlock , retrieveErr := tr .Retriever .RetrieveFirstBlock ()
129
129
if retrieveErr != nil {
130
130
if retrieveErr == sql .ErrNoRows {
131
- logrus .Error (retrieveErr )
131
+ logrus .Error (fmt . Errorf ( "error retrieving first block: %s" , retrieveErr . Error ()) )
132
132
firstBlock = 0
133
133
} else {
134
134
return fmt .Errorf ("error retrieving first block: %s" , retrieveErr .Error ())
@@ -252,33 +252,19 @@ func (tr *Transformer) Execute() error {
252
252
continue
253
253
}
254
254
255
- // Sort logs by the contract they belong to
256
- // Start by adding every contract addr to the map
257
- // So that if we don't have any logs for it, it is caught and the header is still marked checked for its events
258
- for _ , addr := range tr .contractAddresses {
259
- sortedLogs [addr ] = nil
260
- }
261
255
for _ , log := range allLogs {
262
256
addr := strings .ToLower (log .Address .Hex ())
263
257
sortedLogs [addr ] = append (sortedLogs [addr ], log )
264
258
}
265
259
266
260
// Process logs for each contract
267
261
for conAddr , logs := range sortedLogs {
268
- con := tr .Contracts [conAddr ]
269
- if len (logs ) < 1 {
270
- eventIds := make ([]string , 0 )
271
- for eventName := range con .Events {
272
- eventIds = append (eventIds , strings .ToLower (eventName + "_" + con .Address ))
273
- }
274
- markCheckedErr := tr .HeaderRepository .MarkHeaderCheckedForAll (header .Id , eventIds )
275
- if markCheckedErr != nil {
276
- return fmt .Errorf ("error marking header checked: %s" , markCheckedErr .Error ())
277
- }
262
+ if logs == nil {
278
263
logrus .Tracef ("no logs found for contract %s at block %d, continuing" , conAddr , header .BlockNumber )
279
264
continue
280
265
}
281
266
// Configure converter with this contract
267
+ con := tr .Contracts [conAddr ]
282
268
tr .Converter .Update (con )
283
269
284
270
// Convert logs into batches of log mappings (eventName => []types.Logs
@@ -290,23 +276,22 @@ func (tr *Transformer) Execute() error {
290
276
for eventName , logs := range convertedLogs {
291
277
// If logs for this event are empty, mark them checked at this header and continue
292
278
if len (logs ) < 1 {
293
- eventID := strings .ToLower (eventName + "_" + con .Address )
294
- markCheckedErr := tr .HeaderRepository .MarkHeaderChecked (header .Id , eventID )
295
- if markCheckedErr != nil {
296
- return fmt .Errorf ("error marking header checked: %s" , markCheckedErr .Error ())
297
- }
298
279
logrus .Tracef ("no logs found for event %s on contract %s at block %d, continuing" , eventName , conAddr , header .BlockNumber )
299
280
continue
300
281
}
301
282
// If logs aren't empty, persist them
302
- // Header is marked checked in the transactions
303
283
persistErr := tr .EventRepository .PersistLogs (logs , con .Events [eventName ], con .Address , con .Name )
304
284
if persistErr != nil {
305
285
return fmt .Errorf ("error persisting logs: %s" , persistErr .Error ())
306
286
}
307
287
}
308
288
}
309
289
290
+ markCheckedErr := tr .HeaderRepository .MarkHeaderCheckedForAll (header .Id , tr .eventIds )
291
+ if markCheckedErr != nil {
292
+ return fmt .Errorf ("error marking header checked: %s" , markCheckedErr .Error ())
293
+ }
294
+
310
295
// Poll contracts at this block height
311
296
pollingErr := tr .methodPolling (header , tr .sortedMethodIds )
312
297
if pollingErr != nil {
0 commit comments