diff options
author | Andrew Chow <achow101-github@achow101.com> | 2022-04-20 12:51:59 -0400 |
---|---|---|
committer | Andrew Chow <achow101-github@achow101.com> | 2022-05-10 11:54:02 -0400 |
commit | a1080802f8d7c3d1251ec6f2be33031f568deafa (patch) | |
tree | 1c3fdcaeeac37f344d11562dccd8c43e07149597 | |
parent | 7c0d34476df446e3825198b27c6f62bba4c0b974 (diff) | |
download | bitcoin-a1080802f8d7c3d1251ec6f2be33031f568deafa.tar.xz |
walletdb: Create a mock database of specific type
We may want to make a mock database of either SQLite or BDB, not just
whatever the compiled default is.
-rw-r--r-- | src/wallet/walletdb.cpp | 31 | ||||
-rw-r--r-- | src/wallet/walletdb.h | 1 |
2 files changed, 28 insertions, 4 deletions
diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 7bbed7973f..26908b3777 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -1187,13 +1187,36 @@ std::unique_ptr<WalletDatabase> CreateDummyWalletDatabase() } /** Return object for accessing temporary in-memory database. */ -std::unique_ptr<WalletDatabase> CreateMockWalletDatabase() +std::unique_ptr<WalletDatabase> CreateMockWalletDatabase(DatabaseOptions& options) { - DatabaseOptions options; + + std::optional<DatabaseFormat> format; + if (options.require_format) format = options.require_format; + if (!format) { +#ifdef USE_BDB + format = DatabaseFormat::BERKELEY; +#endif #ifdef USE_SQLITE - return std::make_unique<SQLiteDatabase>("", "", options, true); -#elif USE_BDB + format = DatabaseFormat::SQLITE; +#endif + } + + if (format == DatabaseFormat::SQLITE) { +#ifdef USE_SQLITE + return std::make_unique<SQLiteDatabase>("", "", options, true); +#endif + assert(false); + } + +#ifdef USE_BDB return std::make_unique<BerkeleyDatabase>(std::make_shared<BerkeleyEnvironment>(), "", options); #endif + assert(false); +} + +std::unique_ptr<WalletDatabase> CreateMockWalletDatabase() +{ + DatabaseOptions options; + return CreateMockWalletDatabase(options); } } // namespace wallet diff --git a/src/wallet/walletdb.h b/src/wallet/walletdb.h index 3dfe781d56..a04ea598b6 100644 --- a/src/wallet/walletdb.h +++ b/src/wallet/walletdb.h @@ -301,6 +301,7 @@ bool ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, st std::unique_ptr<WalletDatabase> CreateDummyWalletDatabase(); /** Return object for accessing temporary in-memory database. */ +std::unique_ptr<WalletDatabase> CreateMockWalletDatabase(DatabaseOptions& options); std::unique_ptr<WalletDatabase> CreateMockWalletDatabase(); } // namespace wallet |