Skip to content

Commit 008c360

Browse files
committed
Wallet: Move multiwallet sanity checks to CWallet::Verify, and do other checks on all wallets
1 parent 0f08575 commit 008c360

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

src/wallet/wallet.cpp

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -440,30 +440,40 @@ bool CWallet::Verify()
440440
if (GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET))
441441
return true;
442442

443-
uiInterface.InitMessage(_("Verifying wallet..."));
444-
std::string walletFile = GetArg("-wallet", DEFAULT_WALLET_DAT);
443+
SoftSetArg("-wallet", DEFAULT_WALLET_DAT);
445444

446-
std::string strError;
447-
if (!CWalletDB::VerifyEnvironment(walletFile, GetDataDir().string(), strError))
448-
return InitError(strError);
445+
uiInterface.InitMessage(_("Verifying wallet(s)..."));
449446

450-
if (GetBoolArg("-salvagewallet", false))
451-
{
452-
// Recover readable keypairs:
453-
CWallet dummyWallet;
454-
if (!CWalletDB::Recover(walletFile, (void *)&dummyWallet, CWalletDB::RecoverKeysOnlyFilter))
447+
for (const std::string& walletFile : gArgs.GetArgs("-wallet")) {
448+
if (boost::filesystem::path(walletFile).filename() != walletFile) {
449+
return InitError(_("-wallet parameter must only specify a filename (not a path)"));
450+
} else if (SanitizeString(walletFile, SAFE_CHARS_FILENAME) != walletFile) {
451+
return InitError(_("Invalid characters in -wallet filename"));
452+
}
453+
454+
std::string strError;
455+
if (!CWalletDB::VerifyEnvironment(walletFile, GetDataDir().string(), strError))
456+
return InitError(strError);
457+
458+
if (GetBoolArg("-salvagewallet", false))
459+
{
460+
// Recover readable keypairs:
461+
CWallet dummyWallet;
462+
if (!CWalletDB::Recover(walletFile, (void *)&dummyWallet, CWalletDB::RecoverKeysOnlyFilter))
463+
return false;
464+
}
465+
466+
std::string strWarning;
467+
bool dbV = CWalletDB::VerifyDatabaseFile(walletFile, GetDataDir().string(), strWarning, strError);
468+
if (!strWarning.empty())
469+
InitWarning(strWarning);
470+
if (!dbV)
471+
{
472+
InitError(strError);
455473
return false;
474+
}
456475
}
457476

458-
std::string strWarning;
459-
bool dbV = CWalletDB::VerifyDatabaseFile(walletFile, GetDataDir().string(), strWarning, strError);
460-
if (!strWarning.empty())
461-
InitWarning(strWarning);
462-
if (!dbV)
463-
{
464-
InitError(strError);
465-
return false;
466-
}
467477
return true;
468478
}
469479

@@ -3930,15 +3940,7 @@ bool CWallet::InitLoadWallet()
39303940
return true;
39313941
}
39323942

3933-
SoftSetArg("-wallet", DEFAULT_WALLET_DAT);
3934-
39353943
for (const std::string& walletFile : gArgs.GetArgs("-wallet")) {
3936-
if (boost::filesystem::path(walletFile).filename() != walletFile) {
3937-
return InitError(_("-wallet parameter must only specify a filename (not a path)"));
3938-
} else if (SanitizeString(walletFile, SAFE_CHARS_FILENAME) != walletFile) {
3939-
return InitError(_("Invalid characters in -wallet filename"));
3940-
}
3941-
39423944
CWallet * const pwallet = CreateWalletFromFile(walletFile);
39433945
if (!pwallet) {
39443946
return false;

0 commit comments

Comments
 (0)