|
|
@ -24,7 +24,6 @@ |
|
|
|
#include "util.h" |
|
|
|
#include "util.h" |
|
|
|
#include "utilmoneystr.h" |
|
|
|
#include "utilmoneystr.h" |
|
|
|
#ifdef ENABLE_WALLET |
|
|
|
#ifdef ENABLE_WALLET |
|
|
|
#include "wallet/db.h" |
|
|
|
|
|
|
|
#include "wallet/wallet.h" |
|
|
|
#include "wallet/wallet.h" |
|
|
|
#include "wallet/walletdb.h" |
|
|
|
#include "wallet/walletdb.h" |
|
|
|
#endif |
|
|
|
#endif |
|
|
@ -151,7 +150,7 @@ void Shutdown() |
|
|
|
StopRPCThreads(); |
|
|
|
StopRPCThreads(); |
|
|
|
#ifdef ENABLE_WALLET |
|
|
|
#ifdef ENABLE_WALLET |
|
|
|
if (pwalletMain) |
|
|
|
if (pwalletMain) |
|
|
|
bitdb.Flush(false); |
|
|
|
pwalletMain->Flush(false); |
|
|
|
GenerateBitcoins(false, NULL, 0); |
|
|
|
GenerateBitcoins(false, NULL, 0); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
StopNode(); |
|
|
|
StopNode(); |
|
|
@ -184,7 +183,7 @@ void Shutdown() |
|
|
|
} |
|
|
|
} |
|
|
|
#ifdef ENABLE_WALLET |
|
|
|
#ifdef ENABLE_WALLET |
|
|
|
if (pwalletMain) |
|
|
|
if (pwalletMain) |
|
|
|
bitdb.Flush(true); |
|
|
|
pwalletMain->Flush(true); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
#ifndef WIN32 |
|
|
|
#ifndef WIN32 |
|
|
|
boost::filesystem::remove(GetPidFile()); |
|
|
|
boost::filesystem::remove(GetPidFile()); |
|
|
@ -852,47 +851,17 @@ bool AppInit2(boost::thread_group& threadGroup) |
|
|
|
LogPrintf("Using wallet %s\n", strWalletFile); |
|
|
|
LogPrintf("Using wallet %s\n", strWalletFile); |
|
|
|
uiInterface.InitMessage(_("Verifying wallet...")); |
|
|
|
uiInterface.InitMessage(_("Verifying wallet...")); |
|
|
|
|
|
|
|
|
|
|
|
if (!bitdb.Open(GetDataDir())) |
|
|
|
std::string warningString; |
|
|
|
{ |
|
|
|
std::string errorString; |
|
|
|
// try moving the database env out of the way
|
|
|
|
|
|
|
|
boost::filesystem::path pathDatabase = GetDataDir() / "database"; |
|
|
|
if (!CWallet::Verify(strWalletFile, warningString, errorString)) |
|
|
|
boost::filesystem::path pathDatabaseBak = GetDataDir() / strprintf("database.%d.bak", GetTime()); |
|
|
|
return false; |
|
|
|
try { |
|
|
|
|
|
|
|
boost::filesystem::rename(pathDatabase, pathDatabaseBak); |
|
|
|
if (!warningString.empty()) |
|
|
|
LogPrintf("Moved old %s to %s. Retrying.\n", pathDatabase.string(), pathDatabaseBak.string()); |
|
|
|
InitWarning(warningString); |
|
|
|
} catch (const boost::filesystem::filesystem_error&) { |
|
|
|
if (!errorString.empty()) |
|
|
|
// failure is ok (well, not really, but it's not worse than what we started with)
|
|
|
|
return InitError(warningString); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// try again
|
|
|
|
|
|
|
|
if (!bitdb.Open(GetDataDir())) { |
|
|
|
|
|
|
|
// if it still fails, it probably means we can't even create the database env
|
|
|
|
|
|
|
|
string msg = strprintf(_("Error initializing wallet database environment %s!"), strDataDir); |
|
|
|
|
|
|
|
return InitError(msg); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (GetBoolArg("-salvagewallet", false)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Recover readable keypairs:
|
|
|
|
|
|
|
|
if (!CWalletDB::Recover(bitdb, strWalletFile, true)) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (boost::filesystem::exists(GetDataDir() / strWalletFile)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
CDBEnv::VerifyResult r = bitdb.Verify(strWalletFile, CWalletDB::Recover); |
|
|
|
|
|
|
|
if (r == CDBEnv::RECOVER_OK) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
string msg = strprintf(_("Warning: wallet.dat corrupt, data salvaged!" |
|
|
|
|
|
|
|
" Original wallet.dat saved as wallet.{timestamp}.bak in %s; if" |
|
|
|
|
|
|
|
" your balance or transactions are incorrect you should" |
|
|
|
|
|
|
|
" restore from a backup."), strDataDir); |
|
|
|
|
|
|
|
InitWarning(msg); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (r == CDBEnv::RECOVER_FAIL) |
|
|
|
|
|
|
|
return InitError(_("wallet.dat corrupt, salvage failed")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} // (!fDisableWallet)
|
|
|
|
} // (!fDisableWallet)
|
|
|
|
#endif // ENABLE_WALLET
|
|
|
|
#endif // ENABLE_WALLET
|
|
|
|
// ********************************************************* Step 6: network initialization
|
|
|
|
// ********************************************************* Step 6: network initialization
|
|
|
|