Skip to content

Commit 01a4c09

Browse files
committed
wallet: Add WalletLocation utility class
1 parent 613fc95 commit 01a4c09

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/wallet/walletutil.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,14 @@ std::vector<fs::path> ListWalletDir()
7575

7676
return paths;
7777
}
78+
79+
WalletLocation::WalletLocation(const std::string& name)
80+
: m_name(name)
81+
, m_path(fs::absolute(name, GetWalletDir()))
82+
{
83+
}
84+
85+
bool WalletLocation::Exists() const
86+
{
87+
return fs::symlink_status(m_path).type() != fs::file_not_found;
88+
}

src/wallet/walletutil.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,24 @@ fs::path GetWalletDir();
1515
//! Get wallets in wallet directory.
1616
std::vector<fs::path> ListWalletDir();
1717

18+
//! The WalletLocation class provides wallet information.
19+
class WalletLocation final
20+
{
21+
std::string m_name;
22+
fs::path m_path;
23+
24+
public:
25+
explicit WalletLocation() {}
26+
explicit WalletLocation(const std::string& name);
27+
28+
//! Get wallet name.
29+
const std::string& GetName() const { return m_name; }
30+
31+
//! Get wallet absolute path.
32+
const fs::path& GetPath() const { return m_path; }
33+
34+
//! Return whether the wallet exists.
35+
bool Exists() const;
36+
};
37+
1838
#endif // BITCOIN_WALLET_WALLETUTIL_H

0 commit comments

Comments
 (0)