DB_INIT_MPOOL |
DB_INIT_TXN |
DB_THREAD |
- DB_PRIVATE |
DB_RECOVER,
S_IRUSR | S_IWUSR);
if (ret > 0)
- throw runtime_error(strprintf("CDB() : error %d opening database environment\n", ret));
+ throw runtime_error(strprintf("CDB() : error %d opening database environment", ret));
fDbEnvInit = true;
}
CRITICAL_BLOCK(cs_db)
--mapFileUseCount[strFile];
strFile = "";
- throw runtime_error(strprintf("CDB() : can't open database file %s, error %d\n", pszFile, ret));
+ throw runtime_error(strprintf("CDB() : can't open database file %s, error %d", pszFile, ret));
}
if (fCreate && !Exists(string("version")))
// Watch for genesis block
if (pindexGenesisBlock == NULL && diskindex.GetBlockHash() == hashGenesisBlock)
pindexGenesisBlock = pindexNew;
+
+ if (!pindexNew->CheckIndex())
+ return error("LoadBlockIndex() : CheckIndex failed at %d", pindexNew->nHeight);
}
else
{
pindexBest = mapBlockIndex[hashBestChain];
nBestHeight = pindexBest->nHeight;
bnBestChainWork = pindexBest->bnChainWork;
- printf("LoadBlockIndex(): hashBestChain=%s height=%d\n", hashBestChain.ToString().substr(0,16).c_str(), nBestHeight);
+ printf("LoadBlockIndex(): hashBestChain=%s height=%d\n", hashBestChain.ToString().substr(0,20).c_str(), nBestHeight);
// Load bnBestInvalidWork, OK if it doesn't exist
ReadBestInvalidWork(bnBestInvalidWork);
CBlockIndex* pindexFork = NULL;
for (CBlockIndex* pindex = pindexBest; pindex && pindex->pprev; pindex = pindex->pprev)
{
+ if (pindex->nHeight < 74000 && !mapArgs.count("-checkblocks"))
+ break;
CBlock block;
if (!block.ReadFromDisk(pindex))
return error("LoadBlockIndex() : block.ReadFromDisk failed");
}
if (pindexFork)
{
+ // Reorg back to the fork
printf("LoadBlockIndex() : *** moving best chain pointer back to block %d\n", pindexFork->nHeight);
CBlock block;
if (!block.ReadFromDisk(pindexFork))
//printf("LoadWallet %s\n", wtx.GetHash().ToString().c_str());
//printf(" %12I64d %s %s %s\n",
// wtx.vout[0].nValue,
- // DateTimeStrFormat("%x %H:%M:%S", wtx.nTime).c_str(),
- // wtx.hashBlock.ToString().substr(0,16).c_str(),
+ // DateTimeStrFormat("%x %H:%M:%S", wtx.GetBlockTime()).c_str(),
+ // wtx.hashBlock.ToString().substr(0,20).c_str(),
// wtx.mapValue["message"].c_str());
}
else if (strType == "key" || strType == "wkey")
}
}
}
+
+void BackupWallet(const string& strDest)
+{
+ while (!fShutdown)
+ {
+ CRITICAL_BLOCK(cs_db)
+ {
+ const string strFile = "wallet.dat";
+ if (!mapFileUseCount.count(strFile) || mapFileUseCount[strFile] == 0)
+ {
+ // Flush log data to the dat file
+ CloseDb(strFile);
+ dbenv.txn_checkpoint(0, 0, 0);
+ dbenv.lsn_reset(strFile.c_str(), 0);
+ mapFileUseCount.erase(strFile);
+
+ // Copy wallet.dat
+ filesystem::path pathSrc(GetDataDir() + "/" + strFile);
+ filesystem::path pathDest(strDest);
+ if (filesystem::is_directory(pathDest))
+ pathDest = pathDest / strFile;
+#if BOOST_VERSION >= 104000
+ filesystem::copy_file(pathSrc, pathDest, filesystem::copy_option::overwrite_if_exists);
+#else
+ filesystem::copy_file(pathSrc, pathDest);
+#endif
+ printf("copied wallet.dat to %s\n", pathDest.string().c_str());
+
+ return;
+ }
+ }
+ Sleep(100);
+ }
+}