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[])
337
337
338
338
if (errMsg.isStr ())
339
339
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
+ }
340
344
}
341
345
} else {
342
346
// Result
Original file line number Diff line number Diff line change @@ -82,6 +82,8 @@ enum RPCErrorCode
82
82
RPC_WALLET_WRONG_ENC_STATE = -15 , // !< Command given in wrong wallet encryption state (encrypting an encrypted wallet etc.)
83
83
RPC_WALLET_ENCRYPTION_FAILED = -16 , // !< Failed to encrypt the wallet
84
84
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)
85
87
};
86
88
87
89
UniValue 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)
43
43
return pwallet;
44
44
}
45
45
}
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" );
47
47
}
48
48
return ::vpwallets.size () == 1 || (request.fHelp && ::vpwallets.size () > 0 ) ? ::vpwallets[0 ] : nullptr ;
49
49
}
@@ -57,13 +57,14 @@ std::string HelpRequiringPassphrase(CWallet * const pwallet)
57
57
58
58
bool EnsureWalletIsAvailable (CWallet * const pwallet, bool avoidException)
59
59
{
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)." );
67
68
}
68
69
69
70
void EnsureWalletIsUnlocked (CWallet * const pwallet)
Original file line number Diff line number Diff line change @@ -21,8 +21,11 @@ def run_test(self):
21
21
w1 = self .nodes [0 ] / "wallet/w1"
22
22
w1 .generate (1 )
23
23
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
+
24
27
# 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 )
26
29
27
30
# check w1 wallet balance
28
31
w1_info = w1 .getwalletinfo ()
You can’t perform that action at this time.
0 commit comments