File tree Expand file tree Collapse file tree 4 files changed +19
-9
lines changed Expand file tree Collapse file tree 4 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -337,6 +337,10 @@ int CommandLineRPC(int argc, char *argv[])
337337
338338 if (errMsg.isStr ())
339339 strPrint += " error message:\n " +errMsg.get_str ();
340+
341+ if (errCode.isNum () && errCode.get_int () == RPC_WALLET_NOT_SPECIFIED) {
342+ strPrint += " \n Try adding \" -rpcwallet=<filename>\" option to bitcoin-cli command line." ;
343+ }
340344 }
341345 } else {
342346 // Result
Original file line number Diff line number Diff line change @@ -82,6 +82,8 @@ enum RPCErrorCode
8282 RPC_WALLET_WRONG_ENC_STATE = -15 , // !< Command given in wrong wallet encryption state (encrypting an encrypted wallet etc.)
8383 RPC_WALLET_ENCRYPTION_FAILED = -16 , // !< Failed to encrypt the wallet
8484 RPC_WALLET_ALREADY_UNLOCKED = -17 , // !< Wallet is already unlocked
85+ RPC_WALLET_NOT_FOUND = -18 , // !< Invalid wallet specified
86+ RPC_WALLET_NOT_SPECIFIED = -19 , // !< No wallet specified (error when there are multiple wallets loaded)
8587};
8688
8789UniValue JSONRPCRequestObj (const std::string& strMethod, const UniValue& params, const UniValue& id);
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ CWallet *GetWalletForJSONRPCRequest(const JSONRPCRequest& request)
4343 return pwallet;
4444 }
4545 }
46- throw JSONRPCError (RPC_INVALID_PARAMETER , " Requested wallet does not exist or is not loaded" );
46+ throw JSONRPCError (RPC_WALLET_NOT_FOUND , " Requested wallet does not exist or is not loaded" );
4747 }
4848 return ::vpwallets.size () == 1 || (request.fHelp && ::vpwallets.size () > 0 ) ? ::vpwallets[0 ] : nullptr ;
4949}
@@ -57,13 +57,14 @@ std::string HelpRequiringPassphrase(CWallet * const pwallet)
5757
5858bool EnsureWalletIsAvailable (CWallet * const pwallet, bool avoidException)
5959{
60- if (!pwallet) {
61- if (!avoidException)
62- throw JSONRPCError (RPC_METHOD_NOT_FOUND, " Method not found (disabled)" );
63- else
64- return false ;
65- }
66- return true ;
60+ if (pwallet) return true ;
61+ if (avoidException) return false ;
62+ if (::vpwallets.empty ()) {
63+ // Wallet RPC methods are disabled if no wallets are loaded.
64+ throw JSONRPCError (RPC_METHOD_NOT_FOUND, " Method not found (disabled)" );
65+ }
66+ throw JSONRPCError (RPC_WALLET_NOT_SPECIFIED,
67+ " Wallet file not specified (must request wallet RPC through /wallet/<filename> uri-path)." );
6768}
6869
6970void EnsureWalletIsUnlocked (CWallet * const pwallet)
Original file line number Diff line number Diff line change @@ -21,8 +21,11 @@ def run_test(self):
2121 w1 = self .nodes [0 ] / "wallet/w1"
2222 w1 .generate (1 )
2323
24+ # accessing invalid wallet fails
25+ assert_raises_jsonrpc (- 18 , "Requested wallet does not exist or is not loaded" , (self .nodes [0 ] / "wallet/bad" ).getwalletinfo )
26+
2427 # accessing wallet RPC without using wallet endpoint fails
25- assert_raises_jsonrpc (- 32601 , "Method not found " , self .nodes [0 ].getwalletinfo )
28+ assert_raises_jsonrpc (- 19 , "Wallet file not specified " , self .nodes [0 ].getwalletinfo )
2629
2730 # check w1 wallet balance
2831 w1_info = w1 .getwalletinfo ()
You can’t perform that action at this time.
0 commit comments