Skip to content

Commit a58b719

Browse files
committed
Do not compile BDB things when USE_BDB is defined
1 parent b33af48 commit a58b719

File tree

10 files changed

+63
-7
lines changed

10 files changed

+63
-7
lines changed

build_msvc/bitcoin_config.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
/* Define to 1 to enable wallet functions */
3939
#define ENABLE_WALLET 1
4040

41+
/* Define to 1 to enable BDB wallet */
42+
#define USE_BDB 1
43+
44+
/* Define to 1 to enable SQLite wallet */
45+
#define USE_SQLITE 1
46+
4147
/* Define to 1 to enable ZMQ functions */
4248
#define ENABLE_ZMQ 1
4349

build_msvc/libbitcoin_wallet/libbitcoin_wallet.vcxproj.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
<ConfigurationType>StaticLibrary</ConfigurationType>
99
</PropertyGroup>
1010
<ItemGroup>
11+
<ClCompile Include="..\..\src\wallet\bdb.cpp" />
12+
<ClCompile Include="..\..\src\wallet\salvage.cpp" />
13+
<ClCompile Include="..\..\src\wallet\sqlite.cpp" />
1114
@SOURCE_FILES@
1215
</ItemGroup>
1316
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,6 +1602,7 @@ AM_CONDITIONAL([TARGET_LINUX], [test x$TARGET_OS = xlinux])
16021602
AM_CONDITIONAL([TARGET_WINDOWS], [test x$TARGET_OS = xwindows])
16031603
AM_CONDITIONAL([ENABLE_WALLET],[test x$enable_wallet = xyes])
16041604
AM_CONDITIONAL([USE_SQLITE], [test "x$use_sqlite" = "xyes"])
1605+
AM_CONDITIONAL([USE_BDB], [true])
16051606
AM_CONDITIONAL([ENABLE_TESTS],[test x$BUILD_TEST = xyes])
16061607
AM_CONDITIONAL([ENABLE_FUZZ],[test x$enable_fuzz = xyes])
16071608
AM_CONDITIONAL([ENABLE_QT],[test x$bitcoin_enable_qt = xyes])

src/Makefile.am

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,6 @@ libbitcoin_wallet_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(SQLITE_CFLAG
360360
libbitcoin_wallet_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
361361
libbitcoin_wallet_a_SOURCES = \
362362
interfaces/wallet.cpp \
363-
wallet/bdb.cpp \
364363
wallet/coincontrol.cpp \
365364
wallet/context.cpp \
366365
wallet/crypter.cpp \
@@ -370,7 +369,6 @@ libbitcoin_wallet_a_SOURCES = \
370369
wallet/load.cpp \
371370
wallet/rpcdump.cpp \
372371
wallet/rpcwallet.cpp \
373-
wallet/salvage.cpp \
374372
wallet/scriptpubkeyman.cpp \
375373
wallet/wallet.cpp \
376374
wallet/walletdb.cpp \
@@ -381,6 +379,9 @@ libbitcoin_wallet_a_SOURCES = \
381379
if USE_SQLITE
382380
libbitcoin_wallet_a_SOURCES += wallet/sqlite.cpp
383381
endif
382+
if USE_BDB
383+
libbitcoin_wallet_a_SOURCES += wallet/bdb.cpp wallet/salvage.cpp
384+
endif
384385

385386
libbitcoin_wallet_tool_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
386387
libbitcoin_wallet_tool_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)

src/Makefile.test.include

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ BITCOIN_TESTS =\
292292

293293
if ENABLE_WALLET
294294
BITCOIN_TESTS += \
295-
wallet/test/db_tests.cpp \
296295
wallet/test/psbt_wallet_tests.cpp \
297296
wallet/test/wallet_tests.cpp \
298297
wallet/test/wallet_crypto_tests.cpp \
@@ -301,6 +300,10 @@ BITCOIN_TESTS += \
301300
wallet/test/ismine_tests.cpp \
302301
wallet/test/scriptpubkeyman_tests.cpp
303302

303+
if USE_BDB
304+
BITCOIN_TESTS += wallet/test/db_tests.cpp
305+
endif
306+
304307
BITCOIN_TEST_SUITE += \
305308
wallet/test/wallet_test_fixture.cpp \
306309
wallet/test/wallet_test_fixture.h \

src/qt/rpcconsole.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
#include <univalue.h>
2626

2727
#ifdef ENABLE_WALLET
28+
#ifdef USE_BDB
2829
#include <wallet/bdb.h>
30+
#endif
2931
#include <wallet/db.h>
3032
#include <wallet/wallet.h>
3133
#endif

