Skip to content

Commit f7bcb3d

Browse files
build: Drop bitcoin-tx and bitcoin-wallet dependencies on libevent
Bitcoin Core PR: bitcoin/bitcoin#18504 Pull request description: This fixes compile errors trying to build bitcoin-tx and bitcoin-wallet without libevent, which were reported by Luke Dashjr in bitcoin/bitcoin#18465 The fix avoiding `bitcoin-tx` dependency on libevent just adds a conditional build rule. This is implemented in the first commit (more details in commit description). The fix avoiding `bitcoin-wallet` dependency on libevent requires minor code changes, because `bitcoin-wallet` (unlike `bitcoin-tx`) links against code that calls `urlDecode` / `evhttp_uridecode`. This fix is implemented in the second commit (again details in the commit description).
1 parent d0bdafd commit f7bcb3d

File tree

10 files changed

+23
-6
lines changed

10 files changed

+23
-6
lines changed

build_msvc/libbitcoin_util/libbitcoin_util.vcxproj.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<ConfigurationType>StaticLibrary</ConfigurationType>
99
</PropertyGroup>
1010
<ItemGroup>
11+
<ClCompile Include="..\..\src\util\url.cpp" />
1112
@SOURCE_FILES@
1213
</ItemGroup>
1314
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />

configure.ac

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ if test x$use_pkgconfig = xyes; then
12651265
BITCOIN_QT_CHECK([PKG_CHECK_MODULES([QR], [libqrencode], [have_qrencode=yes], [have_qrencode=no])])
12661266
fi
12671267
if test x$build_bitcoin_cli$build_bitcoind$bitcoin_enable_qt$use_tests$use_bench != xnonononono; then
1268-
PKG_CHECK_MODULES([EVENT], [libevent >= 2.0.21],, [AC_MSG_ERROR(libevent version 2.0.21 or greater not found.)])
1268+
PKG_CHECK_MODULES([EVENT], [libevent], [use_libevent=yes], [AC_MSG_ERROR(libevent not found.)])
12691269
if test x$TARGET_OS != xwindows; then
12701270
PKG_CHECK_MODULES([EVENT_PTHREADS], [libevent_pthreads >= 2.0.21],, [AC_MSG_ERROR(libevent_pthreads version 2.0.21 or greater not found.)])
12711271
fi
@@ -1285,7 +1285,7 @@ if test x$use_pkgconfig = xyes; then
12851285
else
12861286

12871287
if test x$build_bitcoin_cli$build_bitcoind$bitcoin_enable_qt$use_tests$use_bench != xnonononono; then
1288-
AC_CHECK_HEADER([event2/event.h],, AC_MSG_ERROR(libevent headers missing),)
1288+
AC_CHECK_HEADER([event2/event.h], [use_libevent=yes], AC_MSG_ERROR(libevent headers missing),)
12891289
AC_CHECK_LIB([event],[main],EVENT_LIBS=-levent,AC_MSG_ERROR(libevent missing))
12901290
if test x$TARGET_OS != xwindows; then
12911291
AC_CHECK_LIB([event_pthreads],[main],EVENT_PTHREADS_LIBS=-levent_pthreads,AC_MSG_ERROR(libevent_pthreads missing))
@@ -1523,6 +1523,7 @@ AM_CONDITIONAL([ENABLE_QT_TESTS],[test x$BUILD_TEST_QT = xyes])
15231523
AM_CONDITIONAL([ENABLE_BENCH],[test x$use_bench = xyes])
15241524
AM_CONDITIONAL([USE_QRCODE], [test x$use_qr = xyes])
15251525
AM_CONDITIONAL([USE_LCOV],[test x$use_lcov = xyes])
1526+
AM_CONDITIONAL([USE_LIBEVENT],[test x$use_libevent = xyes])
15261527
AM_CONDITIONAL([GLIBC_BACK_COMPAT],[test x$use_glibc_compat = xyes])
15271528
AM_CONDITIONAL([HARDEN],[test x$use_hardening = xyes])
15281529
AM_CONDITIONAL([ENABLE_SSE42],[test x$enable_sse42 = xyes])

