MCPcopy Create free account
hub / github.com/LUX-Core/lux / GetTransaction

Function GetTransaction

src/main.cpp:1775–1840  ·  view source on GitHub ↗

Return transaction in tx, and if it was found inside a block, its hash is placed in hashBlock */

Source from the content-addressed store, hash-verified

1773
1774/** Return transaction in tx, and if it was found inside a block, its hash is placed in hashBlock */
1775bool GetTransaction(const uint256& hash, CTransaction& txOut, const Consensus::Params& consensusParams, uint256& hashBlock, bool fAllowSlow)
1776{
1777 CBlockIndex* pindexSlow = NULL;
1778
1779 //LOCK(cs_main);
1780
1781 CTransactionRef ptx = mempool.get(hash);
1782 if (ptx)
1783 {
1784 txOut = *ptx.get();
1785 return true;
1786 }
1787
1788 if (fTxIndex) {
1789 CDiskTxPos postx;
1790 if (pblocktree->ReadTxIndex(hash, postx)) {
1791 CAutoFile file(OpenBlockFile(postx, true), SER_DISK, CLIENT_VERSION);
1792 if (file.IsNull())
1793 return error("%s: OpenBlockFile failed", __func__);
1794 CBlockHeader header;
1795 try {
1796 file >> header;
1797 fseek(file.Get(), postx.nTxOffset, SEEK_CUR);
1798 file >> txOut;
1799 } catch (const std::exception& e) {
1800 return error("%s: Deserialize or I/O error - %s", __func__, e.what());
1801 }
1802
1803 CBlockIndex* pindexPrev = LookupBlockIndex(header.hashPrevBlock);
1804 int TheHeight = pindexPrev ? pindexPrev->nHeight + 1 : 0;
1805 hashBlock = header.GetHash(TheHeight);
1806 if (txOut.GetHash() != hash)
1807 return error("%s: txid mismatch", __func__);
1808 return true;
1809 }
1810
1811 return false;
1812 }
1813
1814 if (fAllowSlow) { // use coin database to locate block that contains transaction, and scan it
1815 int nHeight = -1;
1816 {
1817 const CCoinsViewCache& view = *pcoinsTip;
1818 const CCoins* coins = view.AccessCoins(hash);
1819 if (coins)
1820 nHeight = coins->nHeight;
1821 }
1822 if (nHeight > 0)
1823 pindexSlow = chainActive[nHeight];
1824 }
1825
1826 if (pindexSlow) {
1827 CBlock block;
1828 if (ReadBlockFromDisk(block, pindexSlow, consensusParams)) {
1829 for (const CTransaction& tx : block.vtx) {
1830 if (tx.GetHash() == hash) {
1831 txOut = tx;
1832 hashBlock = pindexSlow->GetBlockHash();

Callers 15

MutateTxSignFunction · 0.85
rest_txFunction · 0.85
IsIXTXValidFunction · 0.85
purgetxindexFunction · 0.85
ProcessMessageDarksendFunction · 0.85
SignatureValidMethod · 0.85
IsCollateralValidMethod · 0.85
getPrevBlockMethod · 0.85
CheckProofMethod · 0.85
getrawtransactionFunction · 0.85

Calls 12

OpenBlockFileFunction · 0.85
errorFunction · 0.85
LookupBlockIndexFunction · 0.85
ReadBlockFromDiskFunction · 0.85
ReadTxIndexMethod · 0.80
AccessCoinsMethod · 0.80
getMethod · 0.45
IsNullMethod · 0.45
GetMethod · 0.45
whatMethod · 0.45
GetHashMethod · 0.45
GetBlockHashMethod · 0.45

Tested by

no test coverage detected