* 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. */
| 1033 | * If blockIndex is provided, the transaction is fetched from the corresponding block. |
| 1034 | */ |
| 1035 | bool 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 |
no test coverage detected