Skip to content

Commit 8ede6de

Browse files
committed
wallet, rpc: Remove legacy wallet only RPCs
1 parent 4de3cec commit 8ede6de

File tree

12 files changed

+7
-1618
lines changed

12 files changed

+7
-1618
lines changed

src/qt/rpcconsole.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ namespace {
7272

7373
// don't add private key handling cmd's to the history
7474
const QStringList historyFilter = QStringList()
75-
<< "importprivkey"
76-
<< "importmulti"
77-
<< "sethdseed"
7875
<< "signmessagewithprivkey"
7976
<< "signrawtransactionwithkey"
8077
<< "walletpassphrase"

src/qt/test/rpcnestedtests.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ void RPCNestedTests::rpcNestedTests()
8585
QVERIFY(result == "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b");
8686
QVERIFY(filtered == "getblock(getbestblockhash())[tx][0]");
8787

88-
RPCConsole::RPCParseCommandLine(nullptr, result, "importprivkey", false, &filtered);
89-
QVERIFY(filtered == "importprivkey(…)");
9088
RPCConsole::RPCParseCommandLine(nullptr, result, "signmessagewithprivkey abc", false, &filtered);
9189
QVERIFY(filtered == "signmessagewithprivkey(…)");
9290
RPCConsole::RPCParseCommandLine(nullptr, result, "signmessagewithprivkey abc,def", false, &filtered);
@@ -99,12 +97,6 @@ void RPCNestedTests::rpcNestedTests()
9997
QVERIFY(filtered == "walletpassphrasechange(…)");
10098
RPCConsole::RPCParseCommandLine(nullptr, result, "help(encryptwallet(abc, def))", false, &filtered);
10199
QVERIFY(filtered == "help(encryptwallet(…))");
102-
RPCConsole::RPCParseCommandLine(nullptr, result, "help(importprivkey())", false, &filtered);
103-
QVERIFY(filtered == "help(importprivkey(…))");
104-
RPCConsole::RPCParseCommandLine(nullptr, result, "help(importprivkey(help()))", false, &filtered);
105-
QVERIFY(filtered == "help(importprivkey(…))");
106-
RPCConsole::RPCParseCommandLine(nullptr, result, "help(importprivkey(abc), walletpassphrase(def))", false, &filtered);
107-
QVERIFY(filtered == "help(importprivkey(…), walletpassphrase(…))");
108100

109101
RPCConsole::RPCExecuteCommandLine(m_node, result, "rpcNestedTest");
110102
QVERIFY(result == "[]");

src/rpc/client.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ static const CRPCConvertParam vRPCConvertParams[] =
4848
{ "sendtoaddress", 9, "fee_rate"},
4949
{ "sendtoaddress", 10, "verbose"},
5050
{ "settxfee", 0, "amount" },
51-
{ "sethdseed", 0, "newkeypool" },
5251
{ "getreceivedbyaddress", 1, "minconf" },
5352
{ "getreceivedbyaddress", 2, "include_immature_coinbase" },
5453
{ "getreceivedbylabel", 1, "minconf" },
@@ -96,8 +95,6 @@ static const CRPCConvertParam vRPCConvertParams[] =
9695
{ "getdescriptoractivity", 1, "scanobjects" },
9796
{ "getdescriptoractivity", 2, "include_mempool" },
9897
{ "scantxoutset", 1, "scanobjects" },
99-
{ "addmultisigaddress", 0, "nrequired" },
100-
{ "addmultisigaddress", 1, "keys" },
10198
{ "createmultisig", 0, "nrequired" },
10299
{ "createmultisig", 1, "keys" },
103100
{ "listunspent", 0, "minconf" },
@@ -236,17 +233,10 @@ static const CRPCConvertParam vRPCConvertParams[] =
236233
{ "simulaterawtransaction", 0, "rawtxs" },
237234
{ "simulaterawtransaction", 1, "options" },
238235
{ "simulaterawtransaction", 1, "include_watchonly"},
239-
{ "importprivkey", 2, "rescan" },
240-
{ "importaddress", 2, "rescan" },
241-
{ "importaddress", 3, "p2sh" },
242-
{ "importpubkey", 2, "rescan" },
243236
{ "importmempool", 1, "options" },
244237
{ "importmempool", 1, "apply_fee_delta_priority" },
245238
{ "importmempool", 1, "use_current_time" },
246239
{ "importmempool", 1, "apply_unbroadcast_set" },
247-
{ "importmulti", 0, "requests" },
248-
{ "importmulti", 1, "options" },
249-
{ "importmulti", 1, "rescan" },
250240
{ "importdescriptors", 0, "requests" },
251241
{ "listdescriptors", 0, "private" },
252242
{ "verifychain", 0, "checklevel" },

src/test/fuzz/rpc.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,12 @@ const std::vector<std::string> RPC_COMMANDS_NOT_SAFE_FOR_FUZZING{
7575
"addnode", // avoid DNS lookups
7676
"addpeeraddress", // avoid DNS lookups
7777
"dumptxoutset", // avoid writing to disk
78-
"dumpwallet", // avoid writing to disk
7978
"enumeratesigners",
8079
"echoipc", // avoid assertion failure (Assertion `"EnsureAnyNodeContext(request.context).init" && check' failed.)
8180
"generatetoaddress", // avoid prohibitively slow execution (when `num_blocks` is large)
8281
"generatetodescriptor", // avoid prohibitively slow execution (when `nblocks` is large)
8382
"gettxoutproof", // avoid prohibitively slow execution
8483
"importmempool", // avoid reading from disk
85-
"importwallet", // avoid reading from disk
8684
"loadtxoutset", // avoid reading from disk
8785
"loadwallet", // avoid reading from disk
8886
"savemempool", // disabled as a precautionary measure: may take a file path argument in the future

src/wallet/rpc/addresses.cpp

Lines changed: 0 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -215,124 +215,6 @@ RPCHelpMan listaddressgroupings()
215215
};
216216
}
217217

