@@ -335,16 +335,22 @@ export class TapCollector {
335
335
private async filterAndUpdateRavs (
336
336
ravsLastNotFinal : ReceiptAggregateVoucher [ ] ,
337
337
) : Promise < ReceiptAggregateVoucher [ ] > {
338
+ // look for all transactions for that includes senderaddress[] and allocations[]
338
339
const tapSubgraphResponse = await this . findTransactionsForRavs ( ravsLastNotFinal )
339
340
340
- const redeemedRavsNotOnOurDatabase = tapSubgraphResponse . transactions . filter (
341
- ( tx ) =>
342
- ! ravsLastNotFinal . find (
343
- ( rav ) =>
344
- toAddress ( rav . senderAddress ) === toAddress ( tx . sender . id ) &&
345
- toAddress ( rav . allocationId ) === toAddress ( tx . allocationID ) ,
346
- ) ,
347
- )
341
+ // get a list of transacations for ravs marked as not redeemed in our database
342
+ const redeemedRavsNotOnOurDatabase = tapSubgraphResponse . transactions . filter ( ( tx ) => {
343
+ // check if exists in the list sent
344
+ ! ! ravsLastNotFinal . find (
345
+ ( rav ) =>
346
+ // rav has the same sender address as tx
347
+ toAddress ( rav . senderAddress ) === toAddress ( tx . sender . id ) &&
348
+ // rav has the same allocation id as tx
349
+ toAddress ( rav . allocationId ) === toAddress ( tx . allocationID ) &&
350
+ // rav was not redeemed
351
+ ! rav . redeemedAt ,
352
+ )
353
+ } )
348
354
349
355
// for each transaction that is not redeemed on our database
350
356
// but was redeemed on the blockchain, update it to redeemed
@@ -360,7 +366,9 @@ export class TapCollector {
360
366
361
367
// Filter unfinalized RAVS fetched from DB, keeping RAVs that have not yet been redeemed on-chain
362
368
const nonRedeemedRavs = ravsLastNotFinal
369
+ // get all ravs that were marked as redeemed in our database
363
370
. filter ( ( rav ) => ! ! rav . redeemedAt )
371
+ // get all ravs that wasn't possible to find the transaction
364
372
. filter (
365
373
( rav ) =>
366
374
! tapSubgraphResponse . transactions . find (
@@ -396,6 +404,14 @@ export class TapCollector {
396
404
let lastId = ''
397
405
const transactions : TapTransaction [ ] = [ ]
398
406
407
+ const unfinalizedRavsAllocationIds = [
408
+ ...new Set ( ravs . map ( ( value ) => toAddress ( value . allocationId ) . toLowerCase ( ) ) ) ,
409
+ ]
410
+
411
+ const senderAddresses = [
412
+ ...new Set ( ravs . map ( ( value ) => toAddress ( value . senderAddress ) . toLowerCase ( ) ) ) ,
413
+ ]
414
+
399
415
for ( ; ; ) {
400
416
let block : { hash : string } | undefined = undefined
401
417
if ( meta ?. block ?. hash ) {
@@ -445,12 +461,8 @@ export class TapCollector {
445
461
lastId,
446
462
pageSize : PAGE_SIZE ,
447
463
block,
448
- unfinalizedRavsAllocationIds : ravs . map ( ( value ) =>
449
- toAddress ( value . allocationId ) . toLowerCase ( ) ,
450
- ) ,
451
- senderAddresses : ravs . map ( ( value ) =>
452
- toAddress ( value . senderAddress ) . toLowerCase ( ) ,
453
- ) ,
464
+ unfinalizedRavsAllocationIds,
465
+ senderAddresses,
454
466
} ,
455
467
)
456
468
0 commit comments