Skip to content

Commit 9cbe8c8

Browse files
committed
wallet: Forbid -salvagewallet, -zapwallettxes, and -upgradewallet with multiple wallets
1 parent a2a5f3f commit 9cbe8c8

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/wallet/wallet.cpp

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

443-
SoftSetArg("-wallet", DEFAULT_WALLET_DAT);
444-
445443
uiInterface.InitMessage(_("Verifying wallet(s)..."));
446444

447445
for (const std::string& walletFile : gArgs.GetArgs("-wallet")) {
@@ -3968,6 +3966,9 @@ void CWallet::postInitProcess(CScheduler& scheduler)
39683966

39693967
bool CWallet::ParameterInteraction()
39703968
{
3969+
SoftSetArg("-wallet", DEFAULT_WALLET_DAT);
3970+
const bool is_multiwallet = gArgs.GetArgs("-wallet").size() > 1;
3971+
39713972
if (GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET))
39723973
return true;
39733974

@@ -3976,15 +3977,27 @@ bool CWallet::ParameterInteraction()
39763977
}
39773978

39783979
if (GetBoolArg("-salvagewallet", false) && SoftSetBoolArg("-rescan", true)) {
3980+
if (is_multiwallet) {
3981+
return InitError(strprintf("%s is only allowed with a single wallet file", "-salvagewallet"));
3982+
}
39793983
// Rewrite just private keys: rescan to find transactions
39803984
LogPrintf("%s: parameter interaction: -salvagewallet=1 -> setting -rescan=1\n", __func__);
39813985
}
39823986

39833987
// -zapwallettx implies a rescan
39843988
if (GetBoolArg("-zapwallettxes", false) && SoftSetBoolArg("-rescan", true)) {
3989+
if (is_multiwallet) {
3990+
return InitError(strprintf("%s is only allowed with a single wallet file", "-zapwallettxes"));
3991+
}
39853992
LogPrintf("%s: parameter interaction: -zapwallettxes=<mode> -> setting -rescan=1\n", __func__);
39863993
}
39873994

3995+
if (is_multiwallet) {
3996+
if (GetBoolArg("-upgradewallet", false)) {
3997+
return InitError(strprintf("%s is only allowed with a single wallet file", "-upgradewallet"));
3998+
}
3999+
}
4000+
39884001
if (GetBoolArg("-sysperms", false))
39894002
return InitError("-sysperms is not allowed in combination with enabled wallet functionality");
39904003
if (GetArg("-prune", 0) && GetBoolArg("-rescan", false))

0 commit comments

Comments
 (0)