Skip to content

Commit 647fbc9

Browse files
luke-jrrandom-zebra
authored andcommitted
Wallet: Move multiwallet sanity checks to CWallet::Verify, and do other
checks on all wallets
1 parent b27dcfe commit 647fbc9

File tree

1 file changed

+33
-37
lines changed

1 file changed

+33
-37
lines changed

src/wallet/wallet.cpp

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,40 +2080,44 @@ bool CWallet::Verify()
20802080
return true;
20812081
}
20822082

2083-
uiInterface.InitMessage(_("Verifying wallet..."));
2084-
std::string walletFile = gArgs.GetArg("-wallet", DEFAULT_WALLET_DAT);
2085-
std::string strDataDir = GetDataDir().string();
2086-
2087-
std::string strError;
2088-
if (!CWalletDB::VerifyEnvironment(walletFile, GetDataDir().string(), strError))
2089-
return UIError(strError);
2090-
2091-
if (gArgs.GetBoolArg("-salvagewallet", false)) {
2092-
// Recover readable keypairs:
2093-
CWallet dummyWallet;
2094-
// Even if we don't use this lock in this function, we want to preserve
2095-
// lock order in LoadToWallet if query of chain state is needed to know
2096-
// tx status. If lock can't be taken, tx confirmation status may be not
2097-
// reliable.
2098-
LOCK(cs_main);
2099-
if (!CWalletDB::Recover(walletFile, (void *)&dummyWallet, CWalletDB::RecoverKeysOnlyFilter))
2100-
return false;
2101-
}
2083+
gArgs.SoftSetArg("-wallet", DEFAULT_WALLET_DAT);
2084+
uiInterface.InitMessage(_("Verifying wallet(s)..."));
21022085

2103-
std::string strWarning;
2104-
bool dbV = CWalletDB::VerifyDatabaseFile(walletFile, GetDataDir().string(), strWarning, strError);
2105-
if (!strWarning.empty()) {
2106-
UIWarning(strWarning);
2107-
}
2108-
if (!dbV) {
2109-
UIError(strError);
2110-
return false;
2086+
for (const std::string& walletFile : gArgs.GetArgs("-wallet")) {
2087+
if (fs::path(walletFile).filename() != walletFile) {
2088+
return UIError(_("-wallet parameter must only specify a filename (not a path)"));
2089+
} else if (SanitizeString(walletFile, SAFE_CHARS_FILENAME) != walletFile) {
2090+
return UIError(_("Invalid characters in -wallet filename"));
2091+
}
2092+
2093+
std::string strError;
2094+
if (!CWalletDB::VerifyEnvironment(walletFile, GetDataDir().string(), strError))
2095+
return UIError(strError);
2096+
2097+
if (gArgs.GetBoolArg("-salvagewallet", false)) {
2098+
// Recover readable keypairs:
2099+
CWallet dummyWallet;
2100+
// Even if we don't use this lock in this function, we want to preserve
2101+
// lock order in LoadToWallet if query of chain state is needed to know
2102+
// tx status. If lock can't be taken, tx confirmation status may be not
2103+
// reliable.
2104+
LOCK(cs_main);
2105+
if (!CWalletDB::Recover(walletFile, (void *)&dummyWallet, CWalletDB::RecoverKeysOnlyFilter))
2106+
return false;
2107+
}
2108+
2109+
std::string strWarning;
2110+
bool dbV = CWalletDB::VerifyDatabaseFile(walletFile, GetDataDir().string(), strWarning, strError);
2111+
if (!strWarning.empty())
2112+
UIWarning(strWarning);
2113+
if (!dbV) {
2114+
return UIError(strError);
2115+
}
21112116
}
2117+
21122118
return true;
21132119
}
21142120

2115-
2116-
21172121
void CWallet::ResendWalletTransactions(CConnman* connman)
21182122
{
21192123
// Do this infrequently and randomly to avoid giving away
@@ -4348,15 +4352,7 @@ bool CWallet::InitLoadWallet()
43484352
return true;
43494353
}
43504354

4351-
gArgs.SoftSetArg("-wallet", DEFAULT_WALLET_DAT);
4352-
43534355
for (const std::string& walletFile : gArgs.GetArgs("-wallet")) {
4354-
if (fs::path(walletFile).filename() != walletFile) {
4355-
return UIError(_("-wallet parameter must only specify a filename (not a path)"));
4356-
} else if (SanitizeString(walletFile, SAFE_CHARS_FILENAME) != walletFile) {
4357-
return UIError(_("Invalid characters in -wallet filename"));
4358-
}
4359-
43604356
// automatic backups
43614357
std::string strWarning, strError;
43624358
if(!AutoBackupWallet(walletFile, strWarning, strError)) {

0 commit comments

Comments
 (0)