Skip to content

Commit abb3a17

Browse files
committed
common: fix marking already redeemed ravs
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 88fbeff commit abb3a17

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

packages/indexer-common/src/allocations/tap-collector.ts

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -335,16 +335,22 @@ export class TapCollector {
335335
private async filterAndUpdateRavs(
336336
ravsLastNotFinal: ReceiptAggregateVoucher[],
337337
): Promise<ReceiptAggregateVoucher[]> {
338+
// look for all transactions for that includes senderaddress[] and allocations[]
338339
const tapSubgraphResponse = await this.findTransactionsForRavs(ravsLastNotFinal)
339340

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+
})
348354

349355
// for each transaction that is not redeemed on our database
350356
// but was redeemed on the blockchain, update it to redeemed
@@ -360,7 +366,9 @@ export class TapCollector {
360366

361367
// Filter unfinalized RAVS fetched from DB, keeping RAVs that have not yet been redeemed on-chain
362368
const nonRedeemedRavs = ravsLastNotFinal
369+
// get all ravs that were marked as redeemed in our database
363370
.filter((rav) => !!rav.redeemedAt)
371+
// get all ravs that wasn't possible to find the transaction
364372
.filter(
365373
(rav) =>
366374
!tapSubgraphResponse.transactions.find(
@@ -396,6 +404,14 @@ export class TapCollector {
396404
let lastId = ''
397405
const transactions: TapTransaction[] = []
398406

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+
399415
for (;;) {
400416
let block: { hash: string } | undefined = undefined
401417
if (meta?.block?.hash) {
@@ -445,12 +461,8 @@ export class TapCollector {
445461
lastId,
446462
pageSize: PAGE_SIZE,
447463
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,
454466
},
455467
)
456468

0 commit comments

Comments
 (0)