Skip to content

Commit b6dbbf3

Browse files
committed
wallet: Forbid -salvagewallet, -zapwallettxes, and -upgradewallet with
multiple wallets >>> backports bitcoin/bitcoin@9cbe8c8
1 parent 60f9b4b commit b6dbbf3

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

src/init.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -936,24 +936,6 @@ void InitParameterInteraction()
936936
if (gArgs.SoftSetBoolArg("-discover", false))
937937
LogPrintf("%s : parameter interaction: -externalip set -> setting -discover=0\n", __func__);
938938
}
939-
940-
if (gArgs.GetBoolArg("-salvagewallet", false)) {
941-
// Rewrite just private keys: rescan to find transactions
942-
if (gArgs.SoftSetBoolArg("-rescan", true))
943-
LogPrintf("%s : parameter interaction: -salvagewallet=1 -> setting -rescan=1\n", __func__);
944-
}
945-
946-
int zapwallettxes = gArgs.GetArg("-zapwallettxes", 0);
947-
// -zapwallettxes implies dropping the mempool on startup
948-
if (zapwallettxes != 0 && gArgs.SoftSetBoolArg("-persistmempool", false)) {
949-
LogPrintf("%s: parameter interaction: -zapwallettxes=%s -> setting -persistmempool=0\n", __func__, zapwallettxes);
950-
}
951-
952-
// -zapwallettxes implies a rescan
953-
if (zapwallettxes != 0) {
954-
if (gArgs.SoftSetBoolArg("-rescan", true))
955-
LogPrintf("%s : parameter interaction: -zapwallettxes=%s -> setting -rescan=1\n", __func__, zapwallettxes);
956-
}
957939
}
958940

959941
bool InitNUParams()

src/wallet/wallet.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,37 @@ bool CWallet::ParameterInteraction()
654654
return UIError("-sysperms is not allowed in combination with enabled wallet functionality");
655655
}
656656

657+
gArgs.SoftSetArg("-wallet", DEFAULT_WALLET_DAT);
658+
const bool is_multiwallet = gArgs.GetArgs("-wallet").size() > 1;
659+
660+
if (gArgs.GetBoolArg("-salvagewallet", false) && gArgs.SoftSetBoolArg("-rescan", true)) {
661+
if (is_multiwallet) {
662+
return UIError(strprintf("%s is only allowed with a single wallet file", "-salvagewallet"));
663+
}
664+
// Rewrite just private keys: rescan to find transactions
665+
LogPrintf("%s: parameter interaction: -salvagewallet=1 -> setting -rescan=1\n", __func__);
666+
}
667+
668+
int zapwallettxes = gArgs.GetArg("-zapwallettxes", 0);
669+
// -zapwallettxes implies dropping the mempool on startup
670+
if (zapwallettxes != 0 && gArgs.SoftSetBoolArg("-persistmempool", false)) {
671+
LogPrintf("%s: parameter interaction: -zapwallettxes=%s -> setting -persistmempool=0\n", __func__, zapwallettxes);
672+
}
673+
674+
// -zapwallettxes implies a rescan
675+
if (zapwallettxes != 0 && gArgs.SoftSetBoolArg("-rescan", true)) {
676+
if (is_multiwallet) {
677+
return UIError(strprintf("%s is only allowed with a single wallet file", "-zapwallettxes"));
678+
}
679+
LogPrintf("%s: parameter interaction: -zapwallettxes=<mode> -> setting -rescan=1\n", __func__);
680+
}
681+
682+
if (is_multiwallet) {
683+
if (gArgs.GetBoolArg("-upgradewallet", false)) {
684+
return UIError(strprintf("%s is only allowed with a single wallet file", "-upgradewallet"));
685+
}
686+
}
687+
657688
if (gArgs.IsArgSet("-mintxfee")) {
658689
CAmount n = 0;
659690
if (ParseMoney(gArgs.GetArg("-mintxfee", ""), n) && n > 0)
@@ -2080,7 +2111,6 @@ bool CWallet::Verify()
20802111
return true;
20812112
}
20822113

2083-
gArgs.SoftSetArg("-wallet", DEFAULT_WALLET_DAT);
20842114
uiInterface.InitMessage(_("Verifying wallet(s)..."));
20852115

20862116
for (const std::string& walletFile : gArgs.GetArgs("-wallet")) {

0 commit comments

Comments
 (0)