@@ -338,31 +338,8 @@ export class TapCollector {
338
338
// look for all transactions for that includes senderaddress[] and allocations[]
339
339
const tapSubgraphResponse = await this . findTransactionsForRavs ( ravsLastNotFinal )
340
340
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
- } )
354
-
355
- // for each transaction that is not redeemed on our database
356
- // but was redeemed on the blockchain, update it to redeemed
357
- if ( redeemedRavsNotOnOurDatabase . length > 0 ) {
358
- for ( const rav of redeemedRavsNotOnOurDatabase ) {
359
- await this . markRavAsRedeemed (
360
- toAddress ( rav . allocationID ) ,
361
- toAddress ( rav . sender . id ) ,
362
- rav . timestamp ,
363
- )
364
- }
365
- }
341
+ // check for redeemed ravs in tx list but not marked as redeemed in our database
342
+ this . markRavsInTransactionsAsRedeemed ( tapSubgraphResponse , ravsLastNotFinal )
366
343
367
344
// Filter unfinalized RAVS fetched from DB, keeping RAVs that have not yet been redeemed on-chain
368
345
const nonRedeemedRavs = ravsLastNotFinal
@@ -397,6 +374,40 @@ export class TapCollector {
397
374
} )
398
375
}
399
376
377
+ public async markRavsInTransactionsAsRedeemed (
378
+ tapSubgraphResponse : TapSubgraphResponse ,
379
+ ravsLastNotFinal : ReceiptAggregateVoucher [ ] ,
380
+ ) {
381
+ // get a list of transactions for ravs marked as not redeemed in our database
382
+ const redeemedRavsNotOnOurDatabase = tapSubgraphResponse . transactions
383
+ // get only the transactions that exists, this prevents errors marking as redeemed
384
+ // transactions for different senders with the same allocation id
385
+ . filter ( ( tx ) => {
386
+ // check if exists in the ravsLastNotFinal list
387
+ ! ! ravsLastNotFinal . find (
388
+ ( rav ) =>
389
+ // rav has the same sender address as tx
390
+ toAddress ( rav . senderAddress ) === toAddress ( tx . sender . id ) &&
391
+ // rav has the same allocation id as tx
392
+ toAddress ( rav . allocationId ) === toAddress ( tx . allocationID ) &&
393
+ // rav was marked as not redeemed in the db
394
+ ! rav . redeemedAt ,
395
+ )
396
+ } )
397
+
398
+ // for each transaction that is not redeemed on our database
399
+ // but was redeemed on the blockchain, update it to redeemed
400
+ if ( redeemedRavsNotOnOurDatabase . length > 0 ) {
401
+ for ( const rav of redeemedRavsNotOnOurDatabase ) {
402
+ await this . markRavAsRedeemed (
403
+ toAddress ( rav . allocationID ) ,
404
+ toAddress ( rav . sender . id ) ,
405
+ rav . timestamp ,
406
+ )
407
+ }
408
+ }
409
+ }
410
+
400
411
public async findTransactionsForRavs (
401
412
ravs : ReceiptAggregateVoucher [ ] ,
402
413
) : Promise < TapSubgraphResponse > {
0 commit comments