Browse Source

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>
ppa-0.6.1
Christian Decker 7 years ago
committed by Rusty Russell
parent
commit
e48a97ffd4
  1. 9
      contrib/pylightning/lightning/lightning.py

9
contrib/pylightning/lightning/lightning.py

@ -46,11 +46,16 @@ class UnixDomainSocketRpc(object):
def call(self, method, payload=None): def call(self, method, payload=None):
self.logger.debug("Calling %s with payload %r", method, payload) 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 = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect(self.socket_path) sock.connect(self.socket_path)
self._writeobj(sock, { self._writeobj(sock, {
"method": method, "method": method,
"params": payload or {}, "params": payload,
"id": 0 "id": 0
}) })
resp = self._readobj(sock) resp = self._readobj(sock)
@ -58,7 +63,7 @@ class UnixDomainSocketRpc(object):
self.logger.debug("Received response for %s call: %r", method, resp) self.logger.debug("Received response for %s call: %r", method, resp)
if "error" in resp: if "error" in resp:
raise ValueError( raise ValueError(
"RPC call failed: {}, method: {}, payload: {}".format( "RPC call failed: {}, method: {}, payload: {}".format(
resp["error"], resp["error"],
method, method,

Loading…
Cancel
Save