From 45c08f8a7b89dda6afb7d7cf9573a8ae8290ac92 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Wed, 17 Jun 2020 12:25:22 -0400 Subject: [PATCH] Add Create*WalletDatabase functions These functions doing the same things as WalletDatabase::Create, CreateMock, and CreateDummy --- src/wallet/walletdb.cpp | 19 +++++++++++++++++++ src/wallet/walletdb.h | 9 +++++++++ 2 files changed, 28 insertions(+) diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 2f6c2b883ac..6f383980764 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -1023,3 +1023,22 @@ bool IsWalletLoaded(const fs::path& wallet_path) { return IsBDBWalletLoaded(wallet_path); } + +/** Return object for accessing database at specified path. */ +std::unique_ptr CreateWalletDatabase(const fs::path& path) +{ + std::string filename; + return MakeUnique(GetWalletEnv(path, filename), std::move(filename)); +} + +/** Return object for accessing dummy database with no read/write capabilities. */ +std::unique_ptr CreateDummyWalletDatabase() +{ + return MakeUnique(); +} + +/** Return object for accessing temporary in-memory database. */ +std::unique_ptr CreateMockWalletDatabase() +{ + return MakeUnique(std::make_shared(), ""); +} diff --git a/src/wallet/walletdb.h b/src/wallet/walletdb.h index 1037bd579fe..61e0f19e562 100644 --- a/src/wallet/walletdb.h +++ b/src/wallet/walletdb.h @@ -293,4 +293,13 @@ bool ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, st /** Return whether a wallet database is currently loaded. */ bool IsWalletLoaded(const fs::path& wallet_path); +/** Return object for accessing database at specified path. */ +std::unique_ptr CreateWalletDatabase(const fs::path& path); + +/** Return object for accessing dummy database with no read/write capabilities. */ +std::unique_ptr CreateDummyWalletDatabase(); + +/** Return object for accessing temporary in-memory database. */ +std::unique_ptr CreateMockWalletDatabase(); + #endif // BITCOIN_WALLET_WALLETDB_H