mirror of
https://github.com/prusnak/suez.git
synced 2026-08-13 12:33:13 +02:00
reformat sources
This commit is contained in:
parent
9aa4020d56
commit
e402edbddb
3 changed files with 52 additions and 35 deletions
|
|
@ -6,27 +6,35 @@ from lndclient import LndClient
|
|||
|
||||
class LndCliClient(LndClient):
|
||||
def getinfo(self):
|
||||
return self._run('getinfo')
|
||||
return self._run("getinfo")
|
||||
|
||||
def listchannels(self):
|
||||
return self._run('listchannels')
|
||||
return self._run("listchannels")
|
||||
|
||||
def getchaninfo(self, chan_id):
|
||||
return self._run('getchaninfo', chan_id)
|
||||
return self._run("getchaninfo", chan_id)
|
||||
|
||||
def getnodeinfo(self, node_id):
|
||||
return self._run('getnodeinfo', node_id)
|
||||
return self._run("getnodeinfo", node_id)
|
||||
|
||||
def fwd_events(self):
|
||||
return self._run('fwdinghistory', "--max_events", "50000", "--start_time", "-30d")
|
||||
return self._run(
|
||||
"fwdinghistory", "--max_events", "50000", "--start_time", "-30d"
|
||||
)
|
||||
|
||||
def updatechanpolicy(self, channel, policy):
|
||||
base_fee, fee_rate, time_lock_delta = policy.calculate(channel)
|
||||
return self._run('updatechanpolicy',
|
||||
"--base_fee_msat", str(base_fee),
|
||||
"--fee_rate", "%0.8f" % fee_rate,
|
||||
"--time_lock_delta", str(time_lock_delta),
|
||||
"--chan_point", channel.channel_point)
|
||||
return self._run(
|
||||
"updatechanpolicy",
|
||||
"--base_fee_msat",
|
||||
str(base_fee),
|
||||
"--fee_rate",
|
||||
"%0.8f" % fee_rate,
|
||||
"--time_lock_delta",
|
||||
str(time_lock_delta),
|
||||
"--chan_point",
|
||||
channel.channel_point,
|
||||
)
|
||||
|
||||
def _run(self, *args):
|
||||
if self.client_args:
|
||||
|
|
|
|||
|
|
@ -113,4 +113,3 @@ class LndClient(abc.ABC):
|
|||
def apply_fee_policy(self, policy):
|
||||
for c in self.channels.values():
|
||||
self.updatechanpolicy(c, policy)
|
||||
|
||||
|
|
|
|||
|
|
@ -12,55 +12,65 @@ class LndRestClient(LndClient):
|
|||
def __init__(self, client_args):
|
||||
args = dict(a.split("=", 1) for a in client_args)
|
||||
|
||||
self.rpcserver = args['rpcserver']
|
||||
self.macaroonpath = args['macaroonpath']
|
||||
self.tlscertpath = args['tlscertpath']
|
||||
self.rpcserver = args["rpcserver"]
|
||||
self.macaroonpath = args["macaroonpath"]
|
||||
self.tlscertpath = args["tlscertpath"]
|
||||
|
||||
self.api_base = posixpath.join(self.rpcserver, 'v1')
|
||||
self.api_base = posixpath.join(self.rpcserver, "v1")
|
||||
|
||||
with open(self.macaroonpath, 'rb') as f:
|
||||
macaroon = codecs.encode(f.read(), 'hex')
|
||||
self.headers = {'Grpc-Metadata-macaroon': macaroon}
|
||||
with open(self.macaroonpath, "rb") as f:
|
||||
macaroon = codecs.encode(f.read(), "hex")
|
||||
self.headers = {"Grpc-Metadata-macaroon": macaroon}
|
||||
|
||||
super().__init__(client_args)
|
||||
|
||||
def getinfo(self):
|
||||
return self._do_get('getinfo')
|
||||
return self._do_get("getinfo")
|
||||
|
||||
def listchannels(self):
|
||||
return self._do_get('channels')
|
||||
return self._do_get("channels")
|
||||
|
||||
def getchaninfo(self, chan_id):
|
||||
return self._do_get('graph/edge', chan_id)
|
||||
return self._do_get("graph/edge", chan_id)
|
||||
|
||||
def getnodeinfo(self, node_id):
|
||||
return self._do_get('graph/node', node_id)
|
||||
return self._do_get("graph/node", node_id)
|
||||
|
||||
def fwd_events(self):
|
||||
start_date = datetime.now() - timedelta(days=30)
|
||||
return self._do_post('switch',
|
||||
return self._do_post(
|
||||
"switch",
|
||||
num_max_events=50000,
|
||||
start_time=str(int(time.mktime(start_date.timetuple()))))
|
||||
start_time=str(int(time.mktime(start_date.timetuple()))),
|
||||
)
|
||||
|
||||
def updatechanpolicy(self, channel, policy):
|
||||
base_fee, fee_rate, time_lock_delta = policy.calculate(channel)
|
||||
funding_txid_str, output_index = channel.channel_point.split(":")
|
||||
return self._do_post('chanpolicy',
|
||||
chan_point={'funding_txid_str': funding_txid_str,
|
||||
'output_index': int(output_index)},
|
||||
return self._do_post(
|
||||
"chanpolicy",
|
||||
chan_point={
|
||||
"funding_txid_str": funding_txid_str,
|
||||
"output_index": int(output_index),
|
||||
},
|
||||
base_fee_msat=str(base_fee),
|
||||
fee_rate=fee_rate,
|
||||
time_lock_delta=time_lock_delta)
|
||||
time_lock_delta=time_lock_delta,
|
||||
)
|
||||
|
||||
def _do_get(self, method, *args):
|
||||
response = requests.get(posixpath.join(self.api_base, method, *args),
|
||||
headers=self.headers,
|
||||
verify=self.tlscertpath)
|
||||
response = requests.get(
|
||||
posixpath.join(self.api_base, method, *args),
|
||||
headers=self.headers,
|
||||
verify=self.tlscertpath,
|
||||
)
|
||||
return json.loads(response.text)
|
||||
|
||||
def _do_post(self, method, **data):
|
||||
response = requests.post(posixpath.join(self.api_base, method),
|
||||
headers=self.headers,
|
||||
data=json.dumps(data),
|
||||
verify=self.tlscertpath)
|
||||
response = requests.post(
|
||||
posixpath.join(self.api_base, method),
|
||||
headers=self.headers,
|
||||
data=json.dumps(data),
|
||||
verify=self.tlscertpath,
|
||||
)
|
||||
return json.loads(response.text)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue