refactor: Replace ListWalletDir() function with ListDatabases()

No change to behavior. This is just cleanup after previous MOVEONLY commit to
make db.h list function fit conventions of surrounding functions.
This commit is contained in:
Russell Yanofsky
2020-10-30 16:25:56 -04:00
parent 5aaeb6cf87
commit 6ee9cbdd18
5 changed files with 6 additions and 9 deletions

View File

@ -10,8 +10,6 @@
#include <string> #include <string>
fs::path GetWalletDir();
#ifdef USE_BDB #ifdef USE_BDB
bool ExistsBerkeleyDatabase(const fs::path& path); bool ExistsBerkeleyDatabase(const fs::path& path);
#else #else
@ -23,9 +21,8 @@ bool ExistsSQLiteDatabase(const fs::path& path);
# define ExistsSQLiteDatabase(path) (false) # define ExistsSQLiteDatabase(path) (false)
#endif #endif
std::vector<fs::path> ListWalletDir() std::vector<fs::path> ListDatabases(const fs::path& wallet_dir)
{ {
const fs::path wallet_dir = GetWalletDir();
const size_t offset = wallet_dir.string().size() + 1; const size_t offset = wallet_dir.string().size() + 1;
std::vector<fs::path> paths; std::vector<fs::path> paths;
boost::system::error_code ec; boost::system::error_code ec;

View File

@ -223,6 +223,9 @@ enum class DatabaseStatus {
FAILED_ENCRYPT, FAILED_ENCRYPT,
}; };
/** Recursively list database paths in directory. */
std::vector<fs::path> ListDatabases(const fs::path& path);
std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error); std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error);
bool IsBDBFile(const fs::path& path); bool IsBDBFile(const fs::path& path);

View File

@ -551,7 +551,7 @@ public:
std::vector<std::string> listWalletDir() override std::vector<std::string> listWalletDir() override
{ {
std::vector<std::string> paths; std::vector<std::string> paths;
for (auto& path : ListWalletDir()) { for (auto& path : ListDatabases(GetWalletDir())) {
paths.push_back(path.string()); paths.push_back(path.string());
} }
return paths; return paths;

View File

@ -2537,7 +2537,7 @@ static RPCHelpMan listwalletdir()
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{ {
UniValue wallets(UniValue::VARR); UniValue wallets(UniValue::VARR);
for (const auto& path : ListWalletDir()) { for (const auto& path : ListDatabases(GetWalletDir())) {
UniValue wallet(UniValue::VOBJ); UniValue wallet(UniValue::VOBJ);
wallet.pushKV("name", path.string()); wallet.pushKV("name", path.string());
wallets.push_back(wallet); wallets.push_back(wallet);

View File

@ -65,9 +65,6 @@ enum WalletFlags : uint64_t {
//! Get the path of the wallet directory. //! Get the path of the wallet directory.
fs::path GetWalletDir(); fs::path GetWalletDir();
//! Get wallets in wallet directory.
std::vector<fs::path> ListWalletDir();
/** Descriptor with some wallet metadata */ /** Descriptor with some wallet metadata */
class WalletDescriptor class WalletDescriptor
{ {