|
|
@ -143,7 +143,7 @@ void CDBEnv::MakeMock() |
|
|
|
fMockDb = true; |
|
|
|
fMockDb = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CDBEnv::VerifyResult CDBEnv::Verify(const std::string& strFile, bool (*recoverFunc)(const std::string& strFile)) |
|
|
|
CDBEnv::VerifyResult CDBEnv::Verify(const std::string& strFile, recoverFunc_type recoverFunc, std::string& out_backup_filename) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_db); |
|
|
|
LOCK(cs_db); |
|
|
|
assert(mapFileUseCount.count(strFile) == 0); |
|
|
|
assert(mapFileUseCount.count(strFile) == 0); |
|
|
@ -156,11 +156,11 @@ CDBEnv::VerifyResult CDBEnv::Verify(const std::string& strFile, bool (*recoverFu |
|
|
|
return RECOVER_FAIL; |
|
|
|
return RECOVER_FAIL; |
|
|
|
|
|
|
|
|
|
|
|
// Try to recover:
|
|
|
|
// Try to recover:
|
|
|
|
bool fRecovered = (*recoverFunc)(strFile); |
|
|
|
bool fRecovered = (*recoverFunc)(strFile, out_backup_filename); |
|
|
|
return (fRecovered ? RECOVER_OK : RECOVER_FAIL); |
|
|
|
return (fRecovered ? RECOVER_OK : RECOVER_FAIL); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool CDB::Recover(const std::string& filename, void *callbackDataIn, bool (*recoverKVcallback)(void* callbackData, CDataStream ssKey, CDataStream ssValue)) |
|
|
|
bool CDB::Recover(const std::string& filename, void *callbackDataIn, bool (*recoverKVcallback)(void* callbackData, CDataStream ssKey, CDataStream ssValue), std::string& newFilename) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Recovery procedure:
|
|
|
|
// Recovery procedure:
|
|
|
|
// move wallet file to wallet.timestamp.bak
|
|
|
|
// move wallet file to wallet.timestamp.bak
|
|
|
@ -170,7 +170,7 @@ bool CDB::Recover(const std::string& filename, void *callbackDataIn, bool (*reco |
|
|
|
// Set -rescan so any missing transactions will be
|
|
|
|
// Set -rescan so any missing transactions will be
|
|
|
|
// found.
|
|
|
|
// found.
|
|
|
|
int64_t now = GetTime(); |
|
|
|
int64_t now = GetTime(); |
|
|
|
std::string newFilename = strprintf("wallet.%d.bak", now); |
|
|
|
newFilename = strprintf("wallet.%d.bak", now); |
|
|
|
|
|
|
|
|
|
|
|
int result = bitdb.dbenv->dbrename(NULL, filename.c_str(), NULL, |
|
|
|
int result = bitdb.dbenv->dbrename(NULL, filename.c_str(), NULL, |
|
|
|
newFilename.c_str(), DB_AUTO_COMMIT); |
|
|
|
newFilename.c_str(), DB_AUTO_COMMIT); |
|
|
@ -261,18 +261,19 @@ bool CDB::VerifyEnvironment(const std::string& walletFile, const fs::path& dataD |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool CDB::VerifyDatabaseFile(const std::string& walletFile, const fs::path& dataDir, std::string& warningStr, std::string& errorStr, bool (*recoverFunc)(const std::string& strFile)) |
|
|
|
bool CDB::VerifyDatabaseFile(const std::string& walletFile, const fs::path& dataDir, std::string& warningStr, std::string& errorStr, CDBEnv::recoverFunc_type recoverFunc) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (fs::exists(dataDir / walletFile)) |
|
|
|
if (fs::exists(dataDir / walletFile)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CDBEnv::VerifyResult r = bitdb.Verify(walletFile, recoverFunc); |
|
|
|
std::string backup_filename; |
|
|
|
|
|
|
|
CDBEnv::VerifyResult r = bitdb.Verify(walletFile, recoverFunc, backup_filename); |
|
|
|
if (r == CDBEnv::RECOVER_OK) |
|
|
|
if (r == CDBEnv::RECOVER_OK) |
|
|
|
{ |
|
|
|
{ |
|
|
|
warningStr = strprintf(_("Warning: Wallet file corrupt, data salvaged!" |
|
|
|
warningStr = strprintf(_("Warning: Wallet file corrupt, data salvaged!" |
|
|
|
" Original %s saved as %s in %s; if" |
|
|
|
" Original %s saved as %s in %s; if" |
|
|
|
" your balance or transactions are incorrect you should" |
|
|
|
" your balance or transactions are incorrect you should" |
|
|
|
" restore from a backup."), |
|
|
|
" restore from a backup."), |
|
|
|
walletFile, "wallet.{timestamp}.bak", dataDir); |
|
|
|
walletFile, backup_filename, dataDir); |
|
|
|
} |
|
|
|
} |
|
|
|
if (r == CDBEnv::RECOVER_FAIL) |
|
|
|
if (r == CDBEnv::RECOVER_FAIL) |
|
|
|
{ |
|
|
|
{ |
|
|
|