diff --git a/contrib/pylightning/lightning/lightning.py b/contrib/pylightning/lightning/lightning.py index 8f2f512de..5d9741420 100644 --- a/contrib/pylightning/lightning/lightning.py +++ b/contrib/pylightning/lightning/lightning.py @@ -284,145 +284,180 @@ class LightningRpc(UnixDomainSocketRpc): def __init__(self, socket_path, executor=None, logger=logging): super().__init__(socket_path, executor, logging, self.LightningJSONEncoder, self.LightningJSONDecoder()) - def getpeer(self, peer_id, level=None): + def close(self, peer_id, force=None, timeout=None): """ - Show peer with {peer_id}, if {level} is set, include {log}s + Close the channel with peer {id}, forcing a unilateral + close if {force} is True, and timing out with {timeout} + seconds. """ payload = { "id": peer_id, - "level": level + "force": force, + "timeout": timeout } - res = self.call("listpeers", payload) - return res.get("peers") and res["peers"][0] or None + return self.call("close", payload) - def listnodes(self, node_id=None): + def connect(self, peer_id, host=None, port=None): """ - Show all nodes in our local network view, filter on node {id} - if provided + Connect to {peer_id} at {host} and {port} """ payload = { - "id": node_id + "id": peer_id, + "host": host, + "port": port } - return self.call("listnodes", payload) + return self.call("connect", payload) - def getroute(self, node_id, msatoshi, riskfactor, cltv=9, fromid=None, fuzzpercent=None, exclude=[], maxhops=20): + def decodepay(self, bolt11, description=None): """ - Show route to {id} for {msatoshi}, using {riskfactor} and optional - {cltv} (default 9). If specified search from {fromid} otherwise use - this node as source. Randomize the route with up to {fuzzpercent} - (0.0 -> 100.0, default 5.0). {exclude} is an optional array of - scid/direction to exclude. Limit the number of hops in the route to - {maxhops}. + Decode {bolt11}, using {description} if necessary """ payload = { - "id": node_id, - "msatoshi": msatoshi, - "riskfactor": riskfactor, - "cltv": cltv, - "fromid": fromid, - "fuzzpercent": fuzzpercent, - "exclude": exclude, - "maxhops": maxhops + "bolt11": bolt11, + "description": description } - return self.call("getroute", payload) + return self.call("decodepay", payload) - def listchannels(self, short_channel_id=None, source=None): + def delexpiredinvoice(self, maxexpirytime=None): """ - Show all known channels, accept optional {short_channel_id} or {source} + Delete all invoices that have expired on or before the given {maxexpirytime} """ payload = { - "short_channel_id": short_channel_id, - "source": source + "maxexpirytime": maxexpirytime } - return self.call("listchannels", payload) + return self.call("delexpiredinvoice", payload) - def invoice(self, msatoshi, label, description, expiry=None, fallbacks=None, preimage=None, exposeprivatechannels=None): + def delinvoice(self, label, status): """ - Create an invoice for {msatoshi} with {label} and {description} with - optional {expiry} seconds (default 1 hour) + Delete unpaid invoice {label} with {status} """ payload = { - "msatoshi": msatoshi, "label": label, - "description": description, - "expiry": expiry, - "fallbacks": fallbacks, - "preimage": preimage, - "exposeprivatechannels": exposeprivatechannels + "status": status } - return self.call("invoice", payload) + return self.call("delinvoice", payload) - def listinvoices(self, label=None): + def dev_crash(self): """ - Show invoice {label} (or all, if no {label)) + Crash lightningd by calling fatal() + """ + return self.call("dev-crash") + + def dev_fail(self, peer_id): + """ + Fail with peer {peer_id} """ payload = { - "label": label + "id": peer_id } - return self.call("listinvoices", payload) + return self.call("dev-fail", payload) - def delinvoice(self, label, status): + def dev_forget_channel(self, peerid, force=False): + """ Forget the channel with id=peerid """ - Delete unpaid invoice {label} with {status} + return self.call( + "dev-forget-channel", + payload={"id": peerid, "force": force} + ) + + def dev_memdump(self): + """ + Show memory objects currently in use + """ + return self.call("dev-memdump") + + def dev_memleak(self): + """ + Show unreferenced memory objects + """ + return self.call("dev-memleak") + + def dev_query_scids(self, id, scids): + """ + Ask peer for a particular set of scids """ payload = { - "label": label, - "status": status + "id": id, + "scids": scids } - return self.call("delinvoice", payload) + return self.call("dev-query-scids", payload) - def delexpiredinvoice(self, maxexpirytime=None): + def dev_reenable_commit(self, peer_id): """ - Delete all invoices that have expired on or before the given {maxexpirytime} + Re-enable the commit timer on peer {id} """ payload = { - "maxexpirytime": maxexpirytime + "id": peer_id } - return self.call("delexpiredinvoice", payload) + return self.call("dev-reenable-commit", payload) - def waitanyinvoice(self, lastpay_index=None): + def dev_rescan_outputs(self): """ - Wait for the next invoice to be paid, after {lastpay_index} - (if supplied) + Synchronize the state of our funds with bitcoind + """ + return self.call("dev-rescan-outputs") + + def dev_rhash(self, secret): + """ + Show SHA256 of {secret} """ payload = { - "lastpay_index": lastpay_index + "secret": secret } - return self.call("waitanyinvoice", payload) + return self.call("dev-rhash", payload) - def waitinvoice(self, label): + def dev_sign_last_tx(self, peer_id): """ - Wait for an incoming payment matching the invoice with {label} + Sign and show the last commitment transaction with peer {id} """ payload = { - "label": label + "id": peer_id } - return self.call("waitinvoice", payload) + return self.call("dev-sign-last-tx", payload) - def decodepay(self, bolt11, description=None): + def disconnect(self, peer_id, force=False): """ - Decode {bolt11}, using {description} if necessary + Disconnect from peer with {peer_id}, optional {force} even if has active channel """ payload = { - "bolt11": bolt11, - "description": description + "id": peer_id, + "force": force, } - return self.call("decodepay", payload) + return self.call("disconnect", payload) - def help(self, command=None): + def feerates(self, style, urgent=None, normal=None, slow=None): """ - Show available commands, or just {command} if supplied. + Supply feerate estimates manually. """ payload = { - "command": command, + "style": style, + "urgent": urgent, + "normal": normal, + "slow": slow } - return self.call("help", payload) + return self.call("feerates", payload) - def stop(self): + def fundchannel(self, node_id, satoshi, feerate=None, announce=True, minconf=None): """ - Shut down the lightningd process + Fund channel with {id} using {satoshi} satoshis + with feerate of {feerate} (uses default feerate if unset). + If {announce} is False, don't send channel announcements. + Only select outputs with {minconf} confirmations """ - return self.call("stop") + payload = { + "id": node_id, + "satoshi": satoshi, + "feerate": feerate, + "announce": announce, + "minconf": minconf, + } + return self.call("fundchannel", payload) + + def getinfo(self): + """ + Show information about this node + """ + return self.call("getinfo") def getlog(self, level=None): """ @@ -433,74 +468,102 @@ class LightningRpc(UnixDomainSocketRpc): } return self.call("getlog", payload) - def dev_rhash(self, secret): + def getpeer(self, peer_id, level=None): """ - Show SHA256 of {secret} + Show peer with {peer_id}, if {level} is set, include {log}s """ payload = { - "secret": secret + "id": peer_id, + "level": level } - return self.call("dev-rhash", payload) + res = self.call("listpeers", payload) + return res.get("peers") and res["peers"][0] or None - def dev_crash(self): + def getroute(self, node_id, msatoshi, riskfactor, cltv=9, fromid=None, fuzzpercent=None, exclude=[], maxhops=20): """ - Crash lightningd by calling fatal() + Show route to {id} for {msatoshi}, using {riskfactor} and optional + {cltv} (default 9). If specified search from {fromid} otherwise use + this node as source. Randomize the route with up to {fuzzpercent} + (0.0 -> 100.0, default 5.0). {exclude} is an optional array of + scid/direction to exclude. Limit the number of hops in the route to + {maxhops}. """ - return self.call("dev-crash") + payload = { + "id": node_id, + "msatoshi": msatoshi, + "riskfactor": riskfactor, + "cltv": cltv, + "fromid": fromid, + "fuzzpercent": fuzzpercent, + "exclude": exclude, + "maxhops": maxhops + } + return self.call("getroute", payload) - def dev_query_scids(self, id, scids): + def help(self, command=None): """ - Ask peer for a particular set of scids + Show available commands, or just {command} if supplied. """ payload = { - "id": id, - "scids": scids + "command": command, } - return self.call("dev-query-scids", payload) + return self.call("help", payload) - def getinfo(self): + def invoice(self, msatoshi, label, description, expiry=None, fallbacks=None, preimage=None, exposeprivatechannels=None): """ - Show information about this node + Create an invoice for {msatoshi} with {label} and {description} with + optional {expiry} seconds (default 1 hour) """ - return self.call("getinfo") + payload = { + "msatoshi": msatoshi, + "label": label, + "description": description, + "expiry": expiry, + "fallbacks": fallbacks, + "preimage": preimage, + "exposeprivatechannels": exposeprivatechannels + } + return self.call("invoice", payload) - def sendpay(self, route, payment_hash, description=None, msatoshi=None): + def listchannels(self, short_channel_id=None, source=None): """ - Send along {route} in return for preimage of {payment_hash} + Show all known channels, accept optional {short_channel_id} or {source} """ payload = { - "route": route, - "payment_hash": payment_hash, - "description": description, - "msatoshi": msatoshi, + "short_channel_id": short_channel_id, + "source": source } - return self.call("sendpay", payload) + return self.call("listchannels", payload) - def waitsendpay(self, payment_hash, timeout=None): + def listforwards(self): + """List all forwarded payments and their information """ - Wait for payment for preimage of {payment_hash} to complete + return self.call("listforwards") + + def listfunds(self): + """ + Show funds available for opening channels + """ + return self.call("listfunds") + + def listinvoices(self, label=None): + """ + Show invoice {label} (or all, if no {label)) """ payload = { - "payment_hash": payment_hash, - "timeout": timeout + "label": label } - return self.call("waitsendpay", payload) + return self.call("listinvoices", payload) - def pay(self, bolt11, msatoshi=None, label=None, riskfactor=None, description=None): + def listnodes(self, node_id=None): """ - Send payment specified by {bolt11} with {msatoshi} - (ignored if {bolt11} has an amount), optional {label} - and {riskfactor} (default 1.0) + Show all nodes in our local network view, filter on node {id} + if provided """ payload = { - "bolt11": bolt11, - "msatoshi": msatoshi, - "label": label, - "riskfactor": riskfactor, - # Deprecated. - "description": description, + "id": node_id } - return self.call("pay", payload) + return self.call("listnodes", payload) def listpayments(self, bolt11=None, payment_hash=None): """ @@ -514,17 +577,6 @@ class LightningRpc(UnixDomainSocketRpc): } return self.call("listpayments", payload) - def connect(self, peer_id, host=None, port=None): - """ - Connect to {peer_id} at {host} and {port} - """ - payload = { - "id": peer_id, - "host": host, - "port": port - } - return self.call("connect", payload) - def listpeers(self, peerid=None, level=None): """ Show current peers, if {level} is set, include {log}s" @@ -535,84 +587,84 @@ class LightningRpc(UnixDomainSocketRpc): } return self.call("listpeers", payload) - def fundchannel(self, node_id, satoshi, feerate=None, announce=True, minconf=None): + def newaddr(self, addresstype=None): + """Get a new address of type {addresstype} of the internal wallet. """ - Fund channel with {id} using {satoshi} satoshis - with feerate of {feerate} (uses default feerate if unset). - If {announce} is False, don't send channel announcements. - Only select outputs with {minconf} confirmations + return self.call("newaddr", {"addresstype": addresstype}) + + def pay(self, bolt11, msatoshi=None, label=None, riskfactor=None, description=None): + """ + Send payment specified by {bolt11} with {msatoshi} + (ignored if {bolt11} has an amount), optional {label} + and {riskfactor} (default 1.0) """ payload = { - "id": node_id, - "satoshi": satoshi, - "feerate": feerate, - "announce": announce, - "minconf": minconf, + "bolt11": bolt11, + "msatoshi": msatoshi, + "label": label, + "riskfactor": riskfactor, + # Deprecated. + "description": description, } - return self.call("fundchannel", payload) + return self.call("pay", payload) - def close(self, peer_id, force=None, timeout=None): + def ping(self, peer_id, length=128, pongbytes=128): """ - Close the channel with peer {id}, forcing a unilateral - close if {force} is True, and timing out with {timeout} - seconds. + Send {peer_id} a ping of length {len} asking for {pongbytes}" """ payload = { "id": peer_id, - "force": force, - "timeout": timeout + "len": length, + "pongbytes": pongbytes } - return self.call("close", payload) + return self.call("ping", payload) - def dev_sign_last_tx(self, peer_id): + def sendpay(self, route, payment_hash, description=None, msatoshi=None): """ - Sign and show the last commitment transaction with peer {id} + Send along {route} in return for preimage of {payment_hash} """ payload = { - "id": peer_id + "route": route, + "payment_hash": payment_hash, + "description": description, + "msatoshi": msatoshi, } - return self.call("dev-sign-last-tx", payload) + return self.call("sendpay", payload) - def dev_fail(self, peer_id): + def stop(self): """ - Fail with peer {peer_id} + Shut down the lightningd process """ - payload = { - "id": peer_id - } - return self.call("dev-fail", payload) + return self.call("stop") - def dev_reenable_commit(self, peer_id): + def waitanyinvoice(self, lastpay_index=None): """ - Re-enable the commit timer on peer {id} + Wait for the next invoice to be paid, after {lastpay_index} + (if supplied) """ payload = { - "id": peer_id + "lastpay_index": lastpay_index } - return self.call("dev-reenable-commit", payload) + return self.call("waitanyinvoice", payload) - def ping(self, peer_id, length=128, pongbytes=128): + def waitinvoice(self, label): """ - Send {peer_id} a ping of length {len} asking for {pongbytes}" + Wait for an incoming payment matching the invoice with {label} """ payload = { - "id": peer_id, - "len": length, - "pongbytes": pongbytes + "label": label } - return self.call("ping", payload) - - def dev_memdump(self): - """ - Show memory objects currently in use - """ - return self.call("dev-memdump") + return self.call("waitinvoice", payload) - def dev_memleak(self): + def waitsendpay(self, payment_hash, timeout=None): """ - Show unreferenced memory objects + Wait for payment for preimage of {payment_hash} to complete """ - return self.call("dev-memleak") + payload = { + "payment_hash": payment_hash, + "timeout": timeout + } + return self.call("waitsendpay", payload) def withdraw(self, destination, satoshi, feerate=None, minconf=None): """ @@ -627,55 +679,3 @@ class LightningRpc(UnixDomainSocketRpc): "minconf": minconf, } return self.call("withdraw", payload) - - def newaddr(self, addresstype=None): - """Get a new address of type {addresstype} of the internal wallet. - """ - return self.call("newaddr", {"addresstype": addresstype}) - - def listfunds(self): - """ - Show funds available for opening channels - """ - return self.call("listfunds") - - def listforwards(self): - """List all forwarded payments and their information - """ - return self.call("listforwards") - - def dev_rescan_outputs(self): - """ - Synchronize the state of our funds with bitcoind - """ - return self.call("dev-rescan-outputs") - - def dev_forget_channel(self, peerid, force=False): - """ Forget the channel with id=peerid - """ - return self.call( - "dev-forget-channel", - payload={"id": peerid, "force": force} - ) - - def disconnect(self, peer_id, force=False): - """ - Disconnect from peer with {peer_id}, optional {force} even if has active channel - """ - payload = { - "id": peer_id, - "force": force, - } - return self.call("disconnect", payload) - - def feerates(self, style, urgent=None, normal=None, slow=None): - """ - Supply feerate estimates manually. - """ - payload = { - "style": style, - "urgent": urgent, - "normal": normal, - "slow": slow - } - return self.call("feerates", payload)