Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
fix issue where getrawtransaction RPC call does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
krilson committed Jan 24, 2017
1 parent 8b1ee2a commit 7bddd36
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/main.cpp
Expand Up @@ -238,13 +238,20 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans)
// CTransaction and CTxIndex
//

bool CTransaction::ReadFromDisk(CTxDB& txdb, COutPoint prevout, CTxIndex& txindexRet)
bool CTransaction::ReadFromDisk(CTxDB& txdb, const uint256& hash, CTxIndex& txindexRet)
{
SetNull();
if (!txdb.ReadTxIndex(prevout.hash, txindexRet))
if (!txdb.ReadTxIndex(hash, txindexRet))
return false;
if (!ReadFromDisk(txindexRet.pos))
return false;
return true;
}

bool CTransaction::ReadFromDisk(CTxDB& txdb, COutPoint prevout, CTxIndex& txindexRet)
{
if (!ReadFromDisk(txdb, prevout.hash, txindexRet))
return false;
if (prevout.n >= vout.size())
{
SetNull();
Expand Down Expand Up @@ -853,13 +860,31 @@ bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock)
}
CTxDB txdb("r");
CTxIndex txindex;
if (tx.ReadFromDisk(txdb, COutPoint(hash, 0), txindex))
if (tx.ReadFromDisk(txdb, hash, txindex))
{
CBlock block;
if (block.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos, false))
hashBlock = block.GetHash();
return true;
}
// look for transaction in disconnected blocks to find orphaned CoinBase and CoinStake transactions
BOOST_FOREACH(PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex)
{
CBlockIndex* pindex = item.second;
if (pindex == pindexBest || pindex->pnext != 0)
continue;
CBlock block;
if (!block.ReadFromDisk(pindex))
continue;
BOOST_FOREACH(const CTransaction& txOrphan, block.vtx)
{
if (txOrphan.GetHash() == hash)
{
tx = txOrphan;
return true;
}
}
}
}
return false;
}
Expand Down
1 change: 1 addition & 0 deletions src/main.h
Expand Up @@ -369,6 +369,7 @@ class CTransaction
}


bool ReadFromDisk(CTxDB& txdb, const uint256& hash, CTxIndex& txindexRet);
bool ReadFromDisk(CTxDB& txdb, COutPoint prevout, CTxIndex& txindexRet);
bool ReadFromDisk(CTxDB& txdb, COutPoint prevout);
bool ReadFromDisk(COutPoint prevout);
Expand Down

0 comments on commit 7bddd36

Please sign in to comment.