Skip to content

Commit

Permalink
wallet: Forbid -salvagewallet, -zapwallettxes, and -upgradewallet with
Browse files Browse the repository at this point in the history
multiple wallets

>>> backports bitcoin/bitcoin@9cbe8c8
  • Loading branch information
random-zebra committed May 17, 2021
1 parent 60f9b4b commit b6dbbf3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
18 changes: 0 additions & 18 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,24 +936,6 @@ void InitParameterInteraction()
if (gArgs.SoftSetBoolArg("-discover", false))
LogPrintf("%s : parameter interaction: -externalip set -> setting -discover=0\n", __func__);
}

if (gArgs.GetBoolArg("-salvagewallet", false)) {
// Rewrite just private keys: rescan to find transactions
if (gArgs.SoftSetBoolArg("-rescan", true))
LogPrintf("%s : parameter interaction: -salvagewallet=1 -> setting -rescan=1\n", __func__);
}

int zapwallettxes = gArgs.GetArg("-zapwallettxes", 0);
// -zapwallettxes implies dropping the mempool on startup
if (zapwallettxes != 0 && gArgs.SoftSetBoolArg("-persistmempool", false)) {
LogPrintf("%s: parameter interaction: -zapwallettxes=%s -> setting -persistmempool=0\n", __func__, zapwallettxes);
}

// -zapwallettxes implies a rescan
if (zapwallettxes != 0) {
if (gArgs.SoftSetBoolArg("-rescan", true))
LogPrintf("%s : parameter interaction: -zapwallettxes=%s -> setting -rescan=1\n", __func__, zapwallettxes);
}
}

bool InitNUParams()
Expand Down
32 changes: 31 additions & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,37 @@ bool CWallet::ParameterInteraction()
return UIError("-sysperms is not allowed in combination with enabled wallet functionality");
}

gArgs.SoftSetArg("-wallet", DEFAULT_WALLET_DAT);
const bool is_multiwallet = gArgs.GetArgs("-wallet").size() > 1;

if (gArgs.GetBoolArg("-salvagewallet", false) && gArgs.SoftSetBoolArg("-rescan", true)) {
if (is_multiwallet) {
return UIError(strprintf("%s is only allowed with a single wallet file", "-salvagewallet"));
}
// Rewrite just private keys: rescan to find transactions
LogPrintf("%s: parameter interaction: -salvagewallet=1 -> setting -rescan=1\n", __func__);
}

int zapwallettxes = gArgs.GetArg("-zapwallettxes", 0);
// -zapwallettxes implies dropping the mempool on startup
if (zapwallettxes != 0 && gArgs.SoftSetBoolArg("-persistmempool", false)) {
LogPrintf("%s: parameter interaction: -zapwallettxes=%s -> setting -persistmempool=0\n", __func__, zapwallettxes);
}

// -zapwallettxes implies a rescan
if (zapwallettxes != 0 && gArgs.SoftSetBoolArg("-rescan", true)) {
if (is_multiwallet) {
return UIError(strprintf("%s is only allowed with a single wallet file", "-zapwallettxes"));
}
LogPrintf("%s: parameter interaction: -zapwallettxes=<mode> -> setting -rescan=1\n", __func__);
}

if (is_multiwallet) {
if (gArgs.GetBoolArg("-upgradewallet", false)) {
return UIError(strprintf("%s is only allowed with a single wallet file", "-upgradewallet"));
}
}

if (gArgs.IsArgSet("-mintxfee")) {
CAmount n = 0;
if (ParseMoney(gArgs.GetArg("-mintxfee", ""), n) && n > 0)
Expand Down Expand Up @@ -2080,7 +2111,6 @@ bool CWallet::Verify()
return true;
}

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

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

0 comments on commit b6dbbf3

Please sign in to comment.