mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-10 01:24:30 +01:00
pylightning: Filter out None arguments in JSON-RPC calls
Passing them in doesn't hurt, but better to avoid ambivalences. Suggested-by: @graphite Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
committed by
Rusty Russell
parent
db5c0aa6c1
commit
e48a97ffd4
@@ -46,11 +46,16 @@ class UnixDomainSocketRpc(object):
|
||||
def call(self, method, payload=None):
|
||||
self.logger.debug("Calling %s with payload %r", method, payload)
|
||||
|
||||
if payload is None:
|
||||
payload = {}
|
||||
# Filter out arguments that are None
|
||||
payload = {k: v for k, v in payload.items() if v is not None}
|
||||
|
||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
sock.connect(self.socket_path)
|
||||
self._writeobj(sock, {
|
||||
"method": method,
|
||||
"params": payload or {},
|
||||
"params": payload,
|
||||
"id": 0
|
||||
})
|
||||
resp = self._readobj(sock)
|
||||
@@ -58,7 +63,7 @@ class UnixDomainSocketRpc(object):
|
||||
|
||||
self.logger.debug("Received response for %s call: %r", method, resp)
|
||||
if "error" in resp:
|
||||
raise ValueError(
|
||||
raise ValueError(
|
||||
"RPC call failed: {}, method: {}, payload: {}".format(
|
||||
resp["error"],
|
||||
method,
|
||||
|
||||
Reference in New Issue
Block a user