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.
This commit is contained in:
Ava Chow
2026-04-29 15:12:46 -07:00
parent 2b0dc0d228
commit 3d7f0e4ed5
3 changed files with 10 additions and 2 deletions

View File

@@ -2940,7 +2940,7 @@ bool CWallet::EraseAddressReceiveRequest(WalletBatch& batch, const CTxDestinatio
return true;
}
static util::Result<fs::path> GetWalletPath(const std::string& name)
util::Result<fs::path> GetWalletPath(const std::string& name)
{
const fs::path name_path = fs::PathFromString(name);

View File

@@ -1150,6 +1150,9 @@ struct MigrationResult {
[[nodiscard]] util::Result<MigrationResult> 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<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet> local_wallet, const SecureString& passphrase, WalletContext& context);
//! Determine the path that the wallet is stored in
util::Result<fs::path> GetWalletPath(const std::string& name);
} // namespace wallet
#endif // BITCOIN_WALLET_WALLET_H

View File

@@ -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<fs::path> 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()) {