[Wallet] optimize return value of InitLoadWallet()

This commit is contained in:
Jonas Schnelli 2016-03-05 16:08:10 -05:00
parent fc7c60d699
commit 15e6e13624
No known key found for this signature in database
GPG key ID: 29D4BCB6416F53EC
2 changed files with 16 additions and 5 deletions

View file

@ -1427,12 +1427,15 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
std::string warningString; std::string warningString;
std::string errorString; std::string errorString;
pwalletMain = CWallet::InitLoadWallet(fDisableWallet, strWalletFile, warningString, errorString); pwalletMain = CWallet::InitLoadWallet(fDisableWallet, strWalletFile, warningString, errorString);
if (!pwalletMain)
return false;
if (!warningString.empty()) if (!warningString.empty())
InitWarning(warningString); InitWarning(warningString);
if (!errorString.empty()) if (!errorString.empty())
{
LogPrintf("%s", errorString);
return InitError(errorString); return InitError(errorString);
}
if (!pwalletMain)
return false;
} }
#else // ENABLE_WALLET #else // ENABLE_WALLET
LogPrintf("No wallet support compiled in!\n"); LogPrintf("No wallet support compiled in!\n");

View file

@ -3002,6 +3002,7 @@ CWallet* CWallet::InitLoadWallet(bool fDisableWallet, const std::string& strWall
CWallet *tempWallet = new CWallet(strWalletFile); CWallet *tempWallet = new CWallet(strWalletFile);
DBErrors nZapWalletRet = tempWallet->ZapWalletTx(vWtx); DBErrors nZapWalletRet = tempWallet->ZapWalletTx(vWtx);
if (nZapWalletRet != DB_LOAD_OK) { if (nZapWalletRet != DB_LOAD_OK) {
errorString = _("Error loading wallet.dat: Wallet corrupted");
uiInterface.InitMessage(_("Error loading wallet.dat: Wallet corrupted")); uiInterface.InitMessage(_("Error loading wallet.dat: Wallet corrupted"));
return NULL; return NULL;
} }
@ -3031,10 +3032,12 @@ CWallet* CWallet::InitLoadWallet(bool fDisableWallet, const std::string& strWall
{ {
errorString += strprintf(_("Wallet needed to be rewritten: restart %s to complete"), _(PACKAGE_NAME)) + "\n"; errorString += strprintf(_("Wallet needed to be rewritten: restart %s to complete"), _(PACKAGE_NAME)) + "\n";
LogPrintf("%s", errorString); LogPrintf("%s", errorString);
return walletInstance;
} }
else else
errorString += _("Error loading wallet.dat") + "\n"; errorString += _("Error loading wallet.dat") + "\n";
if (!errorString.empty())
return NULL;
} }
if (GetBoolArg("-upgradewallet", fFirstRun)) if (GetBoolArg("-upgradewallet", fFirstRun))
@ -3049,7 +3052,10 @@ CWallet* CWallet::InitLoadWallet(bool fDisableWallet, const std::string& strWall
else else
LogPrintf("Allowing wallet upgrade up to %i\n", nMaxVersion); LogPrintf("Allowing wallet upgrade up to %i\n", nMaxVersion);
if (nMaxVersion < walletInstance->GetVersion()) if (nMaxVersion < walletInstance->GetVersion())
{
errorString += _("Cannot downgrade wallet") + "\n"; errorString += _("Cannot downgrade wallet") + "\n";
return NULL;
}
walletInstance->SetMaxVersion(nMaxVersion); walletInstance->SetMaxVersion(nMaxVersion);
} }
@ -3062,13 +3068,15 @@ CWallet* CWallet::InitLoadWallet(bool fDisableWallet, const std::string& strWall
if (walletInstance->GetKeyFromPool(newDefaultKey)) { if (walletInstance->GetKeyFromPool(newDefaultKey)) {
walletInstance->SetDefaultKey(newDefaultKey); walletInstance->SetDefaultKey(newDefaultKey);
if (!walletInstance->SetAddressBook(walletInstance->vchDefaultKey.GetID(), "", "receive")) if (!walletInstance->SetAddressBook(walletInstance->vchDefaultKey.GetID(), "", "receive"))
{
errorString += _("Cannot write default address") += "\n"; errorString += _("Cannot write default address") += "\n";
return NULL;
}
} }
walletInstance->SetBestChain(chainActive.GetLocator()); walletInstance->SetBestChain(chainActive.GetLocator());
} }
LogPrintf("%s", errorString);
LogPrintf(" wallet %15dms\n", GetTimeMillis() - nStart); LogPrintf(" wallet %15dms\n", GetTimeMillis() - nStart);
RegisterValidationInterface(walletInstance); RegisterValidationInterface(walletInstance);
@ -3099,7 +3107,7 @@ CWallet* CWallet::InitLoadWallet(bool fDisableWallet, const std::string& strWall
if (pindexRescan != block) if (pindexRescan != block)
{ {
errorString = _("Prune: last wallet synchronisation goes beyond pruned data. You need to -reindex (download the whole blockchain again in case of pruned node)"); errorString = _("Prune: last wallet synchronisation goes beyond pruned data. You need to -reindex (download the whole blockchain again in case of pruned node)");
return walletInstance; return NULL;
} }
} }