218-
RPCHelpMan addmultisigaddress()
219-
{
220-
return RPCHelpMan{"addmultisigaddress",
221-
"\nAdd an nrequired-to-sign multisignature address to the wallet. Requires a new wallet backup.\n"
222-
"Each key is a Bitcoin address or hex-encoded public key.\n"
223-
"This functionality is only intended for use with non-watchonly addresses.\n"
224-
"See `importaddress` for watchonly p2sh address support.\n"
225-
"If 'label' is specified, assign address to that label.\n"
226-
"Note: This command is only compatible with legacy wallets.\n",
227-
{
228-
{"nrequired", RPCArg::Type::NUM, RPCArg::Optional::NO, "The number of required signatures out of the n keys or addresses."},
229-
{"keys", RPCArg::Type::ARR, RPCArg::Optional::NO, "The bitcoin addresses or hex-encoded public keys",
230-
{
231-
{"key", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "bitcoin address or hex-encoded public key"},
232-
},
233-
},
234-
{"label", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "A label to assign the addresses to."},
235-
{"address_type", RPCArg::Type::STR, RPCArg::DefaultHint{"set by -addresstype"}, "The address type to use. Options are \"legacy\", \"p2sh-segwit\", and \"bech32\"."},
236-
},
237-
RPCResult{
238-
RPCResult::Type::OBJ, "", "",
239-
{
240-
{RPCResult::Type::STR, "address", "The value of the new multisig address"},
241-
{RPCResult::Type::STR_HEX, "redeemScript", "The string value of the hex-encoded redemption script"},
242-
{RPCResult::Type::STR, "descriptor", "The descriptor for this multisig"},
243-
{RPCResult::Type::ARR, "warnings", /*optional=*/true, "Any warnings resulting from the creation of this multisig",
244-
{
245-
{RPCResult::Type::STR, "", ""},
246-
}},
247-
}
248-
},
249-
RPCExamples{
250-
"\nAdd a multisig address from 2 addresses\n"
251-
+ HelpExampleCli("addmultisigaddress", "2 \"[\\\"" + EXAMPLE_ADDRESS[0] + "\\\",\\\"" + EXAMPLE_ADDRESS[1] + "\\\"]\"") +
252-
"\nAs a JSON-RPC call\n"
253-
+ HelpExampleRpc("addmultisigaddress", "2, \"[\\\"" + EXAMPLE_ADDRESS[0] + "\\\",\\\"" + EXAMPLE_ADDRESS[1] + "\\\"]\"")
254-
},
255-
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
256-
{
257-
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
258-
if (!pwallet) return UniValue::VNULL;
259-
260-
LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan(*pwallet);
261-
262-
LOCK2(pwallet->cs_wallet, spk_man.cs_KeyStore);
263-
264-
const std::string label{LabelFromValue(request.params[2])};
265-
266-
int required = request.params[0].getInt<int>();
267-
268-
// Get the public keys
269-
const UniValue& keys_or_addrs = request.params[1].get_array();
270-
std::vector<CPubKey> pubkeys;
271-
for (unsigned int i = 0; i < keys_or_addrs.size(); ++i) {
272-
if (IsHex(keys_or_addrs[i].get_str()) && (keys_or_addrs[i].get_str().length() == 66 || keys_or_addrs[i].get_str().length() == 130)) {
273-
pubkeys.push_back(HexToPubKey(keys_or_addrs[i].get_str()));
274-
} else {
275-
pubkeys.push_back(AddrToPubKey(spk_man, keys_or_addrs[i].get_str()));
276-
}
277-
}
278-
279-
OutputType output_type = pwallet->m_default_address_type;
280-
if (!request.params[3].isNull()) {
281-
std::optional<OutputType> parsed = ParseOutputType(request.params[3].get_str());
282-
if (!parsed) {
283-
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[3].get_str()));
284-
} else if (parsed.value() == OutputType::BECH32M) {
285-
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Bech32m multisig addresses cannot be created with legacy wallets");
286-
}
287-
output_type = parsed.value();
288-
}
289-
290-
// Construct multisig scripts
291-
FlatSigningProvider provider;
292-
CScript inner;
293-
CTxDestination dest = AddAndGetMultisigDestination(required, pubkeys, output_type, provider, inner);
294-
295-
// Import scripts into the wallet
296-
for (const auto& [id, script] : provider.scripts) {
297-
// Due to a bug in the legacy wallet, the p2sh maximum script size limit is also imposed on 'p2sh-segwit' and 'bech32' redeem scripts.
298-
// Even when redeem scripts over MAX_SCRIPT_ELEMENT_SIZE bytes are valid for segwit output types, we don't want to
299-
// enable it because:
300-
// 1) It introduces a compatibility-breaking change requiring downgrade protection; older wallets would be unable to interact with these "new" legacy wallets.
301-
// 2) Considering the ongoing deprecation of the legacy spkm, this issue adds another good reason to transition towards descriptors.
302-
if (script.size() > MAX_SCRIPT_ELEMENT_SIZE) throw JSONRPCError(RPC_WALLET_ERROR, "Unsupported multisig script size for legacy wallet. Upgrade to descriptors to overcome this limitation for p2sh-segwit or bech32 scripts");
303-
304-
if (!spk_man.AddCScript(script)) {
305-
if (CScript inner_script; spk_man.GetCScript(CScriptID(script), inner_script)) {
306-
CHECK_NONFATAL(inner_script == script); // Nothing to add, script already contained by the wallet
307-
continue;
308-
}
309-
throw JSONRPCError(RPC_WALLET_ERROR, strprintf("Error importing script into the wallet"));
310-
}
311-
}
312-
313-
// Store destination in the addressbook
314-
pwallet->SetAddressBook(dest, label, AddressPurpose::SEND);
315-
316-
// Make the descriptor
317-
std::unique_ptr<Descriptor> descriptor = InferDescriptor(GetScriptForDestination(dest), spk_man);
318-
319-
UniValue result(UniValue::VOBJ);
320-
result.pushKV("address", EncodeDestination(dest));
321-
result.pushKV("redeemScript", HexStr(inner));
322-
result.pushKV("descriptor", descriptor->ToString());
323-
324-
UniValue warnings(UniValue::VARR);
325-
if (descriptor->GetOutputType() != output_type) {
326-
// Only warns if the user has explicitly chosen an address type we cannot generate
327-
warnings.push_back("Unable to make chosen address type, please ensure no uncompressed public keys are present.");
328-
}
329-
PushWarnings(warnings, result);
330-
331-
return result;
332-
},
333-
};
334-
}
335-
336218
RPCHelpMan keypoolrefill()
337219
{
338220
return RPCHelpMan{"keypoolrefill",
@@ -377,38 +259,6 @@ RPCHelpMan keypoolrefill()
377259
};
378260
}
379261

