| 123 | } |
| 124 | |
| 125 | CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const uint256& hash, const Consensus::Params& consensusParams, uint256& hashBlock) |
| 126 | { |
| 127 | if (mempool && !block_index) { |
| 128 | CTransactionRef ptx = mempool->get(hash); |
| 129 | if (ptx) return ptx; |
| 130 | } |
| 131 | if (g_txindex) { |
| 132 | CTransactionRef tx; |
| 133 | uint256 block_hash; |
| 134 | if (g_txindex->FindTx(hash, block_hash, tx)) { |
| 135 | if (!block_index || block_index->GetBlockHash() == block_hash) { |
| 136 | // Don't return the transaction if the provided block hash doesn't match. |
| 137 | // The case where a transaction appears in multiple blocks (e.g. reorgs or |
| 138 | // BIP30) is handled by the block lookup below. |
| 139 | hashBlock = block_hash; |
| 140 | return tx; |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | if (block_index) { |
| 145 | CBlock block; |
| 146 | if (ReadBlockFromDisk(block, block_index, consensusParams)) { |
| 147 | for (const auto& tx : block.vtx) { |
| 148 | if (tx->GetHash() == hash) { |
| 149 | hashBlock = block_index->GetBlockHash(); |
| 150 | return tx; |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | return nullptr; |
| 156 | } |
| 157 | } // namespace node |
no test coverage detected