using namespace std;
using namespace boost;
-void MakeMockTXDB() {
- // In practice this won't do anything because the test framework always initializes
- // an in-memory BDB via bitdb.MakeMock() first, as we use BDB for addresses and wallets.
- if (!bitdb.IsMock())
- bitdb.MakeMock();
-}
-
//
// CTxDB
//
return Write(string("strCheckpointPubKey"), strPubKey);
}
+bool CTxDB::ReadModifierUpgradeTime(unsigned int& nUpgradeTime)
+{
+ return Read(string("nUpgradeTime"), nUpgradeTime);
+}
+
+bool CTxDB::WriteModifierUpgradeTime(const unsigned int& nUpgradeTime)
+{
+ return Write(string("nUpgradeTime"), nUpgradeTime);
+}
+
CBlockIndex static * InsertBlockIndex(uint256 hash)
{
if (hash == 0)
return NULL;
// Return existing
- map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hash);
+ auto mi = mapBlockIndex.find(hash);
if (mi != mapBlockIndex.end())
return (*mi).second;
// Create new
- CBlockIndex* pindexNew = new CBlockIndex();
+ auto pindexNew = new(nothrow) CBlockIndex();
if (!pindexNew)
throw runtime_error("LoadBlockIndex() : new CBlockIndex failed");
mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first;
// Calculate nChainTrust
vector<pair<int, CBlockIndex*> > vSortedByHeight;
vSortedByHeight.reserve(mapBlockIndex.size());
- BOOST_FOREACH(const PAIRTYPE(uint256, CBlockIndex*)& item, mapBlockIndex)
+ for(const auto& item : mapBlockIndex)
{
- CBlockIndex* pindex = item.second;
+ auto pindex = item.second;
vSortedByHeight.push_back(make_pair(pindex->nHeight, pindex));
}
sort(vSortedByHeight.begin(), vSortedByHeight.end());
- BOOST_FOREACH(const PAIRTYPE(int, CBlockIndex*)& item, vSortedByHeight)
+ for(const auto& item : vSortedByHeight)
{
- CBlockIndex* pindex = item.second;
+ auto pindex = item.second;
pindex->nChainTrust = (pindex->pprev ? pindex->pprev->nChainTrust : 0) + pindex->GetBlockTrust();
// ppcoin: calculate stake modifier checksum
pindex->nStakeModifierChecksum = GetStakeModifierChecksum(pindex);
if (!CheckStakeModifierCheckpoints(pindex->nHeight, pindex->nStakeModifierChecksum))
- return error("CTxDB::LoadBlockIndex() : Failed stake modifier checkpoint height=%d, modifier=0x%016"PRI64x, pindex->nHeight, pindex->nStakeModifier);
+ return error("CTxDB::LoadBlockIndex() : Failed stake modifier checkpoint height=%d, modifier=0x%016" PRIx64, pindex->nHeight, pindex->nStakeModifier);
}
// Load hashBestChain pointer to end of best chain
nBestInvalidTrust = bnBestInvalidTrust.getuint256();
// Verify blocks in the best chain
- int nCheckLevel = GetArg("-checklevel", 1);
- int nCheckDepth = GetArg( "-checkblocks", 2500);
+ int nCheckLevel = GetArgInt("-checklevel", 1);
+ int nCheckDepth = GetArgInt( "-checkblocks", 192);
if (nCheckDepth == 0)
nCheckDepth = 1000000000; // suffices until the year 19000
if (nCheckDepth > nBestHeight)
printf("Verifying last %i blocks at level %i\n", nCheckDepth, nCheckLevel);
CBlockIndex* pindexFork = NULL;
map<pair<unsigned int, unsigned int>, CBlockIndex*> mapBlockPos;
- for (CBlockIndex* pindex = pindexBest; pindex && pindex->pprev; pindex = pindex->pprev)
+ for (auto pindex = pindexBest; pindex && pindex->pprev; pindex = pindex->pprev)
{
if (fRequestShutdown || pindex->nHeight < nBestHeight-nCheckDepth)
break;
// check level 2: verify transaction index validity
if (nCheckLevel>1)
{
- pair<unsigned int, unsigned int> pos = make_pair(pindex->nFile, pindex->nBlockPos);
+ auto pos = make_pair(pindex->nFile, pindex->nBlockPos);
mapBlockPos[pos] = pindex;
- BOOST_FOREACH(const CTransaction &tx, block.vtx)
+ for(const auto &tx : block.vtx)
{
- uint256 hashTx = tx.GetHash();
+ auto hashTx = tx.GetHash();
CTxIndex txindex;
if (ReadTxIndex(hashTx, txindex))
{
unsigned int nOutput = 0;
if (nCheckLevel>3)
{
- BOOST_FOREACH(const CDiskTxPos &txpos, txindex.vSpent)
+ for(const CDiskTxPos &txpos : txindex.vSpent)
{
if (!txpos.IsNull())
{
- pair<unsigned int, unsigned int> posFind = make_pair(txpos.nFile, txpos.nBlockPos);
+ auto posFind = make_pair(txpos.nFile, txpos.nBlockPos);
if (!mapBlockPos.count(posFind))
{
printf("LoadBlockIndex(): *** found bad spend at %d, hashBlock=%s, hashTx=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString().c_str(), hashTx.ToString().c_str());
else
{
bool fFound = false;
- BOOST_FOREACH(const CTxIn &txin, txSpend.vin)
+ for(const CTxIn &txin : txSpend.vin)
if (txin.prevout.hash == hashTx && txin.prevout.n == nOutput)
fFound = true;
if (!fFound)
// check level 5: check whether all prevouts are marked spent
if (nCheckLevel>4)
{
- BOOST_FOREACH(const CTxIn &txin, tx.vin)
+ for(const CTxIn &txin : tx.vin)
{
CTxIndex txindex;
if (ReadTxIndex(txin.prevout.hash, txindex))
// Load mapBlockIndex
unsigned int fFlags = DB_SET_RANGE;
- while (true)
+ for ( ; ; )
{
// Read next record
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
CDiskBlockIndex diskindex;
ssValue >> diskindex;
+ uint256 blockHash = diskindex.GetBlockHash();
+
// Construct block index object
- CBlockIndex* pindexNew = InsertBlockIndex(diskindex.GetBlockHash());
+ CBlockIndex* pindexNew = InsertBlockIndex(blockHash);
pindexNew->pprev = InsertBlockIndex(diskindex.hashPrev);
pindexNew->pnext = InsertBlockIndex(diskindex.hashNext);
pindexNew->nFile = diskindex.nFile;
pindexNew->nNonce = diskindex.nNonce;
// Watch for genesis block
- if (pindexGenesisBlock == NULL && diskindex.GetBlockHash() == (!fTestNet ? hashGenesisBlock : hashGenesisBlockTestNet))
+ if (pindexGenesisBlock == NULL && blockHash == (!fTestNet ? hashGenesisBlock : hashGenesisBlockTestNet))
pindexGenesisBlock = pindexNew;
if (!pindexNew->CheckIndex())
break; // if shutdown requested or finished loading block index
}
} // try
- catch (std::exception &e) {
- return error("%s() : deserialize error", __PRETTY_FUNCTION__);
+ catch (const std::exception&) {
+ return error("%s() : deserialize error", BOOST_CURRENT_FUNCTION);
}
}
pcursor->close();