Skip to content

Commit 357b19e

Browse files
committed
wallet, interfaces: Include database format in listWalletDir
1 parent b1ba1b1 commit 357b19e

File tree

8 files changed

+29
-24
lines changed

8 files changed

+29
-24
lines changed

src/interfaces/wallet.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ enum isminetype : unsigned int;
4141
struct CRecipient;
4242
struct WalletContext;
4343
using isminefilter = std::underlying_type<isminetype>::type;
44+
enum class DatabaseFormat;
4445
} // namespace wallet
4546

4647
namespace interfaces {
@@ -338,7 +339,7 @@ class WalletLoader : public ChainClient
338339
virtual util::Result<WalletMigrationResult> migrateWallet(const std::string& name, const SecureString& passphrase) = 0;
339340

340341
//! Return available wallets in wallet directory.
341-
virtual std::vector<std::string> listWalletDir() = 0;
342+
virtual std::vector<std::pair<std::string, std::string>> listWalletDir() = 0;
342343

343344
//! Return interfaces for accessing wallets (if any).
344345
virtual std::vector<std::unique_ptr<Wallet>> getWallets() = 0;

src/qt/bitcoingui.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,16 +396,16 @@ void BitcoinGUI::createActions()
396396
connect(openAction, &QAction::triggered, this, &BitcoinGUI::openClicked);
397397
connect(m_open_wallet_menu, &QMenu::aboutToShow, [this] {
398398
m_open_wallet_menu->clear();
399-
for (const std::pair<const std::string, bool>& i : m_wallet_controller->listWalletDir()) {
400-
const std::string& path = i.first;
399+
for (const auto& [path, info] : m_wallet_controller->listWalletDir()) {
400+
const auto& [loaded, _] = info;
401401
QString name = path.empty() ? QString("["+tr("default wallet")+"]") : QString::fromStdString(path);
402402
// Menu items remove single &. Single & are shown when && is in
403403
// the string, but only the first occurrence. So replace only
404404
// the first & with &&.
405405
name.replace(name.indexOf(QChar('&')), 1, QString("&&"));
406406
QAction* action = m_open_wallet_menu->addAction(name);
407407

408-
if (i.second) {
408+
if (loaded) {
409409
// This wallet is already loaded
410410
action->setEnabled(false);
411411
continue;

src/qt/walletcontroller.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,16 @@ WalletController::~WalletController()
6464
delete m_activity_worker;
6565
}
6666

67-
std::map<std::string, bool> WalletController::listWalletDir() const
67+
std::map<std::string, std::pair<bool, std::string>> WalletController::listWalletDir() const
6868
{
6969
QMutexLocker locker(&m_mutex);
70-
std::map<std::string, bool> wallets;
71-
for (const std::string& name : m_node.walletLoader().listWalletDir()) {
72-
wallets[name] = false;
70+
std::map<std::string, std::pair<bool, std::string>> wallets;
71+
for (const auto& [name, format] : m_node.walletLoader().listWalletDir()) {
72+
wallets[name] = std::make_pair(false, format);
7373
}
7474
for (WalletModel* wallet_model : m_wallets) {
7575
auto it = wallets.find(wallet_model->wallet().getWalletName());
76-
if (it != wallets.end()) it->second = true;
76+
if (it != wallets.end()) it->second.first = true;
7777
}
7878
return wallets;
7979
}

src/qt/walletcontroller.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class WalletController : public QObject
6161

6262
//! Returns all wallet names in the wallet dir mapped to whether the wallet
6363
//! is loaded.
64-
std::map<std::string, bool> listWalletDir() const;
64+
std::map<std::string, std::pair<bool, std::string>> listWalletDir() const;
6565

6666
void closeWallet(WalletModel* wallet_model, QWidget* parent = nullptr);
6767
void closeAllWallets(QWidget* parent = nullptr);

src/wallet/db.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ namespace wallet {
1919
bool operator<(BytePrefix a, Span<const std::byte> b) { return a.prefix < b.subspan(0, std::min(a.prefix.size(), b.size())); }
2020
bool operator<(Span<const std::byte> a, BytePrefix b) { return a.subspan(0, std::min(a.size(), b.prefix.size())) < b.prefix; }
2121

22-
std::vector<fs::path> ListDatabases(const fs::path& wallet_dir)
22+
std::vector<std::pair<fs::path, std::string>> ListDatabases(const fs::path& wallet_dir)
2323
{
24-
std::vector<fs::path> paths;
24+
std::vector<std::pair<fs::path, std::string>> paths;
2525
std::error_code ec;
2626

2727
for (auto it = fs::recursive_directory_iterator(wallet_dir, ec); it != fs::recursive_directory_iterator(); it.increment(ec)) {
@@ -38,21 +38,25 @@ std::vector<fs::path> ListDatabases(const fs::path& wallet_dir)
3838
try {
3939
const fs::path path{it->path().lexically_relative(wallet_dir)};
4040

41-
if (it->status().type() == fs::file_type::directory &&
42-
(IsBDBFile(BDBDataFile(it->path())) || IsSQLiteFile(SQLiteDataFile(it->path())))) {
43-
// Found a directory which contains wallet.dat btree file, add it as a wallet.
44-
paths.emplace_back(path);
41+
if (it->status().type() == fs::file_type::directory) {
42+
if (IsBDBFile(BDBDataFile(it->path()))) {
43+
// Found a directory which contains wallet.dat btree file, add it as a wallet with BERKELEY format.
44+
paths.emplace_back(path, "bdb");
45+
} else if (IsSQLiteFile(SQLiteDataFile(it->path()))) {
46+
// Found a directory which contains wallet.dat sqlite file, add it as a wallet with SQLITE format.
47+
paths.emplace_back(path, "sqlite");
48+
}
4549
} else if (it.depth() == 0 && it->symlink_status().type() == fs::file_type::regular && IsBDBFile(it->path())) {
4650
if (it->path().filename() == "wallet.dat") {
4751
// Found top-level wallet.dat btree file, add top level directory ""
4852
// as a wallet.
49-
paths.emplace_back();
53+
paths.emplace_back(fs::path(), "bdb");
5054
} else {
5155
// Found top-level btree file not called wallet.dat. Current bitcoin
5256
// software will never create these files but will allow them to be
5357
// opened in a shared database environment for backwards compatibility.
5458
// Add it to the list of available wallets.
55-
paths.emplace_back(path);
59+
paths.emplace_back(path, "bdb");
5660
}
5761
}
5862
} catch (const std::exception& e) {

src/wallet/db.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ enum class DatabaseStatus {
216216
};
217217

218218
/** Recursively list database paths in directory. */
219-
std::vector<fs::path> ListDatabases(const fs::path& path);
219+
std::vector<std::pair<fs::path, std::string>> ListDatabases(const fs::path& path);
220220

221221
void ReadDatabaseArgs(const ArgsManager& args, DatabaseOptions& options);
222222
std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error);

src/wallet/interfaces.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -654,11 +654,11 @@ class WalletLoaderImpl : public WalletLoader
654654
{
655655
return fs::PathToString(GetWalletDir());
656656
}
657-
std::vector<std::string> listWalletDir() override
657+
std::vector<std::pair<std::string, std::string>> listWalletDir() override
658658
{
659-
std::vector<std::string> paths;
660-
for (auto& path : ListDatabases(GetWalletDir())) {
661-
paths.push_back(fs::PathToString(path));
659+
std::vector<std::pair<std::string, std::string>> paths;
660+
for (auto& [path, format] : ListDatabases(GetWalletDir())) {
661+
paths.emplace_back(fs::PathToString(path), format);
662662
}
663663
return paths;
664664
}

src/wallet/rpc/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ static RPCHelpMan listwalletdir()
169169
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
170170
{
171171
UniValue wallets(UniValue::VARR);
172-
for (const auto& path : ListDatabases(GetWalletDir())) {
172+
for (const auto& [path, _] : ListDatabases(GetWalletDir())) {
173173
UniValue wallet(UniValue::VOBJ);
174174
wallet.pushKV("name", path.utf8string());
175175
wallets.push_back(std::move(wallet));

0 commit comments

Comments
 (0)