src/wallet/init.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
#include <util/moneystr.h>
1616
#include <util/system.h>
1717
#include <util/translation.h>
18+
#ifdef USE_BDB
1819
#include <wallet/bdb.h>
20+
#endif
1921
#include <wallet/coincontrol.h>
2022
#include <wallet/wallet.h>
2123
#include <walletinitinterface.h>
@@ -69,9 +71,14 @@ void WalletInit::AddWalletOptions(ArgsManager& argsman) const
6971
#endif
7072
argsman.AddArg("-walletrbf", strprintf("Send transactions with full-RBF opt-in enabled (RPC only, default: %u)", DEFAULT_WALLET_RBF), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
7173

74+
#ifdef USE_BDB
7275
argsman.AddArg("-dblogsize=<n>", strprintf("Flush wallet database activity from memory to disk log every <n> megabytes (default: %u)", DEFAULT_WALLET_DBLOGSIZE), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
7376
argsman.AddArg("-flushwallet", strprintf("Run a thread to flush wallet periodically (default: %u)", DEFAULT_FLUSHWALLET), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
7477
argsman.AddArg("-privdb", strprintf("Sets the DB_PRIVATE flag in the wallet db environment (default: %u)", DEFAULT_WALLET_PRIVDB), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
78+
#else
79+
argsman.AddHiddenArgs({"-dblogsize", "-flushwallet", "-privdb"});
80+
#endif
81+
7582
argsman.AddArg("-walletrejectlongchains", strprintf("Wallet will not create transactions that violate mempool chain limits (default: %u)", DEFAULT_WALLET_REJECT_LONG_CHAINS), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
7683

7784
argsman.AddHiddenArgs({"-zapwallettxes"});

src/wallet/walletdb.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
#include <util/system.h>
1515
#include <util/time.h>
1616
#include <util/translation.h>
17+
#ifdef USE_BDB
1718
#include <wallet/bdb.h>
19+
#endif
1820
#ifdef USE_SQLITE
1921
#include <wallet/sqlite.h>
2022
#endif
@@ -1011,9 +1013,11 @@ std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const Databas
10111013

10121014
Optional<DatabaseFormat> format;
10131015
if (exists) {
1016+
#ifdef USE_BDB
10141017
if (ExistsBerkeleyDatabase(path)) {
10151018
format = DatabaseFormat::BERKELEY;
10161019
}
1020+
#endif
10171021
#ifdef USE_SQLITE
10181022
if (ExistsSQLiteDatabase(path)) {
10191023
if (format) {
@@ -1052,15 +1056,31 @@ std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const Databas
10521056
// Format is not set when a db doesn't already exist, so use the format specified by the options if it is set.
10531057
if (!format && options.require_format) format = options.require_format;
10541058

1059+
// If the format is not specified or detected, choose the default format based on what is available. We prefer BDB over SQLite for now.
1060+
if (!format) {
10551061
#ifdef USE_SQLITE
1056-
if (format && format == DatabaseFormat::SQLITE) {
1057-
return MakeSQLiteDatabase(path, options, status, error);
1062+
format = DatabaseFormat::SQLITE;
1063+
#endif
1064+
#ifdef USE_BDB
1065+
format = DatabaseFormat::BERKELEY;
1066+
#endif
10581067
}
1059-
#else
1060-
assert(format != DatabaseFormat::SQLITE);
1068+
1069+
if (format == DatabaseFormat::SQLITE) {
1070+
#ifdef USE_SQLITE
1071+
return MakeSQLiteDatabase(path, options, status, error);
10611072
#endif
1073+
error = Untranslated(strprintf("Failed to open database path '%s'. Build does not support SQLite database format.", path.string()));
1074+
status = DatabaseStatus::FAILED_BAD_FORMAT;
1075+
return nullptr;
1076+
}
10621077

1078+
#ifdef USE_BDB
10631079
return MakeBerkeleyDatabase(path, options, status, error);
1080+
#endif
1081+
error = Untranslated(strprintf("Failed to open database path '%s'. Build does not support Berkeley DB database format.", path.string()));
1082+
status = DatabaseStatus::FAILED_BAD_FORMAT;
1083+
return nullptr;
10641084
}
10651085

10661086
/** Return object for accessing dummy database with no read/write capabilities. */
@@ -1072,5 +1092,9 @@ std::unique_ptr<WalletDatabase> CreateDummyWalletDatabase()
10721092
/** Return object for accessing temporary in-memory database. */
10731093
std::unique_ptr<WalletDatabase> CreateMockWalletDatabase()
10741094
{
1095+
#ifdef USE_BDB
10751096
return MakeUnique<BerkeleyDatabase>(std::make_shared<BerkeleyEnvironment>(), "");
1097+
#elif USE_SQLITE
1098+
return MakeUnique<SQLiteDatabase>("", "", true);
1099+
#endif
10761100
}

src/wallet/wallettool.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ bool ExecuteWalletToolFunc(const std::string& command, const std::string& name)
122122
WalletShowInfo(wallet_instance.get());
123123
wallet_instance->Close();
124124
} else if (command == "salvage") {
125+
#ifdef USE_BDB
125126
bilingual_str error;
126127
std::vector<bilingual_str> warnings;
127128
bool ret = RecoverDatabaseFile(path, error, warnings);
@@ -134,6 +135,10 @@ bool ExecuteWalletToolFunc(const std::string& command, const std::string& name)
134135
}
135136
}
136137
return ret;
138+
#else
139+
tfm::format(std::cerr, "Salvage command is not available as BDB support is not compiled");
140+
return false;
141+
#endif
137142
}
138143
} else {
139144
tfm::format(std::cerr, "Invalid command: %s\n", command);

src/wallet/walletutil.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
#include <logging.h>
88
#include <util/system.h>
99

10+
#ifdef USE_BDB
1011
bool ExistsBerkeleyDatabase(const fs::path& path);
12+
#else
13+
# define ExistsBerkeleyDatabase(path) (false)
14+
#endif
1115
#ifdef USE_SQLITE
1216
bool ExistsSQLiteDatabase(const fs::path& path);
1317
#else

0 commit comments

Comments
 (0)