Skip to content

Commit 876eb64

Browse files
committed
[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.
1 parent e0e90db commit 876eb64

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

src/wallet/init.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,12 @@ bool WalletInit::Verify() const
207207
return InitError(strprintf(_("Error loading wallet %s. Duplicate -wallet filename specified."), wallet_file));
208208
}
209209

210-
if (!CWallet::Verify(wallet_file, salvage_wallet)) return false;
210+
std::string error_string;
211+
std::string warning_string;
212+
bool verify_success = CWallet::Verify(wallet_file, salvage_wallet, error_string, warning_string);
213+
if (!error_string.empty()) InitError(error_string);
214+
if (!warning_string.empty()) InitWarning(warning_string);
215+
if (!verify_success) return false;
211216
}
212217

213218
return true;

src/wallet/wallet.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3990,7 +3990,7 @@ void CWallet::MarkPreSplitKeys()
39903990
}
39913991
}
39923992

3993-
bool CWallet::Verify(std::string wallet_file, bool salvage_wallet)
3993+
bool CWallet::Verify(std::string wallet_file, bool salvage_wallet, std::string& error_string, std::string& warning_string)
39943994
{
39953995
// Do some checking on wallet path. It should be either a:
39963996
//
@@ -4004,23 +4004,24 @@ bool CWallet::Verify(std::string wallet_file, bool salvage_wallet)
40044004
if (!(path_type == fs::file_not_found || path_type == fs::directory_file ||
40054005
(path_type == fs::symlink_file && fs::is_directory(wallet_path)) ||
40064006
(path_type == fs::regular_file && fs::path(wallet_file).filename() == wallet_file))) {
4007-
return InitError(strprintf(
4008-
_("Invalid -wallet path '%s'. -wallet path should point to a directory where wallet.dat and "
4007+
error_string = strprintf(
4008+
"Invalid -wallet path '%s'. -wallet path should point to a directory where wallet.dat and "
40094009
"database/log.?????????? files can be stored, a location where such a directory could be created, "
4010-
"or (for backwards compatibility) the name of an existing data file in -walletdir (%s)"),
4011-
wallet_file, GetWalletDir()));
4010+
"or (for backwards compatibility) the name of an existing data file in -walletdir (%s)",
4011+
wallet_file, GetWalletDir());
4012+
return false;
40124013
}
40134014

40144015
// Make sure that the wallet path doesn't clash with an existing wallet path
40154016
for (auto wallet : GetWallets()) {
40164017
if (fs::absolute(wallet->GetName(), GetWalletDir()) == wallet_path) {
4017-
return InitError(strprintf(_("Error loading wallet %s. Duplicate -wallet filename specified."), wallet_file));
4018+
error_string = strprintf("Error loading wallet %s. Duplicate -wallet filename specified.", wallet_file);
4019+
return false;
40184020
}
40194021
}
40204022

4021-
std::string strError;
4022-
if (!WalletBatch::VerifyEnvironment(wallet_path, strError)) {
4023-
return InitError(strError);
4023+
if (!WalletBatch::VerifyEnvironment(wallet_path, error_string)) {
4024+
return false;
40244025
}
40254026

40264027
if (salvage_wallet) {
@@ -4032,17 +4033,7 @@ bool CWallet::Verify(std::string wallet_file, bool salvage_wallet)
40324033
}
40334034
}
40344035

4035-
std::string strWarning;
4036-
bool dbV = WalletBatch::VerifyDatabaseFile(wallet_path, strWarning, strError);
4037-
if (!strWarning.empty()) {
4038-
InitWarning(strWarning);
4039-
}
4040-
if (!dbV) {
4041-
InitError(strError);
4042-
return false;
4043-
}
4044-
4045-
return true;
4036+
return WalletBatch::VerifyDatabaseFile(wallet_path, warning_string, error_string);
40464037
}
40474038

40484039
CWallet* CWallet::CreateWalletFromFile(const std::string& name, const fs::path& path)

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
11191119
bool MarkReplaced(const uint256& originalHash, const uint256& newHash);
11201120

11211121
//! Verify wallet naming and perform salvage on the wallet if required
1122-
static bool Verify(std::string wallet_file, bool salvage_wallet);
1122+
static bool Verify(std::string wallet_file, bool salvage_wallet, std::string& error_string, std::string& warning_string);
11231123

11241124
/* Initializes the wallet, returns a new CWallet instance or a null pointer in case of an error */
11251125
static CWallet* CreateWalletFromFile(const std::string& name, const fs::path& path);

0 commit comments

Comments
 (0)