txindex: return optional tx and block hash from FindTx

Co-authored-by: l0rinc <pap.lorinc@gmail.com>
This commit is contained in:
Andrew Toth
2026-08-13 22:03:25 -04:00
parent e34b8d5a7d
commit 4b08baed72
5 changed files with 32 additions and 30 deletions

View File

@@ -146,15 +146,13 @@ CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMe
if (ptx) return ptx;
}
if (g_txindex) {
CTransactionRef tx;
uint256 block_hash;
if (g_txindex->FindTx(hash, block_hash, tx)) {
if (!block_index || block_index->GetBlockHash() == block_hash) {
if (auto result{g_txindex->FindTx(hash)}) {
if (!block_index || block_index->GetBlockHash() == result->block_hash) {
// Don't return the transaction if the provided block hash doesn't match.
// The case where a transaction appears in multiple blocks (e.g. reorgs or
// BIP30) is handled by the block lookup below.
hashBlock = block_hash;
return tx;
hashBlock = result->block_hash;
return result->tx;
}
}
}