mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
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.
This commit is contained in:
parent
7c0d34476d
commit
a1080802f8
2 changed files with 29 additions and 5 deletions
|
@ -1187,13 +1187,36 @@ std::unique_ptr<WalletDatabase> CreateDummyWalletDatabase()
|
|||
}
|
||||
|
||||
/** Return object for accessing temporary in-memory database. */
|
||||
std::unique_ptr<WalletDatabase> CreateMockWalletDatabase(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
|
||||
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;
|
||||
#ifdef USE_SQLITE
|
||||
return std::make_unique<SQLiteDatabase>("", "", options, true);
|
||||
#elif USE_BDB
|
||||
return std::make_unique<BerkeleyDatabase>(std::make_shared<BerkeleyEnvironment>(), "", options);
|
||||
#endif
|
||||
return CreateMockWalletDatabase(options);
|
||||
}
|
||||
} // namespace wallet
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue