Browse Source

init.cpp: cosmetic indent changes, preparing for no-wallet mode

0.10
Jeff Garzik 11 years ago committed by Wladimir J. van der Laan
parent
commit
f9ee7a032b
  1. 222
      src/init.cpp

222
src/init.cpp

@ -587,49 +587,51 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
// ********************************************************* Step 5: verify wallet database integrity // ********************************************************* Step 5: verify wallet database integrity
uiInterface.InitMessage(_("Verifying wallet...")); if (1) {
uiInterface.InitMessage(_("Verifying wallet..."));
if (!bitdb.Open(GetDataDir())) if (!bitdb.Open(GetDataDir()))
{ {
// try moving the database env out of the way // try moving the database env out of the way
boost::filesystem::path pathDatabase = GetDataDir() / "database"; boost::filesystem::path pathDatabase = GetDataDir() / "database";
boost::filesystem::path pathDatabaseBak = GetDataDir() / strprintf("database.%"PRId64".bak", GetTime()); boost::filesystem::path pathDatabaseBak = GetDataDir() / strprintf("database.%"PRId64".bak", GetTime());
try { try {
boost::filesystem::rename(pathDatabase, pathDatabaseBak); boost::filesystem::rename(pathDatabase, pathDatabaseBak);
LogPrintf("Moved old %s to %s. Retrying.\n", pathDatabase.string().c_str(), pathDatabaseBak.string().c_str()); LogPrintf("Moved old %s to %s. Retrying.\n", pathDatabase.string().c_str(), pathDatabaseBak.string().c_str());
} catch(boost::filesystem::filesystem_error &error) { } catch(boost::filesystem::filesystem_error &error) {
// failure is ok (well, not really, but it's not worse than what we started with) // failure is ok (well, not really, but it's not worse than what we started with)
} }
// try again // try again
if (!bitdb.Open(GetDataDir())) { if (!bitdb.Open(GetDataDir())) {
// if it still fails, it probably means we can't even create the database env // 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.c_str()); string msg = strprintf(_("Error initializing wallet database environment %s!"), strDataDir.c_str());
return InitError(msg); return InitError(msg);
}
} }
}
if (GetBoolArg("-salvagewallet", false)) if (GetBoolArg("-salvagewallet", false))
{ {
// Recover readable keypairs: // Recover readable keypairs:
if (!CWalletDB::Recover(bitdb, strWalletFile, true)) if (!CWalletDB::Recover(bitdb, strWalletFile, true))
return false; return false;
} }
if (filesystem::exists(GetDataDir() / strWalletFile)) if (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!" CDBEnv::VerifyResult r = bitdb.Verify(strWalletFile, CWalletDB::Recover);
" Original wallet.dat saved as wallet.{timestamp}.bak in %s; if" if (r == CDBEnv::RECOVER_OK)
" your balance or transactions are incorrect you should" {
" restore from a backup."), strDataDir.c_str()); string msg = strprintf(_("Warning: wallet.dat corrupt, data salvaged!"
InitWarning(msg); " Original wallet.dat saved as wallet.{timestamp}.bak in %s; if"
" your balance or transactions are incorrect you should"
" restore from a backup."), strDataDir.c_str());
InitWarning(msg);
}
if (r == CDBEnv::RECOVER_FAIL)
return InitError(_("wallet.dat corrupt, salvage failed"));
} }
if (r == CDBEnv::RECOVER_FAIL) } // (1)
return InitError(_("wallet.dat corrupt, salvage failed"));
}
// ********************************************************* Step 6: network initialization // ********************************************************* Step 6: network initialization
@ -898,92 +900,94 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
// ********************************************************* Step 8: load wallet // ********************************************************* Step 8: load wallet
uiInterface.InitMessage(_("Loading wallet...")); if (1) {
uiInterface.InitMessage(_("Loading wallet..."));
nStart = GetTimeMillis(); nStart = GetTimeMillis();
bool fFirstRun = true; bool fFirstRun = true;
pwalletMain = new CWallet(strWalletFile); pwalletMain = new CWallet(strWalletFile);
DBErrors nLoadWalletRet = pwalletMain->LoadWallet(fFirstRun); DBErrors nLoadWalletRet = pwalletMain->LoadWallet(fFirstRun);
if (nLoadWalletRet != DB_LOAD_OK) if (nLoadWalletRet != DB_LOAD_OK)
{
if (nLoadWalletRet == DB_CORRUPT)
strErrors << _("Error loading wallet.dat: Wallet corrupted") << "\n";
else if (nLoadWalletRet == DB_NONCRITICAL_ERROR)
{ {
string msg(_("Warning: error reading wallet.dat! All keys read correctly, but transaction data" if (nLoadWalletRet == DB_CORRUPT)
" or address book entries might be missing or incorrect.")); strErrors << _("Error loading wallet.dat: Wallet corrupted") << "\n";
InitWarning(msg); else if (nLoadWalletRet == DB_NONCRITICAL_ERROR)
{
string msg(_("Warning: error reading wallet.dat! All keys read correctly, but transaction data"
" or address book entries might be missing or incorrect."));
InitWarning(msg);
}
else if (nLoadWalletRet == DB_TOO_NEW)
strErrors << _("Error loading wallet.dat: Wallet requires newer version of Bitcoin") << "\n";
else if (nLoadWalletRet == DB_NEED_REWRITE)
{
strErrors << _("Wallet needed to be rewritten: restart Bitcoin to complete") << "\n";
LogPrintf("%s", strErrors.str().c_str());
return InitError(strErrors.str());
}
else
strErrors << _("Error loading wallet.dat") << "\n";
} }
else if (nLoadWalletRet == DB_TOO_NEW)
strErrors << _("Error loading wallet.dat: Wallet requires newer version of Bitcoin") << "\n"; if (GetBoolArg("-upgradewallet", fFirstRun))
else if (nLoadWalletRet == DB_NEED_REWRITE)
{ {
strErrors << _("Wallet needed to be rewritten: restart Bitcoin to complete") << "\n"; int nMaxVersion = GetArg("-upgradewallet", 0);
LogPrintf("%s", strErrors.str().c_str()); if (nMaxVersion == 0) // the -upgradewallet without argument case
return InitError(strErrors.str()); {
LogPrintf("Performing wallet upgrade to %i\n", FEATURE_LATEST);
nMaxVersion = CLIENT_VERSION;
pwalletMain->SetMinVersion(FEATURE_LATEST); // permanently upgrade the wallet immediately
}
else
LogPrintf("Allowing wallet upgrade up to %i\n", nMaxVersion);
if (nMaxVersion < pwalletMain->GetVersion())
strErrors << _("Cannot downgrade wallet") << "\n";
pwalletMain->SetMaxVersion(nMaxVersion);
} }
else
strErrors << _("Error loading wallet.dat") << "\n";
}
if (GetBoolArg("-upgradewallet", fFirstRun)) if (fFirstRun)
{
int nMaxVersion = GetArg("-upgradewallet", 0);
if (nMaxVersion == 0) // the -upgradewallet without argument case
{ {
LogPrintf("Performing wallet upgrade to %i\n", FEATURE_LATEST); // Create new keyUser and set as default key
nMaxVersion = CLIENT_VERSION; RandAddSeedPerfmon();
pwalletMain->SetMinVersion(FEATURE_LATEST); // permanently upgrade the wallet immediately
} CPubKey newDefaultKey;
else if (pwalletMain->GetKeyFromPool(newDefaultKey)) {
LogPrintf("Allowing wallet upgrade up to %i\n", nMaxVersion); pwalletMain->SetDefaultKey(newDefaultKey);
if (nMaxVersion < pwalletMain->GetVersion()) if (!pwalletMain->SetAddressBook(pwalletMain->vchDefaultKey.GetID(), "", "receive"))
strErrors << _("Cannot downgrade wallet") << "\n"; strErrors << _("Cannot write default address") << "\n";
pwalletMain->SetMaxVersion(nMaxVersion); }
}
if (fFirstRun) pwalletMain->SetBestChain(chainActive.GetLocator());
{
// Create new keyUser and set as default key
RandAddSeedPerfmon();
CPubKey newDefaultKey;
if (pwalletMain->GetKeyFromPool(newDefaultKey)) {
pwalletMain->SetDefaultKey(newDefaultKey);
if (!pwalletMain->SetAddressBook(pwalletMain->vchDefaultKey.GetID(), "", "receive"))
strErrors << _("Cannot write default address") << "\n";
} }
pwalletMain->SetBestChain(chainActive.GetLocator()); LogPrintf("%s", strErrors.str().c_str());
} LogPrintf(" wallet %15"PRId64"ms\n", GetTimeMillis() - nStart);
LogPrintf("%s", strErrors.str().c_str());
LogPrintf(" wallet %15"PRId64"ms\n", GetTimeMillis() - nStart);
RegisterWallet(pwalletMain); RegisterWallet(pwalletMain);
CBlockIndex *pindexRescan = chainActive.Tip(); CBlockIndex *pindexRescan = chainActive.Tip();
if (GetBoolArg("-rescan", false)) if (GetBoolArg("-rescan", false))
pindexRescan = chainActive.Genesis();
else
{
CWalletDB walletdb(strWalletFile);
CBlockLocator locator;
if (walletdb.ReadBestBlock(locator))
pindexRescan = chainActive.FindFork(locator);
else
pindexRescan = chainActive.Genesis(); pindexRescan = chainActive.Genesis();
} else
if (chainActive.Tip() && chainActive.Tip() != pindexRescan) {
{ CWalletDB walletdb(strWalletFile);
uiInterface.InitMessage(_("Rescanning...")); CBlockLocator locator;
LogPrintf("Rescanning last %i blocks (from block %i)...\n", chainActive.Height() - pindexRescan->nHeight, pindexRescan->nHeight); if (walletdb.ReadBestBlock(locator))
nStart = GetTimeMillis(); pindexRescan = chainActive.FindFork(locator);
pwalletMain->ScanForWalletTransactions(pindexRescan, true); else
LogPrintf(" rescan %15"PRId64"ms\n", GetTimeMillis() - nStart); pindexRescan = chainActive.Genesis();
pwalletMain->SetBestChain(chainActive.GetLocator()); }
nWalletDBUpdated++; if (chainActive.Tip() && chainActive.Tip() != pindexRescan)
} {
uiInterface.InitMessage(_("Rescanning..."));
LogPrintf("Rescanning last %i blocks (from block %i)...\n", chainActive.Height() - pindexRescan->nHeight, pindexRescan->nHeight);
nStart = GetTimeMillis();
pwalletMain->ScanForWalletTransactions(pindexRescan, true);
LogPrintf(" rescan %15"PRId64"ms\n", GetTimeMillis() - nStart);
pwalletMain->SetBestChain(chainActive.GetLocator());
nWalletDBUpdated++;
}
} // (1)
// ********************************************************* Step 9: import blocks // ********************************************************* Step 9: import blocks

Loading…
Cancel
Save