mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-13 07:28:59 +01:00
Fix misleading "Method not found" multiwallet errors
Raise RPC_WALLET_NOT_SPECIFIED instead of RPC_METHOD_NOT_FOUND when a required wallet filename was not specified in an RPC call. Also raise more specific RPC_WALLET_NOT_FOUND error instead of RPC_INVALID_PARAMETER in case an invalid wallet was specified, for consistency.
This commit is contained in:
@@ -43,7 +43,7 @@ CWallet *GetWalletForJSONRPCRequest(const JSONRPCRequest& request)
|
||||
return pwallet;
|
||||
}
|
||||
}
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Requested wallet does not exist or is not loaded");
|
||||
throw JSONRPCError(RPC_WALLET_NOT_FOUND, "Requested wallet does not exist or is not loaded");
|
||||
}
|
||||
return ::vpwallets.size() == 1 || (request.fHelp && ::vpwallets.size() > 0) ? ::vpwallets[0] : nullptr;
|
||||
}
|
||||
@@ -57,13 +57,14 @@ std::string HelpRequiringPassphrase(CWallet * const pwallet)
|
||||
|
||||
bool EnsureWalletIsAvailable(CWallet * const pwallet, bool avoidException)
|
||||
{
|
||||
if (!pwallet) {
|
||||
if (!avoidException)
|
||||
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (disabled)");
|
||||
else
|
||||
return false;
|
||||
if (pwallet) return true;
|
||||
if (avoidException) return false;
|
||||
if (::vpwallets.empty()) {
|
||||
// Wallet RPC methods are disabled if no wallets are loaded.
|
||||
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (disabled)");
|
||||
}
|
||||
return true;
|
||||
throw JSONRPCError(RPC_WALLET_NOT_SPECIFIED,
|
||||
"Wallet file not specified (must request wallet RPC through /wallet/<filename> uri-path).");
|
||||
}
|
||||
|
||||
void EnsureWalletIsUnlocked(CWallet * const pwallet)
|
||||
|
||||
Reference in New Issue
Block a user