380-
RPCHelpMan newkeypool()
381-
{
382-
return RPCHelpMan{"newkeypool",
383-
"\nEntirely clears and refills the keypool.\n"
384-
"WARNING: On non-HD wallets, this will require a new backup immediately, to include the new keys.\n"
385-
"When restoring a backup of an HD wallet created before the newkeypool command is run, funds received to\n"
386-
"new addresses may not appear automatically. They have not been lost, but the wallet may not find them.\n"
387-
"This can be fixed by running the newkeypool command on the backup and then rescanning, so the wallet\n"
388-
"re-generates the required keys." +
389-
HELP_REQUIRING_PASSPHRASE,
390-
{},
391-
RPCResult{RPCResult::Type::NONE, "", ""},
392-
RPCExamples{
393-
HelpExampleCli("newkeypool", "")
394-
+ HelpExampleRpc("newkeypool", "")
395-
},
396-
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
397-
{
398-
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
399-
if (!pwallet) return UniValue::VNULL;
400-
401-
LOCK(pwallet->cs_wallet);
402-
403-
LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan(*pwallet, true);
404-
spk_man.NewKeyPool();
405-
406-
return UniValue::VNULL;
407-
},
408-
};
409-
}
410-
411-
412262
class DescribeWalletAddressVisitor
413263
{
414264
public:

0 commit comments

Comments
 (0)