aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build_msvc/bitcoin_config.h6
-rw-r--r--build_msvc/libbitcoin_wallet/libbitcoin_wallet.vcxproj.in3
-rw-r--r--configure.ac1
-rw-r--r--src/Makefile.am5
-rw-r--r--src/Makefile.test.include5
-rw-r--r--src/qt/rpcconsole.cpp2
-rw-r--r--src/wallet/init.cpp7
-rw-r--r--src/wallet/walletdb.cpp32
-rw-r--r--src/wallet/wallettool.cpp5
-rw-r--r--src/wallet/walletutil.cpp4
10 files changed, 63 insertions, 7 deletions
diff --git a/build_msvc/bitcoin_config.h b/build_msvc/bitcoin_config.h
index c1433d4852..2e6101a52e 100644
--- a/build_msvc/bitcoin_config.h
+++ b/build_msvc/bitcoin_config.h
@@ -38,6 +38,12 @@
/* Define to 1 to enable wallet functions */
#define ENABLE_WALLET 1
+/* Define to 1 to enable BDB wallet */
+#define USE_BDB 1
+
+/* Define to 1 to enable SQLite wallet */
+#define USE_SQLITE 1
+
/* Define to 1 to enable ZMQ functions */
#define ENABLE_ZMQ 1
diff --git a/build_msvc/libbitcoin_wallet/libbitcoin_wallet.vcxproj.in b/build_msvc/libbitcoin_wallet/libbitcoin_wallet.vcxproj.in
index 9c8279c72a..613d5c7199 100644
--- a/build_msvc/libbitcoin_wallet/libbitcoin_wallet.vcxproj.in
+++ b/build_msvc/libbitcoin_wallet/libbitcoin_wallet.vcxproj.in
@@ -8,6 +8,9 @@
<ConfigurationType>StaticLibrary</ConfigurationType>
</PropertyGroup>
<ItemGroup>
+ <ClCompile Include="..\..\src\wallet\bdb.cpp" />
+ <ClCompile Include="..\..\src\wallet\salvage.cpp" />
+ <ClCompile Include="..\..\src\wallet\sqlite.cpp" />
@SOURCE_FILES@
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
diff --git a/configure.ac b/configure.ac
index 01041ceab1..0ec7935091 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1602,6 +1602,7 @@ AM_CONDITIONAL([TARGET_LINUX], [test x$TARGET_OS = xlinux])
AM_CONDITIONAL([TARGET_WINDOWS], [test x$TARGET_OS = xwindows])
AM_CONDITIONAL([ENABLE_WALLET],[test x$enable_wallet = xyes])
AM_CONDITIONAL([USE_SQLITE], [test "x$use_sqlite" = "xyes"])
+AM_CONDITIONAL([USE_BDB], [true])
AM_CONDITIONAL([ENABLE_TESTS],[test x$BUILD_TEST = xyes])
AM_CONDITIONAL([ENABLE_FUZZ],[test x$enable_fuzz = xyes])
AM_CONDITIONAL([ENABLE_QT],[test x$bitcoin_enable_qt = xyes])
diff --git a/src/Makefile.am b/src/Makefile.am
index 67fd402603..0409faee1e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -360,7 +360,6 @@ libbitcoin_wallet_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(SQLITE_CFLAG
libbitcoin_wallet_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libbitcoin_wallet_a_SOURCES = \
interfaces/wallet.cpp \
- wallet/bdb.cpp \
wallet/coincontrol.cpp \
wallet/context.cpp \
wallet/crypter.cpp \
@@ -370,7 +369,6 @@ libbitcoin_wallet_a_SOURCES = \
wallet/load.cpp \
wallet/rpcdump.cpp \
wallet/rpcwallet.cpp \
- wallet/salvage.cpp \
wallet/scriptpubkeyman.cpp \
wallet/wallet.cpp \
wallet/walletdb.cpp \
@@ -381,6 +379,9 @@ libbitcoin_wallet_a_SOURCES = \
if USE_SQLITE
libbitcoin_wallet_a_SOURCES += wallet/sqlite.cpp
endif
+if USE_BDB
+libbitcoin_wallet_a_SOURCES += wallet/bdb.cpp wallet/salvage.cpp
+endif
libbitcoin_wallet_tool_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
libbitcoin_wallet_tool_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
diff --git a/src/Makefile.test.include b/src/Makefile.test.include
index 9cc383c240..9fc7533e0d 100644
--- a/src/Makefile.test.include
+++ b/src/Makefile.test.include
@@ -292,7 +292,6 @@ BITCOIN_TESTS =\
if ENABLE_WALLET
BITCOIN_TESTS += \
- wallet/test/db_tests.cpp \
wallet/test/psbt_wallet_tests.cpp \
wallet/test/wallet_tests.cpp \
wallet/test/wallet_crypto_tests.cpp \
@@ -301,6 +300,10 @@ BITCOIN_TESTS += \
wallet/test/ismine_tests.cpp \
wallet/test/scriptpubkeyman_tests.cpp
+if USE_BDB
+BITCOIN_TESTS += wallet/test/db_tests.cpp
+endif
+
BITCOIN_TEST_SUITE += \
wallet/test/wallet_test_fixture.cpp \
wallet/test/wallet_test_fixture.h \
diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp
index 9887ae668b..88dfbd69ff 100644
--- a/src/qt/rpcconsole.cpp
+++ b/src/qt/rpcconsole.cpp
@@ -25,7 +25,9 @@
#include <univalue.h>
#ifdef ENABLE_WALLET
+#ifdef USE_BDB
#include <wallet/bdb.h>
+#endif
#include <wallet/db.h>
#include <wallet/wallet.h>
#endif
diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp
index c2fb893c51..085dde1026 100644
--- a/src/wallet/init.cpp
+++ b/src/wallet/init.cpp
@@ -15,7 +15,9 @@
#include <util/moneystr.h>
#include <util/system.h>
#include <util/translation.h>
+#ifdef USE_BDB
#include <wallet/bdb.h>
+#endif
#include <wallet/coincontrol.h>
#include <wallet/wallet.h>
#include <walletinitinterface.h>
@@ -69,9 +71,14 @@ void WalletInit::AddWalletOptions(ArgsManager& argsman) const
#endif
argsman.AddArg("-walletrbf", strprintf("Send transactions with full-RBF opt-in enabled (RPC only, default: %u)", DEFAULT_WALLET_RBF), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
+#ifdef USE_BDB
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);
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);
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);
+#else
+ argsman.AddHiddenArgs({"-dblogsize", "-flushwallet", "-privdb"});
+#endif
+
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);
argsman.AddHiddenArgs({"-zapwallettxes"});
diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp
index aa3b3c10b0..1543e8fb81 100644
--- a/src/wallet/walletdb.cpp
+++ b/src/wallet/walletdb.cpp
@@ -14,7 +14,9 @@
#include <util/system.h>
#include <util/time.h>
#include <util/translation.h>
+#ifdef USE_BDB
#include <wallet/bdb.h>
+#endif
#ifdef USE_SQLITE
#include <wallet/sqlite.h>
#endif
@@ -1011,9 +1013,11 @@ std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const Databas
Optional<DatabaseFormat> format;
if (exists) {
+#ifdef USE_BDB
if (ExistsBerkeleyDatabase(path)) {
format = DatabaseFormat::BERKELEY;
}
+#endif
#ifdef USE_SQLITE
if (ExistsSQLiteDatabase(path)) {
if (format) {
@@ -1052,15 +1056,31 @@ std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const Databas
// Format is not set when a db doesn't already exist, so use the format specified by the options if it is set.
if (!format && options.require_format) format = options.require_format;
+ // If the format is not specified or detected, choose the default format based on what is available. We prefer BDB over SQLite for now.
+ if (!format) {
#ifdef USE_SQLITE
- if (format && format == DatabaseFormat::SQLITE) {
- return MakeSQLiteDatabase(path, options, status, error);
+ format = DatabaseFormat::SQLITE;
+#endif
+#ifdef USE_BDB
+ format = DatabaseFormat::BERKELEY;
+#endif
}
-#else
- assert(format != DatabaseFormat::SQLITE);
+
+ if (format == DatabaseFormat::SQLITE) {
+#ifdef USE_SQLITE
+ return MakeSQLiteDatabase(path, options, status, error);
#endif
+ error = Untranslated(strprintf("Failed to open database path '%s'. Build does not support SQLite database format.", path.string()));
+ status = DatabaseStatus::FAILED_BAD_FORMAT;
+ return nullptr;
+ }
+#ifdef USE_BDB
return MakeBerkeleyDatabase(path, options, status, error);
+#endif
+ error = Untranslated(strprintf("Failed to open database path '%s'. Build does not support Berkeley DB database format.", path.string()));
+ status = DatabaseStatus::FAILED_BAD_FORMAT;
+ return nullptr;
}
/** Return object for accessing dummy database with no read/write capabilities. */
@@ -1072,5 +1092,9 @@ std::unique_ptr<WalletDatabase> CreateDummyWalletDatabase()
/** Return object for accessing temporary in-memory database. */
std::unique_ptr<WalletDatabase> CreateMockWalletDatabase()
{
+#ifdef USE_BDB
return MakeUnique<BerkeleyDatabase>(std::make_shared<BerkeleyEnvironment>(), "");
+#elif USE_SQLITE
+ return MakeUnique<SQLiteDatabase>("", "", true);
+#endif
}
diff --git a/src/wallet/wallettool.cpp b/src/wallet/wallettool.cpp
index 0e18d6a740..dad1232e10 100644
--- a/src/wallet/wallettool.cpp
+++ b/src/wallet/wallettool.cpp
@@ -122,6 +122,7 @@ bool ExecuteWalletToolFunc(const std::string& command, const std::string& name)
WalletShowInfo(wallet_instance.get());
wallet_instance->Close();
} else if (command == "salvage") {
+#ifdef USE_BDB
bilingual_str error;
std::vector<bilingual_str> warnings;
bool ret = RecoverDatabaseFile(path, error, warnings);
@@ -134,6 +135,10 @@ bool ExecuteWalletToolFunc(const std::string& command, const std::string& name)
}
}
return ret;
+#else
+ tfm::format(std::cerr, "Salvage command is not available as BDB support is not compiled");
+ return false;
+#endif
}
} else {
tfm::format(std::cerr, "Invalid command: %s\n", command);
diff --git a/src/wallet/walletutil.cpp b/src/wallet/walletutil.cpp
index 702293e6c7..d3f76ec66c 100644
--- a/src/wallet/walletutil.cpp
+++ b/src/wallet/walletutil.cpp
@@ -7,7 +7,11 @@
#include <logging.h>
#include <util/system.h>
+#ifdef USE_BDB
bool ExistsBerkeleyDatabase(const fs::path& path);
+#else
+# define ExistsBerkeleyDatabase(path) (false)
+#endif
#ifdef USE_SQLITE
bool ExistsSQLiteDatabase(const fs::path& path);
#else