diff --git a/src/wallet/db.h b/src/wallet/db.h --- a/src/wallet/db.h +++ b/src/wallet/db.h @@ -104,6 +104,11 @@ /** Return whether a wallet database is currently loaded. */ bool IsWalletLoaded(const fs::path &wallet_path); +/** + * Given a wallet directory path or legacy file path, return path to main data + * file in the wallet database. */ +fs::path WalletDataFilePath(const fs::path &wallet_path); + /** Get BerkeleyEnvironment and database filename given a wallet path. */ std::shared_ptr GetWalletEnv(const fs::path &wallet_path, std::string &database_filename); diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp --- a/src/wallet/db.cpp +++ b/src/wallet/db.cpp @@ -95,6 +95,13 @@ return database && database->IsDatabaseLoaded(database_filename); } +fs::path WalletDataFilePath(const fs::path &wallet_path) { + fs::path env_directory; + std::string database_filename; + SplitWalletPath(wallet_path, env_directory, database_filename); + return env_directory / database_filename; +} + /** * @param[in] wallet_path Path to wallet directory. Or (for backwards * compatibility only) a path to a berkeley btree data file inside a wallet diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4699,7 +4699,8 @@ std::shared_ptr CWallet::CreateWalletFromFile( const CChainParams &chainParams, interfaces::Chain &chain, const WalletLocation &location, uint64_t wallet_creation_flags) { - const std::string &walletFile = location.GetName(); + const std::string &walletFile = + WalletDataFilePath(location.GetPath()).string(); // Needed to restore wallet transaction meta data after -zapwallettxes std::vector vWtx; diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -435,7 +435,15 @@ strType != DBKeys::SETTINGS) { wss.m_unknown_records++; } + } catch (const std::exception &e) { + if (strErr.empty()) { + strErr = e.what(); + } + return false; } catch (...) { + if (strErr.empty()) { + strErr = "Caught unknown exception in ReadKeyValue"; + } return false; } return true;