From 5b376b51258ccf02d586aa25abe4ce653711e659 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Sat, 5 Mar 2016 16:08:10 -0500 Subject: [PATCH] [Wallet] optimize return value of InitLoadWallet() --- src/init.cpp | 7 +++++-- src/wallet/wallet.cpp | 14 +++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 03b1a5965..f7a1958ea 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1582,12 +1582,15 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) std::string warningString; std::string errorString; pwalletMain = CWallet::InitLoadWallet(fDisableWallet, clearWitnessCaches, strWalletFile, warningString, errorString); - if (!pwalletMain) - return false; if (!warningString.empty()) InitWarning(warningString); if (!errorString.empty()) + { + LogPrintf("%s", errorString); return InitError(errorString); + } + if (!pwalletMain) + return false; } #else // ENABLE_WALLET LogPrintf("No wallet support compiled in!\n"); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 7ef2b10f7..7f7fbbb16 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4416,6 +4416,7 @@ CWallet* CWallet::InitLoadWallet( CWallet *tempWallet = new CWallet(strWalletFile); DBErrors nZapWalletRet = tempWallet->ZapWalletTx(vWtx); if (nZapWalletRet != DB_LOAD_OK) { + errorString = _("Error loading wallet.dat: Wallet corrupted"); uiInterface.InitMessage(_("Error loading wallet.dat: Wallet corrupted")); return NULL; } @@ -4445,10 +4446,12 @@ CWallet* CWallet::InitLoadWallet( { errorString += strprintf(_("Wallet needed to be rewritten: restart %s to complete"), _(PACKAGE_NAME)) + "\n"; LogPrintf("%s", errorString); - return walletInstance; } else errorString += _("Error loading wallet.dat") + "\n"; + + if (!errorString.empty()) + return NULL; } if (GetBoolArg("-upgradewallet", fFirstRun)) @@ -4463,7 +4466,10 @@ CWallet* CWallet::InitLoadWallet( else LogPrintf("Allowing wallet upgrade up to %i\n", nMaxVersion); if (nMaxVersion < walletInstance->GetVersion()) + { errorString += _("Cannot downgrade wallet") + "\n"; + return NULL; + } walletInstance->SetMaxVersion(nMaxVersion); } @@ -4487,13 +4493,15 @@ CWallet* CWallet::InitLoadWallet( if (walletInstance->GetKeyFromPool(newDefaultKey)) { walletInstance->SetDefaultKey(newDefaultKey); if (!walletInstance->SetAddressBook(walletInstance->vchDefaultKey.GetID(), "", "receive")) + { errorString += _("Cannot write default address") += "\n"; + return NULL; + } } walletInstance->SetBestChain(chainActive.GetLocator()); } - LogPrintf("%s", errorString); LogPrintf(" wallet %15dms\n", GetTimeMillis() - nStart); RegisterValidationInterface(walletInstance); @@ -4527,7 +4535,7 @@ CWallet* CWallet::InitLoadWallet( 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)"); - return walletInstance; + return NULL; } }