Skip to content

Commit

Permalink
Fix filtering of spent boxes in mempool using ModifierId
Browse files Browse the repository at this point in the history
  • Loading branch information
anon-yum2 authored Mar 28, 2024
1 parent 6783dc5 commit 3f9cb45
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,17 @@ case class BlockchainApiRoute(readersHolder: ActorRef, ergoSettings: ErgoSetting
excludeMempoolSpent: Boolean
): Future[Seq[IndexedErgoBox]] = {

val originalLimit = limit

def fetchAndFilter(limit: Int, accumulated: Seq[IndexedErgoBox] = Seq.empty): Future[Seq[IndexedErgoBox]] = {
getHistoryWithMempool.flatMap { case (history, mempool) =>
val addressUtxos = getAddress(addr)(history)
.getOrElse(IndexedErgoAddress(hashErgoTree(addr.script)))
.retrieveUtxos(history, mempool, offset + accumulated.length, limit, sortDir, unconfirmed)

val spentBoxesIdsInMempool: Set[Array[Byte]] = mempool.spentInputs.map(idToBytes).toSet
val spentBoxesIdsInMempool: Set[ModifierId] = mempool.spentInputs.map(bytesToId).toSet
val newUtxos = if (excludeMempoolSpent) {
addressUtxos.filterNot(box => spentBoxesIdsInMempool.contains(idToBytes(box.id)))
addressUtxos.filterNot(box => spentBoxesIdsInMempool.contains(box.id))
} else {
addressUtxos
}
Expand All @@ -271,11 +273,11 @@ case class BlockchainApiRoute(readersHolder: ActorRef, ergoSettings: ErgoSetting
} else {
val maxLimit = 200;
val newLimit = Math.min(limit * 2, maxLimit); // Prevents limit becoming too large
fetchAndFilter(newLimit, updatedAccumulated)
fetchAndFilter(newLimit, updatedAccumulated)
}
}
}
val originalLimit = limit

fetchAndFilter(originalLimit)
}

Expand Down

0 comments on commit 3f9cb45

Please sign in to comment.