commit 0b295cb72e0029c6e97e36a614c12cbf5b2c2989
parent a6430df0a41bedbeaf0593dabcd655d248ea219b
Author: parazyd <parazyd@dyne.org>
Date: Fri, 16 Apr 2021 02:28:20 +0200
Return null id on JSON-RPC errors.
Also return invalidrequest where applicable.
Diffstat:
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/obelisk/protocol.py b/obelisk/protocol.py
@@ -164,9 +164,9 @@ class ElectrumProtocol(asyncio.Protocol): # pylint: disable=R0904,R0902
writer.write(json.dumps(response).encode("utf-8") + b"\n")
await writer.drain()
- async def _send_error(self, writer, error, nid):
+ async def _send_error(self, writer, error):
"""Send JSON-RPC error to given writer"""
- response = {"jsonrpc": "2.0", "error": error, "id": nid}
+ response = {"jsonrpc": "2.0", "error": error, "id": None}
self.log.debug("<= %s", response)
writer.write(json.dumps(response).encode("utf-8") + b"\n")
await writer.drain()
@@ -174,17 +174,19 @@ class ElectrumProtocol(asyncio.Protocol): # pylint: disable=R0904,R0902
async def _send_reply(self, writer, resp, query):
"""Wrap function for sending replies"""
if "error" in resp:
- return await self._send_error(writer, resp["error"], query["id"])
+ return await self._send_error(writer, resp["error"])
return await self._send_response(writer, resp["result"], query["id"])
async def handle_query(self, writer, query): # pylint: disable=R0915,R0912,R0911
"""Electrum protocol method handler mapper"""
if "method" not in query:
self.log.debug("No 'method' in query: %s", query)
- return
+ return await self._send_reply(writer, JsonRPCError.invalidrequest(),
+ None)
if "id" not in query:
self.log.debug("No 'id' in query: %s", query)
- return
+ return await self._send_reply(writer, JsonRPCError.invalidrequest(),
+ None)
method = query["method"]
func = self.methodmap.get(method)