Skip to content

Commit

Permalink
handle false-positive txid index hit
Browse files Browse the repository at this point in the history
  • Loading branch information
romanz committed Dec 2, 2023
1 parent 5aba2a1 commit 18a31e3
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl Tracker {
) -> Result<Option<(BlockHash, Transaction)>> {
// Note: there are two blocks with coinbase transactions having same txid (see BIP-30)
let blockhashes = self.index.filter_by_txid(txid);
let result = daemon
Ok(daemon
.for_blocks(blockhashes, |blockhash, block| {
let mut visitor = FindTransaction::new(txid);
match bsl::Block::visit(&block, &mut visitor) {
Expand All @@ -114,9 +114,8 @@ impl Tracker {
}
visitor.tx_found().map(|tx| (blockhash, tx))
})?
.first()
.cloned()
.flatten();
Ok(result)
.into_iter()
.filter_map(|e| e) // skip non-matching blocks, in case of a false-positive index hit
.next()) // return first match
}
}

0 comments on commit 18a31e3

Please sign in to comment.