From 3d7f0e4ed5ac1fea0529fb25662cf0ea9a397cee Mon Sep 17 00:00:00 2001 From: Ava Chow Date: Wed, 29 Apr 2026 15:12:46 -0700 Subject: [PATCH] wallettool: Use GetWalletPath to determine the wallet path Instead of computing the path separately, use GetWalletPath to use the behavior and error checking of the typical wallet path computation. --- src/wallet/wallet.cpp | 2 +- src/wallet/wallet.h | 3 +++ src/wallet/wallettool.cpp | 7 ++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 49099bf70cd..a95d67e884a 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2940,7 +2940,7 @@ bool CWallet::EraseAddressReceiveRequest(WalletBatch& batch, const CTxDestinatio return true; } -static util::Result GetWalletPath(const std::string& name) +util::Result GetWalletPath(const std::string& name) { const fs::path name_path = fs::PathFromString(name); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 9cd78258454..5385ee97116 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1150,6 +1150,9 @@ struct MigrationResult { [[nodiscard]] util::Result MigrateLegacyToDescriptor(const std::string& wallet_name, const SecureString& passphrase, WalletContext& context); //! Requirement: The wallet provided to this function must be isolated, with no attachment to the node's context. [[nodiscard]] util::Result MigrateLegacyToDescriptor(std::shared_ptr local_wallet, const SecureString& passphrase, WalletContext& context); + +//! Determine the path that the wallet is stored in +util::Result GetWalletPath(const std::string& name); } // namespace wallet #endif // BITCOIN_WALLET_WALLET_H diff --git a/src/wallet/wallettool.cpp b/src/wallet/wallettool.cpp index 7c24c0e1c6a..d1f3a8ce982 100644 --- a/src/wallet/wallettool.cpp +++ b/src/wallet/wallettool.cpp @@ -102,7 +102,12 @@ bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command) return false; } const std::string name = args.GetArg("-wallet", ""); - const fs::path path = fsbridge::AbsPathJoin(GetWalletDir(), fs::PathFromString(name)); + util::Result path_res = GetWalletPath(name); + if (!path_res) { + tfm::format(std::cerr, "%s\n", util::ErrorString(path_res).original); + return false; + } + const fs::path& path = *path_res; if (command == "create") { if (name.empty()) {