Skip to content

Commit 01a3392

Browse files
committed
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.
1 parent 0660119 commit 01a3392

File tree

7 files changed

+15
-3
lines changed

7 files changed

+15
-3
lines changed

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
@@ -77,9 +77,9 @@ bool HaveKey(const SigningProvider& wallet, const CKey& key)
7777

7878
bool GetWalletNameFromJSONRPCRequest(const JSONRPCRequest& request, std::string& wallet_name)
7979
{
80-
if (request.URI.substr(0, WALLET_ENDPOINT_BASE.size()) == WALLET_ENDPOINT_BASE) {
80+
if (URL_DECODE && request.URI.substr(0, WALLET_ENDPOINT_BASE.size()) == WALLET_ENDPOINT_BASE) {
8181
// wallet endpoint was used
82-
wallet_name = urlDecode(request.URI.substr(WALLET_ENDPOINT_BASE.size()));
82+
wallet_name = URL_DECODE(request.URI.substr(WALLET_ENDPOINT_BASE.size()));
8383
return true;
8484
}
8585
return false;

0 commit comments

Comments
 (0)