contrib/pyln-client: construct JSON ID correctly.

They can set their name explicitly, but if they don't we extract it from argv[0].

We also set it around callbacks, so it will be expanded by default.

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 d360075d22
commit f1f2c1322d
5 changed files with 43 additions and 11 deletions

View File

@@ -607,17 +607,25 @@ class Plugin(object):
def _exec_func(self, func: Callable[..., Any],
request: Request) -> JSONType:
# By default, any RPC calls this makes will have JSON id prefixed by incoming id.
if self.rpc:
self.rpc.cmdprefix = request.id
params = request.params
if isinstance(params, list):
ba = self._bind_pos(func, params, request)
return func(*ba.args, **ba.kwargs)
ret = func(*ba.args, **ba.kwargs)
elif isinstance(params, dict):
ba = self._bind_kwargs(func, params, request)
return func(*ba.args, **ba.kwargs)
ret = func(*ba.args, **ba.kwargs)
else:
if self.rpc:
self.rpc.cmdprefix = None
raise TypeError(
"Parameters to function call must be either a dict or a list."
)
if self.rpc:
self.rpc.cmdprefix = None
return ret
def _dispatch_request(self, request: Request) -> None:
name = request.method