diff options
author | Russell Yanofsky <russ@yanofsky.org> | 2020-08-04 20:58:43 -0400 |
---|---|---|
committer | Russell Yanofsky <russ@yanofsky.org> | 2020-09-03 12:24:32 -0400 |
commit | a987438e9d9cad0b5530e218a447928485f3fd93 (patch) | |
tree | 4cd45f0556d2133d1fb88860ca0d3b14404d0c47 /src/wallet | |
parent | 8b5e7297c02f3100a9cb27bfe206e3fc617ec173 (diff) |
wallet: Remove path checking code from loadwallet RPC
This commit does not change behavior except for error messages which now
include more complete information.
Diffstat (limited to 'src/wallet')
-rw-r--r-- | src/wallet/rpcwallet.cpp | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 536d11ddd9..497a4120e5 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2503,25 +2503,20 @@ static UniValue loadwallet(const JSONRPCRequest& request) WalletContext& context = EnsureWalletContext(request.context); const std::string name(request.params[0].get_str()); - fs::path path(fs::absolute(name, GetWalletDir())); - - if (fs::symlink_status(path).type() == fs::file_not_found) { - throw JSONRPCError(RPC_WALLET_NOT_FOUND, "Wallet " + name + " not found."); - } else if (fs::is_directory(path)) { - // The given filename is a directory. Check that there's a wallet.dat file. - fs::path wallet_dat_file = path / "wallet.dat"; - if (fs::symlink_status(wallet_dat_file).type() == fs::file_not_found) { - throw JSONRPCError(RPC_WALLET_NOT_FOUND, "Directory " + name + " does not contain a wallet.dat file."); - } - } DatabaseOptions options; DatabaseStatus status; + options.require_existing = true; bilingual_str error; std::vector<bilingual_str> warnings; Optional<bool> load_on_start = request.params[1].isNull() ? nullopt : Optional<bool>(request.params[1].get_bool()); std::shared_ptr<CWallet> const wallet = LoadWallet(*context.chain, name, load_on_start, options, status, error, warnings); - if (!wallet) throw JSONRPCError(RPC_WALLET_ERROR, error.original); + if (!wallet) { + // Map bad format to not found, since bad format is returned when the + // wallet directory exists, but doesn't contain a data file. + RPCErrorCode code = status == DatabaseStatus::FAILED_NOT_FOUND || status == DatabaseStatus::FAILED_BAD_FORMAT ? RPC_WALLET_NOT_FOUND : RPC_WALLET_ERROR; + throw JSONRPCError(code, error.original); + } UniValue obj(UniValue::VOBJ); obj.pushKV("name", wallet->GetName()); |