Skip to content

Commit 1ae5758

Browse files
author
MarcoFalke
committed
Merge #20448: RPC/Wallet: unloadwallet: Allow specifying wallet_name param matching RPC endpoint wallet
89bdad5 RPC/Wallet: unloadwallet: Allow specifying wallet_name param matching RPC endpoint (Luke Dashjr) Pull request description: Allow specifying the `wallet_name` param to `unloadwallet` on RPC wallet endpoints, so long as it matches the endpoint wallet. ACKs for top commit: jonatack: ACK 89bdad5 MarcoFalke: review ACK 89bdad5 Tree-SHA512: efb399c33f7b5596870a26a8680f453ca47aa7a6db4e550f9435d13044f1c4bad0ae11e8f0205213409d08b75c4188c3be782e54aafab1f65b97eb8cf5c252a9
2 parents e2ff5e7 + 89bdad5 commit 1ae5758

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2789,7 +2789,7 @@ static RPCHelpMan unloadwallet()
27892789
"Unloads the wallet referenced by the request endpoint otherwise unloads the wallet specified in the argument.\n"
27902790
"Specifying the wallet name on a wallet endpoint is invalid.",
27912791
{
2792-
{"wallet_name", RPCArg::Type::STR, /* default */ "the wallet name from the RPC endpoint", "The name of the wallet to unload. Must be provided in the RPC endpoint or this parameter (but not both)."},
2792+
{"wallet_name", RPCArg::Type::STR, /* default */ "the wallet name from the RPC endpoint", "The name of the wallet to unload. If provided both here and in the RPC endpoint, the two must be identical."},
27932793
{"load_on_startup", RPCArg::Type::BOOL, /* default */ "null", "Save wallet name to persistent settings and load on startup. True to add wallet to startup list, false to remove, null to leave unchanged."},
27942794
},
27952795
RPCResult{RPCResult::Type::OBJ, "", "", {
@@ -2803,8 +2803,8 @@ static RPCHelpMan unloadwallet()
28032803
{
28042804
std::string wallet_name;
28052805
if (GetWalletNameFromJSONRPCRequest(request, wallet_name)) {
2806-
if (!request.params[0].isNull()) {
2807-
throw JSONRPCError(RPC_INVALID_PARAMETER, "Both the RPC endpoint wallet and wallet_name parameter were provided (only one allowed)");
2806+
if (!(request.params[0].isNull() || request.params[0].get_str() == wallet_name)) {
2807+
throw JSONRPCError(RPC_INVALID_PARAMETER, "RPC endpoint wallet and wallet_name parameter specify different wallets");
28082808
}
28092809
} else {
28102810
wallet_name = request.params[0].get_str();

test/functional/wallet_multiwallet.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,18 @@ def wallet_file(name):
355355
assert_raises_rpc_error(-1, "JSON value is not a string as expected", self.nodes[0].unloadwallet)
356356
assert_raises_rpc_error(-18, "Requested wallet does not exist or is not loaded", self.nodes[0].unloadwallet, "dummy")
357357
assert_raises_rpc_error(-18, "Requested wallet does not exist or is not loaded", node.get_wallet_rpc("dummy").unloadwallet)
358-
assert_raises_rpc_error(-8, "Both the RPC endpoint wallet and wallet_name parameter were provided (only one allowed)", w1.unloadwallet, "w2"),
359-
assert_raises_rpc_error(-8, "Both the RPC endpoint wallet and wallet_name parameter were provided (only one allowed)", w1.unloadwallet, "w1"),
358+
assert_raises_rpc_error(-8, "RPC endpoint wallet and wallet_name parameter specify different wallets", w1.unloadwallet, "w2"),
360359

361360
# Successfully unload the specified wallet name
362361
self.nodes[0].unloadwallet("w1")
363362
assert 'w1' not in self.nodes[0].listwallets()
364363

364+
# Unload w1 again, this time providing the wallet name twice
365+
self.nodes[0].loadwallet("w1")
366+
assert 'w1' in self.nodes[0].listwallets()
367+
w1.unloadwallet("w1")
368+
assert 'w1' not in self.nodes[0].listwallets()
369+
365370
# Successfully unload the wallet referenced by the request endpoint
366371
# Also ensure unload works during walletpassphrase timeout
367372
w2.encryptwallet('test')

0 commit comments

Comments
 (0)