MCPcopy Create free account
hub / github.com/ElementsProject/elements / GetTransaction

Function GetTransaction

src/node/transaction.cpp:125–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123}
124
125CTransactionRef 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

Callers 3

rest_txFunction · 0.85
getrawtransactionFunction · 0.85
gettxoutproofFunction · 0.85

Calls 5

ReadBlockFromDiskFunction · 0.85
FindTxMethod · 0.80
getMethod · 0.45
GetBlockHashMethod · 0.45
GetHashMethod · 0.45

Tested by

no test coverage detected