diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp --- a/src/wallet/init.cpp +++ b/src/wallet/init.cpp @@ -326,7 +326,18 @@ wallet_file)); } - if (!CWallet::Verify(chainParams, wallet_file, salvage_wallet)) { + std::string error_string; + std::string warning_string; + bool verify_success = + CWallet::Verify(chainParams, wallet_file, salvage_wallet, + error_string, warning_string); + if (!error_string.empty()) { + InitError(error_string); + } + if (!warning_string.empty()) { + InitWarning(warning_string); + } + if (!verify_success) { return false; } } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1198,7 +1198,8 @@ //! Verify wallet naming and perform salvage on the wallet if required static bool Verify(const CChainParams &chainParams, std::string wallet_file, - bool salvage_wallet); + bool salvage_wallet, std::string &error_string, + std::string &warning_string); /** * Initializes the wallet, returns a new CWallet instance or a null pointer diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4229,7 +4229,8 @@ } bool CWallet::Verify(const CChainParams &chainParams, std::string wallet_file, - bool salvage_wallet) { + bool salvage_wallet, std::string &error_string, + std::string &warning_string) { // Do some checking on wallet path. It should be either a: // // 1. Path where a directory can be created. @@ -4243,28 +4244,29 @@ (path_type == fs::symlink_file && fs::is_directory(wallet_path)) || (path_type == fs::regular_file && fs::path(wallet_file).filename() == wallet_file))) { - return InitError( - strprintf(_("Invalid -wallet path '%s'. -wallet path should point " - "to a directory where wallet.dat and " - "database/log.?????????? files can be stored, a " - "location where such a directory could be created, " - "or (for backwards compatibility) the name of an " - "existing data file in -walletdir (%s)"), - wallet_file, GetWalletDir())); + error_string = + strprintf("Invalid -wallet path '%s'. -wallet path should point to " + "a directory where wallet.dat and " + "database/log.?????????? files can be stored, a location " + "where such a directory could be created, " + "or (for backwards compatibility) the name of an " + "existing data file in -walletdir (%s)", + wallet_file, GetWalletDir()); + return false; } // Make sure that the wallet path doesn't clash with an existing wallet path for (auto wallet : GetWallets()) { if (fs::absolute(wallet->GetName(), GetWalletDir()) == wallet_path) { - return InitError(strprintf(_("Error loading wallet %s. Duplicate " - "-wallet filename specified."), - wallet_file)); + error_string = strprintf("Error loading wallet %s. Duplicate " + "-wallet filename specified.", + wallet_file); + return false; } } - std::string strError; - if (!WalletBatch::VerifyEnvironment(wallet_path, strError)) { - return InitError(strError); + if (!WalletBatch::VerifyEnvironment(wallet_path, error_string)) { + return false; } if (salvage_wallet) { @@ -4279,18 +4281,8 @@ } } - std::string strWarning; - bool dbV = - WalletBatch::VerifyDatabaseFile(wallet_path, strWarning, strError); - if (!strWarning.empty()) { - InitWarning(strWarning); - } - if (!dbV) { - InitError(strError); - return false; - } - - return true; + return WalletBatch::VerifyDatabaseFile(wallet_path, warning_string, + error_string); } CWallet *CWallet::CreateWalletFromFile(const CChainParams &chainParams,