mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-08 16:44:22 +01:00
contrib/pyln-testing: pass through id correctly.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -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''
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user