@@ -2503,25 +2503,20 @@ static UniValue loadwallet(const JSONRPCRequest& request)
2503
2503
2504
2504
WalletContext& context = EnsureWalletContext (request.context );
2505
2505
const std::string name (request.params [0 ].get_str ());
2506
- fs::path path (fs::absolute (name, GetWalletDir ()));
2507
-
2508
- if (fs::symlink_status (path).type () == fs::file_not_found) {
2509
- throw JSONRPCError (RPC_WALLET_NOT_FOUND, " Wallet " + name + " not found." );
2510
- } else if (fs::is_directory (path)) {
2511
- // The given filename is a directory. Check that there's a wallet.dat file.
2512
- fs::path wallet_dat_file = path / " wallet.dat" ;
2513
- if (fs::symlink_status (wallet_dat_file).type () == fs::file_not_found) {
2514
- throw JSONRPCError (RPC_WALLET_NOT_FOUND, " Directory " + name + " does not contain a wallet.dat file." );
2515
- }
2516
- }
2517
2506
2518
2507
DatabaseOptions options;
2519
2508
DatabaseStatus status;
2509
+ options.require_existing = true ;
2520
2510
bilingual_str error;
2521
2511
std::vector<bilingual_str> warnings;
2522
2512
Optional<bool > load_on_start = request.params [1 ].isNull () ? nullopt : Optional<bool >(request.params [1 ].get_bool ());
2523
2513
std::shared_ptr<CWallet> const wallet = LoadWallet (*context.chain , name, load_on_start, options, status, error, warnings);
2524
- if (!wallet) throw JSONRPCError (RPC_WALLET_ERROR, error.original );
2514
+ if (!wallet) {
2515
+ // Map bad format to not found, since bad format is returned when the
2516
+ // wallet directory exists, but doesn't contain a data file.
2517
+ RPCErrorCode code = status == DatabaseStatus::FAILED_NOT_FOUND || status == DatabaseStatus::FAILED_BAD_FORMAT ? RPC_WALLET_NOT_FOUND : RPC_WALLET_ERROR;
2518
+ throw JSONRPCError (code, error.original );
2519
+ }
2525
2520
2526
2521
UniValue obj (UniValue::VOBJ);
2527
2522
obj.pushKV (" name" , wallet->GetName ());
0 commit comments