Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 697 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Return transaction in txOut, and if it was found inside a block, its hash is | * Return transaction in txOut, and if it was found inside a block, its hash is | ||||
* placed in hashBlock. If blockIndex is provided, the transaction is fetched | * placed in hashBlock. If blockIndex is provided, the transaction is fetched | ||||
* from the corresponding block. | * from the corresponding block. | ||||
*/ | */ | ||||
bool GetTransaction(const TxId &txid, CTransactionRef &txOut, | bool GetTransaction(const TxId &txid, CTransactionRef &txOut, | ||||
const Consensus::Params ¶ms, BlockHash &hashBlock, | const Consensus::Params ¶ms, BlockHash &hashBlock, | ||||
bool fAllowSlow, const CBlockIndex *const blockIndex) { | const CBlockIndex *const block_index) { | ||||
CBlockIndex const *pindexSlow = blockIndex; | |||||
LOCK(cs_main); | LOCK(cs_main); | ||||
if (!blockIndex) { | if (block_index == nullptr) { | ||||
CTransactionRef ptx = g_mempool.get(txid); | CTransactionRef ptx = g_mempool.get(txid); | ||||
if (ptx) { | if (ptx) { | ||||
txOut = ptx; | txOut = ptx; | ||||
return true; | return true; | ||||
} | } | ||||
if (g_txindex) { | if (g_txindex) { | ||||
return g_txindex->FindTx(txid, hashBlock, txOut); | return g_txindex->FindTx(txid, hashBlock, txOut); | ||||
} | } | ||||
} else { | |||||
// use coin database to locate block that contains transaction, and scan | |||||
// it | |||||
if (fAllowSlow) { | |||||
const Coin &coin = AccessByTxid(*pcoinsTip, txid); | |||||
if (!coin.IsSpent()) { | |||||
pindexSlow = ::ChainActive()[coin.GetHeight()]; | |||||
} | |||||
} | |||||
} | |||||
if (pindexSlow) { | |||||
CBlock block; | CBlock block; | ||||
if (ReadBlockFromDisk(block, pindexSlow, params)) { | if (ReadBlockFromDisk(block, block_index, params)) { | ||||
for (const auto &tx : block.vtx) { | for (const auto &tx : block.vtx) { | ||||
if (tx->GetId() == txid) { | if (tx->GetId() == txid) { | ||||
txOut = tx; | txOut = tx; | ||||
hashBlock = pindexSlow->GetBlockHash(); | hashBlock = block_index->GetBlockHash(); | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 4,992 Lines • Show Last 20 Lines |