| 141 | } |
| 142 | |
| 143 | CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const Txid& hash, const BlockManager& blockman, uint256& hashBlock) |
| 144 | { |
| 145 | if (mempool && !block_index) { |
| 146 | CTransactionRef ptx = mempool->get(hash); |
| 147 | if (ptx) return ptx; |
| 148 | } |
| 149 | if (g_txindex) { |
| 150 | CTransactionRef tx; |
| 151 | uint256 block_hash; |
| 152 | if (g_txindex->FindTx(hash, block_hash, tx)) { |
| 153 | if (!block_index || block_index->GetBlockHash() == block_hash) { |
| 154 | // Don't return the transaction if the provided block hash doesn't match. |
| 155 | // The case where a transaction appears in multiple blocks (e.g. reorgs or |
| 156 | // BIP30) is handled by the block lookup below. |
| 157 | hashBlock = block_hash; |
| 158 | return tx; |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | if (block_index) { |
| 163 | CBlock block; |
| 164 | if (blockman.ReadBlock(block, *block_index)) { |
| 165 | for (const auto& tx : block.vtx) { |
| 166 | if (tx->GetHash() == hash) { |
| 167 | hashBlock = block_index->GetBlockHash(); |
| 168 | return tx; |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | return nullptr; |
| 174 | } |
| 175 | } // namespace node |
no test coverage detected