mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 23:18:14 +01:00
[wallet] Pass error message back from CWallet::Verify()
Pass an error message back from CWallet::Verify(), and call InitError/InitWarning from WalletInit::Verify(). This means that we can call CWallet::Verify() independently from WalletInit and not have InitErrors printed to stdout. It also means that the error can be reported to the user if dynamic wallet load fails.
This commit is contained in:
@@ -3990,7 +3990,7 @@ void CWallet::MarkPreSplitKeys()
|
||||
}
|
||||
}
|
||||
|
||||
bool CWallet::Verify(std::string wallet_file, bool salvage_wallet)
|
||||
bool CWallet::Verify(std::string wallet_file, bool salvage_wallet, std::string& error_string, std::string& warning_string)
|
||||
{
|
||||
// Do some checking on wallet path. It should be either a:
|
||||
//
|
||||
@@ -4004,23 +4004,24 @@ bool CWallet::Verify(std::string wallet_file, bool salvage_wallet)
|
||||
if (!(path_type == fs::file_not_found || path_type == fs::directory_file ||
|
||||
(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 "
|
||||
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()));
|
||||
"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) {
|
||||
@@ -4032,17 +4033,7 @@ bool CWallet::Verify(std::string wallet_file, bool salvage_wallet)
|
||||
}
|
||||
}
|
||||
|
||||
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 std::string& name, const fs::path& path)
|
||||
|
||||
Reference in New Issue
Block a user