MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / GetTransaction

Function GetTransaction

src/node/transaction.cpp:143–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

141}
142
143CTransactionRef 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

Callers 3

rest_txFunction · 0.85
gettxoutproofFunction · 0.85
getrawtransactionFunction · 0.85

Calls 5

FindTxMethod · 0.80
getMethod · 0.45
GetBlockHashMethod · 0.45
ReadBlockMethod · 0.45
GetHashMethod · 0.45

Tested by

no test coverage detected