Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13711458
D11560.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Subscribers
None
D11560.id.diff
View Options
diff --git a/src/httprpc.cpp b/src/httprpc.cpp
--- a/src/httprpc.cpp
+++ b/src/httprpc.cpp
@@ -305,7 +305,8 @@
return false;
}
- JSONRPCRequest jreq(context);
+ JSONRPCRequest jreq;
+ jreq.context = context;
jreq.peerAddr = req->GetPeer().ToString();
if (!RPCAuthorized(authHeader.second, jreq.authUser)) {
LogPrintf("ThreadRPCServer incorrect password attempt from %s\n",
diff --git a/src/init.cpp b/src/init.cpp
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1523,7 +1523,7 @@
return false;
}
if (args.GetBoolArg("-rest", DEFAULT_REST_ENABLE)) {
- StartREST(httpRPCRequestProcessor.context);
+ StartREST(&node);
}
StartHTTPServer();
diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp
--- a/src/interfaces/node.cpp
+++ b/src/interfaces/node.cpp
@@ -252,7 +252,8 @@
UniValue executeRpc(const Config &config, const std::string &command,
const UniValue ¶ms,
const std::string &uri) override {
- JSONRPCRequest req(m_context_ref);
+ JSONRPCRequest req;
+ req.context = m_context;
req.params = params;
req.strMethod = command;
req.URI = uri;
@@ -332,16 +333,8 @@
}));
}
NodeContext *context() override { return m_context; }
- void setContext(NodeContext *context) override {
- m_context = context;
- if (context) {
- m_context_ref = context;
- } else {
- m_context_ref.reset();
- }
- }
+ void setContext(NodeContext *context) override { m_context = context; }
NodeContext *m_context{nullptr};
- std::any m_context_ref{m_context};
};
} // namespace
diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp
--- a/src/interfaces/wallet.cpp
+++ b/src/interfaces/wallet.cpp
@@ -478,8 +478,10 @@
[this, &command](const Config &config,
const JSONRPCRequest &request,
UniValue &result, bool last_handler) {
- return command.actor(config, {request, &m_context},
- result, last_handler);
+ JSONRPCRequest wallet_request = request;
+ wallet_request.context = &m_context;
+ return command.actor(config, wallet_request, result,
+ last_handler);
},
command.argNames, command.unique_id);
m_rpc_handlers.emplace_back(
diff --git a/src/rest.cpp b/src/rest.cpp
--- a/src/rest.cpp
+++ b/src/rest.cpp
@@ -345,7 +345,8 @@
switch (rf) {
case RetFormat::JSON: {
- JSONRPCRequest jsonRequest(context);
+ JSONRPCRequest jsonRequest;
+ jsonRequest.context = context;
jsonRequest.params = UniValue(UniValue::VARR);
UniValue chainInfoObject =
getblockchaininfo().HandleRequest(config, jsonRequest);
@@ -787,8 +788,8 @@
void StartREST(const std::any &context) {
for (const auto &up : uri_prefixes) {
- auto handler = [&context, up](Config &config, HTTPRequest *req,
- const std::string &prefix) {
+ auto handler = [context, up](Config &config, HTTPRequest *req,
+ const std::string &prefix) {
return up.handler(config, context, req, prefix);
};
RegisterHTTPHandler(up.prefix, false, handler);
diff --git a/src/rpc/request.h b/src/rpc/request.h
--- a/src/rpc/request.h
+++ b/src/rpc/request.h
@@ -36,18 +36,7 @@
std::string URI;
std::string authUser;
std::string peerAddr;
- const std::any &context;
-
- explicit JSONRPCRequest(const std::any &contextIn)
- : id(NullUniValue), params(NullUniValue), context(contextIn) {}
-
- //! Initializes request information from another request object and the
- //! given context. The implementation should be updated if any members are
- //! added or removed above.
- JSONRPCRequest(const JSONRPCRequest &other, const std::any &contextIn)
- : id(other.id), strMethod(other.strMethod), params(other.params),
- mode(other.mode), URI(other.URI), authUser(other.authUser),
- peerAddr(other.peerAddr), context(contextIn) {}
+ std::any context;
void parse(const UniValue &valRequest);
};
diff --git a/src/test/rpc_server_tests.cpp b/src/test/rpc_server_tests.cpp
--- a/src/test/rpc_server_tests.cpp
+++ b/src/test/rpc_server_tests.cpp
@@ -48,15 +48,16 @@
args.pushKV("arg1", "value1");
// Registered commands execute and return values correctly
- std::any context{&m_node};
- JSONRPCRequest request(context);
+ JSONRPCRequest request;
+ request.context = &m_node;
request.strMethod = commandName;
request.params = args;
UniValue output = rpcServer.ExecuteCommand(config, request);
BOOST_CHECK_EQUAL(output.get_str(), "testing1");
// Not-registered commands throw an exception as expected
- JSONRPCRequest badCommandRequest(context);
+ JSONRPCRequest badCommandRequest;
+ badCommandRequest.context = &m_node;
badCommandRequest.strMethod = "this-command-does-not-exist";
BOOST_CHECK_EXCEPTION(rpcServer.ExecuteCommand(config, badCommandRequest),
UniValue, isRpcMethodNotFound);
@@ -88,8 +89,8 @@
args.pushKV("arg2", "value2");
// Registered commands execute and return values correctly
- std::any context{&m_node};
- JSONRPCRequest request(context);
+ JSONRPCRequest request;
+ request.context = &m_node;
request.strMethod = commandName;
request.params = args;
UniValue output = rpcServer.ExecuteCommand(config, request);
diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp
--- a/src/test/rpc_tests.cpp
+++ b/src/test/rpc_tests.cpp
@@ -21,13 +21,19 @@
#include <any>
-UniValue CallRPC(const std::string &args, const std::any &context) {
+class RPCTestingSetup : public TestingSetup {
+public:
+ UniValue CallRPC(const std::string &args);
+};
+
+UniValue RPCTestingSetup::CallRPC(const std::string &args) {
std::vector<std::string> vArgs;
boost::split(vArgs, args, boost::is_any_of(" \t"));
std::string strMethod = vArgs[0];
vArgs.erase(vArgs.begin());
GlobalConfig config;
- JSONRPCRequest request(context);
+ JSONRPCRequest request;
+ request.context = &m_node;
request.strMethod = strMethod;
request.params = RPCConvertValues(strMethod, vArgs);
if (RPCIsInWarmup(nullptr)) {
@@ -41,14 +47,6 @@
}
}
-class RPCTestingSetup : public TestingSetup {
-public:
- UniValue CallRPC(const std::string &args) {
- const std::any context{&m_node};
- return ::CallRPC(args, context);
- }
-};
-
BOOST_FIXTURE_TEST_SUITE(rpc_tests, RPCTestingSetup)
BOOST_AUTO_TEST_CASE(rpc_rawparams) {
diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp
--- a/src/wallet/test/wallet_tests.cpp
+++ b/src/wallet/test/wallet_tests.cpp
@@ -229,8 +229,7 @@
newTip->GetBlockTimeMax() + TIMESTAMP_WINDOW + 1);
key.pushKV("internal", UniValue(true));
keys.push_back(key);
- std::any context;
- JSONRPCRequest request(context);
+ JSONRPCRequest request;
request.params.setArray();
request.params.push_back(keys);
@@ -298,8 +297,7 @@
::ChainActive().Height(),
::ChainActive().Tip()->GetBlockHash());
}
- std::any context;
- JSONRPCRequest request(context);
+ JSONRPCRequest request;
request.params.setArray();
request.params.push_back(backup_file);
::dumpwallet().HandleRequest(GetConfig(), request);
@@ -314,8 +312,7 @@
LOCK(wallet->cs_wallet);
wallet->SetupLegacyScriptPubKeyMan();
- std::any context;
- JSONRPCRequest request(context);
+ JSONRPCRequest request;
request.params.setArray();
request.params.push_back(backup_file);
AddWallet(wallet);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Apr 26, 12:06 (2 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5573510
Default Alt Text
D11560.id.diff (8 KB)
Attached To
D11560: Drop JSONRPCRequest constructors
Event Timeline
Log In to Comment