diff options
author | Matthew Zipkin <pinheadmz@gmail.com> | 2023-02-27 13:03:45 -0500 |
---|---|---|
committer | Ryan Ofsky <ryan@ofsky.org> | 2024-03-07 19:13:27 -0500 |
commit | a64a2b77e09bff784a2635ba19ff4aa6582bb5a5 (patch) | |
tree | 445a07f3a8882d1650351ab3bf1fb403bced68cf /src/rpc/server.cpp | |
parent | df6e3756d6feaf1856e7886820b70874209fd90b (diff) | |
download | bitcoin-a64a2b77e09bff784a2635ba19ff4aa6582bb5a5.tar.xz |
rpc: refactor single/batch requests
Simplify the request handling flow so that errors and results only
come from JSONRPCExec()
Diffstat (limited to 'src/rpc/server.cpp')
-rw-r--r-- | src/rpc/server.cpp | 33 |
1 files changed, 5 insertions, 28 deletions
diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index fd18a7f9ec..f199914095 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -358,36 +358,13 @@ bool IsDeprecatedRPCEnabled(const std::string& method) return find(enabled_methods.begin(), enabled_methods.end(), method) != enabled_methods.end(); } -static UniValue JSONRPCExecOne(JSONRPCRequest jreq, const UniValue& req) +UniValue JSONRPCExec(const JSONRPCRequest& jreq) { - UniValue rpc_result(UniValue::VOBJ); + // Might throw exception. Single requests will throw and send HTTP error codes + // but inside a batch, we just include the error object and return HTTP 200 + UniValue result = tableRPC.execute(jreq); - try { - jreq.parse(req); - - UniValue result = tableRPC.execute(jreq); - rpc_result = JSONRPCReplyObj(std::move(result), NullUniValue, jreq.id); - } - catch (UniValue& e) - { - rpc_result = JSONRPCReplyObj(NullUniValue, std::move(e), jreq.id); - } - catch (const std::exception& e) - { - rpc_result = JSONRPCReplyObj(NullUniValue, - JSONRPCError(RPC_PARSE_ERROR, e.what()), jreq.id); - } - - return rpc_result; -} - -std::string JSONRPCExecBatch(const JSONRPCRequest& jreq, const UniValue& vReq) -{ - UniValue ret(UniValue::VARR); - for (unsigned int reqIdx = 0; reqIdx < vReq.size(); reqIdx++) - ret.push_back(JSONRPCExecOne(jreq, vReq[reqIdx])); - - return ret.write() + "\n"; + return JSONRPCReplyObj(std::move(result), NullUniValue, jreq.id); } /** |