X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=blobdiff_plain;f=src%2Fmain.cpp;h=20bd94884e2894f60769899c46c9f4078b64d30a;hp=d1fbbb11f6a2dd67b16d8909474f2ee9719584c6;hb=a0d2f9a12dad7b33a3f12d85dee8afa4155dbc99;hpb=f077d1ad62cba26b2620c87abba87be7fec15f0d diff --git a/src/main.cpp b/src/main.cpp index d1fbbb1..20bd948 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -820,7 +820,7 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, map& mapTestPoo // Read txindex CTxIndex txindex; bool fFound = true; - if (fMiner && mapTestPool.count(prevout.hash)) + if ((fBlock || fMiner) && mapTestPool.count(prevout.hash)) { // Get txindex from current proposed changes txindex = mapTestPool[prevout.hash]; @@ -880,12 +880,7 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, map& mapTestPoo txindex.vSpent[prevout.n] = posThisTx; // Write back - if (fBlock) - { - if (!txdb.UpdateTxIndex(prevout.hash, txindex)) - return error("ConnectInputs() : UpdateTxIndex failed"); - } - else if (fMiner) + if (fBlock || fMiner) { mapTestPool[prevout.hash] = txindex; } @@ -907,9 +902,8 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, map& mapTestPoo if (fBlock) { - // Add transaction to disk index - if (!txdb.AddTxIndex(*this, posThisTx, pindexBlock->nHeight)) - return error("ConnectInputs() : AddTxPos failed"); + // Add transaction to changes + mapTestPool[GetHash()] = CTxIndex(posThisTx, vout.size()); } else if (fMiner) { @@ -998,16 +992,22 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex) //// issue here: it doesn't know the version unsigned int nTxPos = pindex->nBlockPos + ::GetSerializeSize(CBlock(), SER_DISK) - 1 + GetSizeOfCompactSize(vtx.size()); - map mapUnused; + map mapQueuedChanges; int64 nFees = 0; BOOST_FOREACH(CTransaction& tx, vtx) { CDiskTxPos posThisTx(pindex->nFile, pindex->nBlockPos, nTxPos); nTxPos += ::GetSerializeSize(tx, SER_DISK); - if (!tx.ConnectInputs(txdb, mapUnused, posThisTx, pindex, nFees, true, false)) + if (!tx.ConnectInputs(txdb, mapQueuedChanges, posThisTx, pindex, nFees, true, false)) return false; } + // Write queued txindex changes + for (map::iterator mi = mapQueuedChanges.begin(); mi != mapQueuedChanges.end(); ++mi) + { + if (!txdb.UpdateTxIndex((*mi).first, (*mi).second)) + return error("ConnectBlock() : UpdateTxIndex failed"); + } if (vtx[0].GetValueOut() > GetBlockValue(pindex->nHeight, nFees)) return false;