Skip to content

Commit

Permalink
contrib/pyln-testing: pass through id correctly.
Browse files Browse the repository at this point in the history
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Sep 16, 2022
1 parent f1f2c13 commit fdc59dc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
15 changes: 10 additions & 5 deletions contrib/pyln-client/pyln/client/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,15 @@ def wrapper(*args, **kwargs):
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.
Expand All @@ -342,15 +351,11 @@ def call(self, method, payload=None, cmdprefix=None):
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''

Expand Down
6 changes: 3 additions & 3 deletions contrib/pyln-testing/pyln/testing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,8 @@ def __init__(self, socket_path, executor=None, logger=logging,
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,
Expand All @@ -681,7 +681,7 @@ def call(self, method, payload=None):
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
Expand Down

0 comments on commit fdc59dc

Please sign in to comment.