Skip to content

Commit

Permalink
Wallet: Move multiwallet sanity checks to CWallet::Verify, and do other
Browse files Browse the repository at this point in the history
checks on all wallets
  • Loading branch information
luke-jr authored and random-zebra committed May 17, 2021
1 parent b27dcfe commit 647fbc9
Showing 1 changed file with 33 additions and 37 deletions.
70 changes: 33 additions & 37 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2080,40 +2080,44 @@ bool CWallet::Verify()
return true;
}

uiInterface.InitMessage(_("Verifying wallet..."));
std::string walletFile = gArgs.GetArg("-wallet", DEFAULT_WALLET_DAT);
std::string strDataDir = GetDataDir().string();

std::string strError;
if (!CWalletDB::VerifyEnvironment(walletFile, GetDataDir().string(), strError))
return UIError(strError);

if (gArgs.GetBoolArg("-salvagewallet", false)) {
// Recover readable keypairs:
CWallet dummyWallet;
// Even if we don't use this lock in this function, we want to preserve
// lock order in LoadToWallet if query of chain state is needed to know
// tx status. If lock can't be taken, tx confirmation status may be not
// reliable.
LOCK(cs_main);
if (!CWalletDB::Recover(walletFile, (void *)&dummyWallet, CWalletDB::RecoverKeysOnlyFilter))
return false;
}
gArgs.SoftSetArg("-wallet", DEFAULT_WALLET_DAT);
uiInterface.InitMessage(_("Verifying wallet(s)..."));

std::string strWarning;
bool dbV = CWalletDB::VerifyDatabaseFile(walletFile, GetDataDir().string(), strWarning, strError);
if (!strWarning.empty()) {
UIWarning(strWarning);
}
if (!dbV) {
UIError(strError);
return false;
for (const std::string& walletFile : gArgs.GetArgs("-wallet")) {
if (fs::path(walletFile).filename() != walletFile) {
return UIError(_("-wallet parameter must only specify a filename (not a path)"));
} else if (SanitizeString(walletFile, SAFE_CHARS_FILENAME) != walletFile) {
return UIError(_("Invalid characters in -wallet filename"));
}

std::string strError;
if (!CWalletDB::VerifyEnvironment(walletFile, GetDataDir().string(), strError))
return UIError(strError);

if (gArgs.GetBoolArg("-salvagewallet", false)) {
// Recover readable keypairs:
CWallet dummyWallet;
// Even if we don't use this lock in this function, we want to preserve
// lock order in LoadToWallet if query of chain state is needed to know
// tx status. If lock can't be taken, tx confirmation status may be not
// reliable.
LOCK(cs_main);
if (!CWalletDB::Recover(walletFile, (void *)&dummyWallet, CWalletDB::RecoverKeysOnlyFilter))
return false;
}

std::string strWarning;
bool dbV = CWalletDB::VerifyDatabaseFile(walletFile, GetDataDir().string(), strWarning, strError);
if (!strWarning.empty())
UIWarning(strWarning);
if (!dbV) {
return UIError(strError);
}
}

return true;
}



void CWallet::ResendWalletTransactions(CConnman* connman)
{
// Do this infrequently and randomly to avoid giving away
Expand Down Expand Up @@ -4348,15 +4352,7 @@ bool CWallet::InitLoadWallet()
return true;
}

gArgs.SoftSetArg("-wallet", DEFAULT_WALLET_DAT);

for (const std::string& walletFile : gArgs.GetArgs("-wallet")) {
if (fs::path(walletFile).filename() != walletFile) {
return UIError(_("-wallet parameter must only specify a filename (not a path)"));
} else if (SanitizeString(walletFile, SAFE_CHARS_FILENAME) != walletFile) {
return UIError(_("Invalid characters in -wallet filename"));
}

// automatic backups
std::string strWarning, strError;
if(!AutoBackupWallet(walletFile, strWarning, strError)) {
Expand Down

0 comments on commit 647fbc9

Please sign in to comment.