aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorAva Chow <github@achow101.com>2024-06-10 15:00:21 -0400
committerAva Chow <github@achow101.com>2024-08-13 11:25:38 -0400
commit28fc562f2692af4f37f918d4ae31c4d115e03aee (patch)
treef45c92d038c4e03d04241ac2c2aa11130294d8ee /src/wallet
parent1873e4116ff53daacde7849f8b7f23ac0b527bec (diff)
wallet, interfaces: Include database format in listWalletDir
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/db.cpp26
-rw-r--r--src/wallet/db.h2
-rw-r--r--src/wallet/interfaces.cpp8
-rw-r--r--src/wallet/rpc/wallet.cpp2
4 files changed, 23 insertions, 15 deletions
diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp
index 1523b7d613..400b9dc44f 100644
--- a/src/wallet/db.cpp
+++ b/src/wallet/db.cpp
@@ -19,9 +19,9 @@ namespace wallet {
bool operator<(BytePrefix a, Span<const std::byte> b) { return a.prefix < b.subspan(0, std::min(a.prefix.size(), b.size())); }
bool operator<(Span<const std::byte> a, BytePrefix b) { return a.subspan(0, std::min(a.size(), b.prefix.size())) < b.prefix; }
-std::vector<fs::path> ListDatabases(const fs::path& wallet_dir)
+std::vector<std::pair<fs::path, std::string>> ListDatabases(const fs::path& wallet_dir)
{
- std::vector<fs::path> paths;
+ std::vector<std::pair<fs::path, std::string>> paths;
std::error_code ec;
for (auto it = fs::recursive_directory_iterator(wallet_dir, ec); it != fs::recursive_directory_iterator(); it.increment(ec)) {
@@ -38,21 +38,29 @@ std::vector<fs::path> ListDatabases(const fs::path& wallet_dir)
try {
const fs::path path{it->path().lexically_relative(wallet_dir)};
- if (it->status().type() == fs::file_type::directory &&
- (IsBDBFile(BDBDataFile(it->path())) || IsSQLiteFile(SQLiteDataFile(it->path())))) {
- // Found a directory which contains wallet.dat btree file, add it as a wallet.
- paths.emplace_back(path);
+ if (it->status().type() == fs::file_type::directory) {
+ if (IsBDBFile(BDBDataFile(it->path()))) {
+ // Found a directory which contains wallet.dat btree file, add it as a wallet with BERKELEY format.
+ paths.emplace_back(path, "bdb");
+ } else if (IsSQLiteFile(SQLiteDataFile(it->path()))) {
+ // Found a directory which contains wallet.dat sqlite file, add it as a wallet with SQLITE format.
+ paths.emplace_back(path, "sqlite");
+ }
} else if (it.depth() == 0 && it->symlink_status().type() == fs::file_type::regular && it->path().extension() != ".bak") {
if (it->path().filename() == "wallet.dat") {
- // Found top-level wallet.dat btree file, add top level directory ""
+ // Found top-level wallet.dat file, add top level directory ""
// as a wallet.
- paths.emplace_back();
+ if (IsBDBFile(it->path())) {
+ paths.emplace_back(fs::path(), "bdb");
+ } else if (IsSQLiteFile(it->path())) {
+ paths.emplace_back(fs::path(), "sqlite");
+ }
} else if (IsBDBFile(it->path())) {
// Found top-level btree file not called wallet.dat. Current bitcoin
// software will never create these files but will allow them to be
// opened in a shared database environment for backwards compatibility.
// Add it to the list of available wallets.
- paths.emplace_back(path);
+ paths.emplace_back(path, "bdb");
}
}
} catch (const std::exception& e) {
diff --git a/src/wallet/db.h b/src/wallet/db.h
index 2045d51376..049af8dd19 100644
--- a/src/wallet/db.h
+++ b/src/wallet/db.h
@@ -216,7 +216,7 @@ enum class DatabaseStatus {
};
/** Recursively list database paths in directory. */
-std::vector<fs::path> ListDatabases(const fs::path& path);
+std::vector<std::pair<fs::path, std::string>> ListDatabases(const fs::path& path);
void ReadDatabaseArgs(const ArgsManager& args, DatabaseOptions& options);
std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error);
diff --git a/src/wallet/interfaces.cpp b/src/wallet/interfaces.cpp
index 9fab1b2ee4..14f05b6871 100644
--- a/src/wallet/interfaces.cpp
+++ b/src/wallet/interfaces.cpp
@@ -656,11 +656,11 @@ public:
{
return fs::PathToString(GetWalletDir());
}
- std::vector<std::string> listWalletDir() override
+ std::vector<std::pair<std::string, std::string>> listWalletDir() override
{
- std::vector<std::string> paths;
- for (auto& path : ListDatabases(GetWalletDir())) {
- paths.push_back(fs::PathToString(path));
+ std::vector<std::pair<std::string, std::string>> paths;
+ for (auto& [path, format] : ListDatabases(GetWalletDir())) {
+ paths.emplace_back(fs::PathToString(path), format);
}
return paths;
}
diff --git a/src/wallet/rpc/wallet.cpp b/src/wallet/rpc/wallet.cpp
index ae1c67ef2a..7a0b0103c0 100644
--- a/src/wallet/rpc/wallet.cpp
+++ b/src/wallet/rpc/wallet.cpp
@@ -169,7 +169,7 @@ static RPCHelpMan listwalletdir()
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
UniValue wallets(UniValue::VARR);
- for (const auto& path : ListDatabases(GetWalletDir())) {
+ for (const auto& [path, _] : ListDatabases(GetWalletDir())) {
UniValue wallet(UniValue::VOBJ);
wallet.pushKV("name", path.utf8string());
wallets.push_back(std::move(wallet));