MCPcopy Create free account
hub / github.com/ElementsProject/elements / unloadwallet

Function unloadwallet

src/wallet/rpc/wallet.cpp:401–450  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

399}
400
401static RPCHelpMan unloadwallet()
402{
403 return RPCHelpMan{"unloadwallet",
404 "Unloads the wallet referenced by the request endpoint otherwise unloads the wallet specified in the argument.\n"
405 "Specifying the wallet name on a wallet endpoint is invalid.",
406 {
407 {"wallet_name", RPCArg::Type::STR, RPCArg::DefaultHint{"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."},
408 {"load_on_startup", RPCArg::Type::BOOL, RPCArg::Optional::OMITTED_NAMED_ARG, "Save wallet name to persistent settings and load on startup. True to add wallet to startup list, false to remove, null to leave unchanged."},
409 },
410 RPCResult{RPCResult::Type::OBJ, "", "", {
411 {RPCResult::Type::STR, "warning", "Warning message if wallet was not unloaded cleanly."},
412 }},
413 RPCExamples{
414 HelpExampleCli("unloadwallet", "wallet_name")
415 + HelpExampleRpc("unloadwallet", "wallet_name")
416 },
417 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
418{
419 std::string wallet_name;
420 if (GetWalletNameFromJSONRPCRequest(request, wallet_name)) {
421 if (!(request.params[0].isNull() || request.params[0].get_str() == wallet_name)) {
422 throw JSONRPCError(RPC_INVALID_PARAMETER, "RPC endpoint wallet and wallet_name parameter specify different wallets");
423 }
424 } else {
425 wallet_name = request.params[0].get_str();
426 }
427
428 WalletContext& context = EnsureWalletContext(request.context);
429 std::shared_ptr<CWallet> wallet = GetWallet(context, wallet_name);
430 if (!wallet) {
431 throw JSONRPCError(RPC_WALLET_NOT_FOUND, "Requested wallet does not exist or is not loaded");
432 }
433
434 // Release the "main" shared pointer and prevent further notifications.
435 // Note that any attempt to load the same wallet would fail until the wallet
436 // is destroyed (see CheckUniqueFileid).
437 std::vector<bilingual_str> warnings;
438 std::optional<bool> load_on_start = request.params[1].isNull() ? std::nullopt : std::optional<bool>(request.params[1].get_bool());
439 if (!RemoveWallet(context, wallet, load_on_start, warnings)) {
440 throw JSONRPCError(RPC_MISC_ERROR, "Requested wallet already unloaded");
441 }
442
443 UnloadWallet(std::move(wallet));
444
445 UniValue result(UniValue::VOBJ);
446 result.pushKV("warning", Join(warnings, Untranslated("\n")).original);
447 return result;
448},
449 };
450}
451
452static RPCHelpMan sethdseed()
453{

Callers

nothing calls this directly

Calls 12

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
JSONRPCErrorFunction · 0.85
GetWalletFunction · 0.85
RemoveWalletFunction · 0.85
UnloadWalletFunction · 0.85
JoinFunction · 0.85
UntranslatedFunction · 0.85
get_boolMethod · 0.80
isNullMethod · 0.45
pushKVMethod · 0.45

Tested by

no test coverage detected