pyln: handle (ignore) notifications, and add notify_msg to send them.

We also sanity check that response id matches our request.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: pyln: pyln.client handles and can send progress notifications.
This commit is contained in:
Rusty Russell
2020-10-12 16:03:50 +10:30
parent 572c849873
commit 806f208295
2 changed files with 32 additions and 3 deletions

View File

@@ -316,17 +316,26 @@ class UnixDomainSocketRpc(object):
# FIXME: we open a new socket for every readobj call...
sock = UnixSocket(self.socket_path)
this_id = self.next_id
self._writeobj(sock, {
"jsonrpc": "2.0",
"method": method,
"params": payload,
"id": self.next_id,
"id": this_id,
})
self.next_id += 1
resp, _ = self._readobj(sock)
sock.close()
buf = b''
while True:
resp, buf = self._readobj(sock, buf)
# FIXME: We should offer a callback for notifications.
if 'method' not in resp or 'id' in resp:
break
self.logger.debug("Received response for %s call: %r", method, resp)
if 'id' in resp and resp['id'] != this_id:
raise ValueError("Malformed response, id is not {}: {}.".format(this_id, resp))
sock.close()
if not isinstance(resp, dict):
raise ValueError("Malformed response, response is not a dictionary %s." % resp)
elif "error" in resp: