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

Function GetTransaction

src/validation.cpp:1035–1072  ·  view source on GitHub ↗

* 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 from the corresponding block. */

Source from the content-addressed store, hash-verified

1033 * If blockIndex is provided, the transaction is fetched from the corresponding block.
1034 */
1035bool GetTransaction(const uint256& hash, CTransactionRef& txOut, const Consensus::Params& consensusParams, uint256& hashBlock, bool fAllowSlow, CBlockIndex* blockIndex)
1036{
1037 CBlockIndex* pindexSlow = blockIndex;
1038
1039 LOCK(cs_main);
1040
1041 if (!blockIndex) {
1042 CTransactionRef ptx = mempool.get(hash);
1043 if (ptx) {
1044 txOut = ptx;
1045 return true;
1046 }
1047
1048 if (g_txindex) {
1049 return g_txindex->FindTx(hash, hashBlock, txOut);
1050 }
1051
1052 if (fAllowSlow) { // use coin database to locate block that contains transaction, and scan it
1053 const Coin& coin = AccessByTxid(*pcoinsTip, hash);
1054 if (!coin.IsSpent()) pindexSlow = chainActive[coin.nHeight];
1055 }
1056 }
1057
1058 if (pindexSlow) {
1059 CBlock block;
1060 if (ReadBlockFromDisk(block, pindexSlow, consensusParams)) {
1061 for (const auto& tx : block.vtx) {
1062 if (tx->GetHash() == hash) {
1063 txOut = tx;
1064 hashBlock = pindexSlow->GetBlockHash();
1065 return true;
1066 }
1067 }
1068 }
1069 }
1070
1071 return false;
1072}
1073
1074
1075

Callers 4

rest_txFunction · 0.85
getrawtransactionFunction · 0.85
gettxoutproofFunction · 0.85
getblockstatsFunction · 0.85

Calls 6

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

Tested by

no test coverage detected