Skip to content

Commit a108080

Browse files
committed
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.
1 parent 7c0d344 commit a108080

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/wallet/walletdb.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,13 +1187,36 @@ std::unique_ptr<WalletDatabase> CreateDummyWalletDatabase()
11871187
}
11881188

11891189
/** Return object for accessing temporary in-memory database. */
1190-
std::unique_ptr<WalletDatabase> CreateMockWalletDatabase()
1190+
std::unique_ptr<WalletDatabase> CreateMockWalletDatabase(DatabaseOptions& options)
11911191
{
1192-
DatabaseOptions options;
1192+
1193+
std::optional<DatabaseFormat> format;
1194+
if (options.require_format) format = options.require_format;
1195+
if (!format) {
1196+
#ifdef USE_BDB
1197+
format = DatabaseFormat::BERKELEY;
1198+
#endif
11931199
#ifdef USE_SQLITE
1194-
return std::make_unique<SQLiteDatabase>("", "", options, true);
1195-
#elif USE_BDB
1200+
format = DatabaseFormat::SQLITE;
1201+
#endif
1202+
}
1203+
1204+
if (format == DatabaseFormat::SQLITE) {
1205+
#ifdef USE_SQLITE
1206+
return std::make_unique<SQLiteDatabase>("", "", options, true);
1207+
#endif
1208+
assert(false);
1209+
}
1210+
1211+
#ifdef USE_BDB
11961212
return std::make_unique<BerkeleyDatabase>(std::make_shared<BerkeleyEnvironment>(), "", options);
11971213
#endif
1214+
assert(false);
1215+
}
1216+
1217+
std::unique_ptr<WalletDatabase> CreateMockWalletDatabase()
1218+
{
1219+
DatabaseOptions options;
1220+
return CreateMockWalletDatabase(options);
11981221
}
11991222
} // namespace wallet

src/wallet/walletdb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ bool ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, st
301301
std::unique_ptr<WalletDatabase> CreateDummyWalletDatabase();
302302

303303
/** Return object for accessing temporary in-memory database. */
304+
std::unique_ptr<WalletDatabase> CreateMockWalletDatabase(DatabaseOptions& options);
304305
std::unique_ptr<WalletDatabase> CreateMockWalletDatabase();
305306
} // namespace wallet
306307

0 commit comments

Comments
 (0)