From 01a3392b1b778fa4fcf568013326d6ea1de4fb3b Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Thu, 2 Apr 2020 08:35:10 -0400 Subject: Drop bitcoin-wallet dependency on libevent Don't require urlDecode function in wallet code since urlDecode implementation currently uses libevent. Just call urlDecode indirectly though URL_DECODE function pointer constant if available. In bitcoind and bitcoin-qt, URL_DECODE is implemented and used to interpret RPC wallet requests. In bitcoin-wallet, URL_DECODE is null to avoid depending on libevent. --- src/bitcoin-cli.cpp | 2 ++ src/bitcoin-wallet.cpp | 2 ++ src/bitcoind.cpp | 2 ++ src/qt/main.cpp | 2 ++ src/test/util/setup_common.cpp | 2 ++ src/util/url.h | 4 +++- src/wallet/rpcwallet.cpp | 4 ++-- 7 files changed, 15 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 6982eaab61..3c773fb64d 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -29,6 +30,7 @@ #include const std::function G_TRANSLATION_FUN = nullptr; +UrlDecodeFn* const URL_DECODE = urlDecode; static const char DEFAULT_RPCCONNECT[] = "127.0.0.1"; static const int DEFAULT_HTTP_CLIENT_TIMEOUT=900; diff --git a/src/bitcoin-wallet.cpp b/src/bitcoin-wallet.cpp index 7f1a4a114b..76152a81d8 100644 --- a/src/bitcoin-wallet.cpp +++ b/src/bitcoin-wallet.cpp @@ -11,11 +11,13 @@ #include #include #include +#include #include #include const std::function G_TRANSLATION_FUN = nullptr; +UrlDecodeFn* const URL_DECODE = nullptr; static void SetupWalletToolArgs() { diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index e284dce0d5..f26eb45fce 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -20,10 +20,12 @@ #include #include #include +#include #include const std::function G_TRANSLATION_FUN = nullptr; +UrlDecodeFn* const URL_DECODE = urlDecode; static void WaitForShutdown(NodeContext& node) { diff --git a/src/qt/main.cpp b/src/qt/main.cpp index 3dfd9e850e..607cf9f976 100644 --- a/src/qt/main.cpp +++ b/src/qt/main.cpp @@ -5,6 +5,7 @@ #include #include +#include #include @@ -15,5 +16,6 @@ extern const std::function G_TRANSLATION_FUN = [](const char* psz) { return QCoreApplication::translate("bitcoin-core", psz).toStdString(); }; +UrlDecodeFn* const URL_DECODE = urlDecode; int main(int argc, char* argv[]) { return GuiMain(argc, argv); } diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index d684b97787..b7f5dcfe43 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -27,12 +27,14 @@ #include #include #include +#include #include #include #include const std::function G_TRANSLATION_FUN = nullptr; +UrlDecodeFn* const URL_DECODE = nullptr; FastRandomContext g_insecure_rand_ctx; /** Random context to get unique temp data dirs. Separate from g_insecure_rand_ctx, which can be seeded from a const env var */ diff --git a/src/util/url.h b/src/util/url.h index e9ea2ab765..be9f1c9e8a 100644 --- a/src/util/url.h +++ b/src/util/url.h @@ -7,6 +7,8 @@ #include -std::string urlDecode(const std::string &urlEncoded); +using UrlDecodeFn = std::string(const std::string& url_encoded); +UrlDecodeFn urlDecode; +extern UrlDecodeFn* const URL_DECODE; #endif // BITCOIN_UTIL_URL_H diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5d34e592db..9dd684a94c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -77,9 +77,9 @@ bool HaveKey(const SigningProvider& wallet, const CKey& key) bool GetWalletNameFromJSONRPCRequest(const JSONRPCRequest& request, std::string& wallet_name) { - if (request.URI.substr(0, WALLET_ENDPOINT_BASE.size()) == WALLET_ENDPOINT_BASE) { + if (URL_DECODE && request.URI.substr(0, WALLET_ENDPOINT_BASE.size()) == WALLET_ENDPOINT_BASE) { // wallet endpoint was used - wallet_name = urlDecode(request.URI.substr(WALLET_ENDPOINT_BASE.size())); + wallet_name = URL_DECODE(request.URI.substr(WALLET_ENDPOINT_BASE.size())); return true; } return false; -- cgit v1.2.3