contrib/pyln-testing: pass through id correctly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2022-09-13 06:49:12 +09:30
parent f1f2c1322d
commit fdc59dc94a
2 changed files with 13 additions and 8 deletions

View File

@@ -329,6 +329,15 @@ class UnixDomainSocketRpc(object):
return self.call(name, payload=kwargs)
return wrapper
def get_json_id(self, method, cmdprefix):
"""Get a nicely formatted, CLN-compliant JSON ID"""
this_id = "{}:{}#{}".format(self.caller_name, method, str(self.next_id))
if cmdprefix is None:
cmdprefix = self.cmdprefix
if cmdprefix:
this_id = cmdprefix + '/' + this_id
return this_id
def call(self, method, payload=None, cmdprefix=None):
"""Generic call API: you can set cmdprefix here, or set self.cmdprefix
before the call is made.
@@ -342,15 +351,11 @@ class UnixDomainSocketRpc(object):
if isinstance(payload, dict):
payload = {k: v for k, v in payload.items() if v is not None}
this_id = "{}:{}#{}".format(self.caller_name, method, str(self.next_id))
this_id = self.get_json_id(method, cmdprefix)
self.next_id += 1
# FIXME: we open a new socket for every readobj call...
sock = UnixSocket(self.socket_path)
if cmdprefix is None:
cmdprefix = self.cmdprefix
if cmdprefix:
this_id = cmdprefix + '/' + this_id
buf = b''

View File

@@ -661,8 +661,8 @@ class PrettyPrintingLightningRpc(LightningRpc):
self.jsonschemas = jsonschemas
self.check_request_schemas = True
def call(self, method, payload=None):
id = self.next_id
def call(self, method, payload=None, cmdprefix=None):
id = self.get_json_id(method, cmdprefix)
schemas = self.jsonschemas.get(method)
self.logger.debug(json.dumps({
"id": id,
@@ -681,7 +681,7 @@ class PrettyPrintingLightningRpc(LightningRpc):
testpayload[k] = v
schemas[0].validate(testpayload)
res = LightningRpc.call(self, method, payload)
res = LightningRpc.call(self, method, payload, cmdprefix)
self.logger.debug(json.dumps({
"id": id,
"result": res