mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-05-30 09:40:16 +02: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
@ -1187,13 +1187,36 @@ std::unique_ptr<WalletDatabase> CreateDummyWalletDatabase()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Return object for accessing temporary in-memory database. */
|
/** 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()
|
std::unique_ptr<WalletDatabase> CreateMockWalletDatabase()
|
||||||
{
|
{
|
||||||
DatabaseOptions options;
|
DatabaseOptions options;
|
||||||
#ifdef USE_SQLITE
|
return CreateMockWalletDatabase(options);
|
||||||
return std::make_unique<SQLiteDatabase>("", "", options, true);
|
|
||||||
#elif USE_BDB
|
|
||||||
return std::make_unique<BerkeleyDatabase>(std::make_shared<BerkeleyEnvironment>(), "", options);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
} // namespace wallet
|
} // namespace wallet
|
||||||
|
@ -301,6 +301,7 @@ bool ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, st
|
|||||||
std::unique_ptr<WalletDatabase> CreateDummyWalletDatabase();
|
std::unique_ptr<WalletDatabase> CreateDummyWalletDatabase();
|
||||||
|
|
||||||
/** Return object for accessing temporary in-memory database. */
|
/** Return object for accessing temporary in-memory database. */
|
||||||
|
std::unique_ptr<WalletDatabase> CreateMockWalletDatabase(DatabaseOptions& options);
|
||||||
std::unique_ptr<WalletDatabase> CreateMockWalletDatabase();
|
std::unique_ptr<WalletDatabase> CreateMockWalletDatabase();
|
||||||
} // namespace wallet
|
} // namespace wallet
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user