mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
pytest: Separating new lightningd and legacy lightningd RPC client
We intend to ultimately no longer use the legacy `daemon/lightningd` and instead use `lightningd/lightningd`, so I grouped the new RPC and the legacy RPC and implemented stubs for the new daemon.
This commit is contained in:
parent
091c2fc8f5
commit
5f61b3a272
@ -1 +1 @@
|
|||||||
from .lightning import LightningRpc
|
from .lightning import LightningRpc, LegacyLightningRpc
|
||||||
|
@ -7,28 +7,12 @@ import socket
|
|||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
class LightningRpc(object):
|
class UnixDomainSocketRpc(object):
|
||||||
"""RPC client for the `lightningd` daemon.
|
|
||||||
|
|
||||||
This RPC client connects to the `lightningd` daemon through a unix
|
|
||||||
domain socket and passes calls through. Since some of the calls
|
|
||||||
are blocking, the corresponding python methods include an `async`
|
|
||||||
keyword argument. If `async` is set to true then the method
|
|
||||||
returns a future immediately, instead of blocking indefinitely.
|
|
||||||
|
|
||||||
This implementation is thread safe in that it locks the socket
|
|
||||||
between calls, but it does not (yet) support concurrent calls.
|
|
||||||
"""
|
|
||||||
def __init__(self, socket_path, executor=None):
|
def __init__(self, socket_path, executor=None):
|
||||||
self.socket_path = socket_path
|
self.socket_path = socket_path
|
||||||
self.socket = None
|
|
||||||
self.buff = b''
|
|
||||||
self.decoder = json.JSONDecoder()
|
self.decoder = json.JSONDecoder()
|
||||||
self.executor = executor
|
self.executor = executor
|
||||||
|
|
||||||
def connect_rpc(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _writeobj(self, sock, obj):
|
def _writeobj(self, sock, obj):
|
||||||
s = json.dumps(obj)
|
s = json.dumps(obj)
|
||||||
sock.sendall(bytearray(s, 'UTF-8'))
|
sock.sendall(bytearray(s, 'UTF-8'))
|
||||||
@ -66,6 +50,58 @@ class LightningRpc(object):
|
|||||||
raise ValueError("Malformed response, 'result' missing.")
|
raise ValueError("Malformed response, 'result' missing.")
|
||||||
return resp['result']
|
return resp['result']
|
||||||
|
|
||||||
|
|
||||||
|
class LightningRpc(UnixDomainSocketRpc):
|
||||||
|
"""RPC client for the `lightningd` daemon.
|
||||||
|
|
||||||
|
This RPC client connects to the `lightningd` daemon through a unix
|
||||||
|
domain socket and passes calls through. Since some of the calls
|
||||||
|
are blocking, the corresponding python methods include an `async`
|
||||||
|
keyword argument. If `async` is set to true then the method
|
||||||
|
returns a future immediately, instead of blocking indefinitely.
|
||||||
|
|
||||||
|
This implementation is thread safe in that it locks the socket
|
||||||
|
between calls, but it does not (yet) support concurrent calls.
|
||||||
|
"""
|
||||||
|
def connect(self, hostname, port, remote_id):
|
||||||
|
return self._call("connect", [hostname, port, remote_id])
|
||||||
|
|
||||||
|
def getpeers(self):
|
||||||
|
return self._call("getpeers", [])
|
||||||
|
|
||||||
|
def getpeer(self, peer_id):
|
||||||
|
"""Get info about a specific peer.
|
||||||
|
"""
|
||||||
|
peers = self.getpeers()['peers']
|
||||||
|
for p in peers:
|
||||||
|
if p['peerid'] == peer_id:
|
||||||
|
return p
|
||||||
|
return None
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
return self._call("stop", [])
|
||||||
|
|
||||||
|
def getlog(self, level=None):
|
||||||
|
args = []
|
||||||
|
if level is not None:
|
||||||
|
args.append(level)
|
||||||
|
return self._call("getlog", args)
|
||||||
|
|
||||||
|
def getinfo(self):
|
||||||
|
return self._call("getinfo", [])
|
||||||
|
|
||||||
|
def dev_add_route(self, src, dst, base, var, delay, minblocks):
|
||||||
|
"""Add route from {src} to {dst}, {base} rate in msatoshi, {var} rate in msatoshi, {delay} blocks delay and {minblocks} minimum timeout
|
||||||
|
"""
|
||||||
|
return self._call("dev-add-route", [src, dst, base, var, delay, minblocks])
|
||||||
|
|
||||||
|
def getchannels(self):
|
||||||
|
return self._call("getchannels", [])
|
||||||
|
|
||||||
|
def getnodes(self):
|
||||||
|
return self._call("getnodes", [])
|
||||||
|
|
||||||
|
class LegacyLightningRpc(UnixDomainSocketRpc):
|
||||||
def getchannels(self):
|
def getchannels(self):
|
||||||
"""List all known channels.
|
"""List all known channels.
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user