src/Makefile.am

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,11 +530,14 @@ libbitcoin_util_a_SOURCES = \
530530
util/strencodings.cpp \
531531
util/string.cpp \
532532
util/time.cpp \
533-
util/url.cpp \
534533
util/matrixchecks.cpp \
535534
util/matrixchecks.h \
536535
$(BITCOIN_CORE_H)
537536

537+
if USE_LIBEVENT
538+
libbitcoin_util_a_SOURCES += util/url.cpp
539+
endif
540+
538541
if GLIBC_BACK_COMPAT
539542
libbitcoin_util_a_SOURCES += compat/glibc_compat.cpp
540543
AM_LDFLAGS += $(COMPAT_LDFLAGS)

src/bitcoin-cli.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <util/strencodings.h>
1616
#include <util/system.h>
1717
#include <util/translation.h>
18+
#include <util/url.h>
1819

1920
#include <functional>
2021
#include <memory>
@@ -29,6 +30,7 @@
2930
#include <compat/stdin.h>
3031

3132
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
33+
UrlDecodeFn* const URL_DECODE = urlDecode;
3234

3335
static const char DEFAULT_RPCCONNECT[] = "127.0.0.1";
3436
static const int DEFAULT_HTTP_CLIENT_TIMEOUT=900;

src/bitcoin-wallet.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
#include <logging.h>
1212
#include <util/system.h>
1313
#include <util/translation.h>
14+
#include <util/url.h>
1415
#include <wallet/wallettool.h>
1516

1617
#include <functional>
1718

1819
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
20+
UrlDecodeFn* const URL_DECODE = nullptr;
1921

2022
static void SetupWalletToolArgs()
2123
{

src/bitcoind.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
#include <util/system.h>
2121
#include <util/threadnames.h>
2222
#include <util/translation.h>
23+
#include <util/url.h>
2324

2425
#include <functional>
2526

2627
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
28+
UrlDecodeFn* const URL_DECODE = urlDecode;
2729

2830
static void WaitForShutdown(NodeContext& node)
2931
{

src/qt/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <qt/bitcoin.h>
66

77
#include <util/translation.h>
8+
#include <util/url.h>
89

910
#include <QCoreApplication>
1011

@@ -15,5 +16,6 @@
1516
extern const std::function<std::string(const char*)> G_TRANSLATION_FUN = [](const char* psz) {
1617
return QCoreApplication::translate("bitcoin-core", psz).toStdString();
1718
};
19+
UrlDecodeFn* const URL_DECODE = urlDecode;
1820

1921
int main(int argc, char* argv[]) { return GuiMain(argc, argv); }

src/test/util/setup_common.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@
2727
#include <util/string.h>
2828
#include <util/time.h>
2929
#include <util/translation.h>
30+
#include <util/url.h>
3031
#include <validation.h>
3132
#include <validationinterface.h>
3233

3334
#include <functional>
3435

3536
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
37+
UrlDecodeFn* const URL_DECODE = nullptr;
3638

3739
FastRandomContext g_insecure_rand_ctx;
3840
/** Random context to get unique temp data dirs. Separate from g_insecure_rand_ctx, which can be seeded from a const env var */

src/util/url.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include <string>
99

10-
std::string urlDecode(const std::string &urlEncoded);
10+
using UrlDecodeFn = std::string(const std::string& url_encoded);
11+
UrlDecodeFn urlDecode;
12+
extern UrlDecodeFn* const URL_DECODE;
1113

1214
#endif // BITCOIN_UTIL_URL_H

src/wallet/rpcwallet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ bool HaveKey(const SigningProvider& wallet, const CKey& key)
7878

7979
bool GetWalletNameFromJSONRPCRequest(const JSONRPCRequest& request, std::string& wallet_name)
8080
{
81-
if (request.URI.substr(0, WALLET_ENDPOINT_BASE.size()) == WALLET_ENDPOINT_BASE) {
81+
if (URL_DECODE && request.URI.substr(0, WALLET_ENDPOINT_BASE.size()) == WALLET_ENDPOINT_BASE) {
8282
// wallet endpoint was used
83-
wallet_name = urlDecode(request.URI.substr(WALLET_ENDPOINT_BASE.size()));
83+
wallet_name = URL_DECODE(request.URI.substr(WALLET_ENDPOINT_BASE.size()));
8484
return true;
8585
}
8686
return false;

0 commit comments

Comments
 (0)