From 69e02e23b1bea97875c97adcdff8b44ffb1c9312 Mon Sep 17 00:00:00 2001 From: Michael Schmoock Date: Wed, 16 Feb 2022 11:32:21 +0100 Subject: [PATCH] cleanups: feeadjuster, drain and summary --- README.md | 2 +- drain/drain.py | 2 +- feeadjuster/feeadjuster.py | 14 ++++++-------- summary/summary.py | 8 ++++---- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f8b0957..833eca5 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Community curated plugins for c-lightning. | [backup][backup] | A simple and reliable backup plugin | | [boltz-channel-creation][boltz] | A c-lightning plugin for Boltz Channel Creation Swaps | | [btcli4j][btcli4j] | A Bitcoin Backend to enable safely the pruning mode, and support also rest APIs. | -| [commando][commando] | Authorize peers to run commands on your node, and running commands on them. | +| [commando][commando] | Authorize peers to run commands on your node, and running commands on them. | | [csvexportpays][csvexportpays] | A plugin that exports all payments to a CSV file | | [currencyrate][currencyrate] | A plugin to convert other currencies to BTC using web requests | | [donations][donations] | A simple donations page to accept donations from the web | diff --git a/drain/drain.py b/drain/drain.py index 330be6a..b9a66d8 100755 --- a/drain/drain.py +++ b/drain/drain.py @@ -293,7 +293,7 @@ def try_for_htlc_fee(plugin, payload, peer_id, amount, chunk, spendable_before): return False # should not happen, but maybe API changes payload['success_msg'].append(f"{amount + fees}msat sent over {len(route)} " f"hops to {payload['command']} {amount}msat " - f"[{chunk + 1}/{payload['chunks']}") + f"[{chunk + 1}/{payload['chunks']}]") # we need to wait for HTLC to resolve, so remaining amounts # can be calculated correctly for the next chunk wait_ours(plugin, payload['scid'], ours) diff --git a/feeadjuster/feeadjuster.py b/feeadjuster/feeadjuster.py index 7f82b5d..994da5c 100755 --- a/feeadjuster/feeadjuster.py +++ b/feeadjuster/feeadjuster.py @@ -66,18 +66,16 @@ def get_ratio_hard(our_percentage): def get_peer_id_for_scid(plugin: Plugin, scid: str): for peer in plugin.peers: for ch in peer['channels']: - if 'short_channel_id' in ch: - if ch['short_channel_id'] == scid: - return peer['id'] + if ch.get('short_channel_id') == scid: + return peer['id'] return None def get_local_channel_for_scid(plugin: Plugin, scid: str): for peer in plugin.peers: for ch in peer['channels']: - if 'short_channel_id' in ch: - if ch['short_channel_id'] == scid: - return ch + if ch.get('short_channel_id') == scid: + return ch return None @@ -236,8 +234,8 @@ def feeadjust(plugin: Plugin, scid: str = None): for peer in plugin.peers: for chan in peer["channels"]: if chan["state"] == "CHANNELD_NORMAL": - _scid = chan["short_channel_id"] - if scid != None and scid != _scid: + _scid = chan.get("short_channel_id") + if scid is not None and scid != _scid: continue plugin.adj_balances[_scid] = { "our": int(chan["to_us_msat"]), diff --git a/summary/summary.py b/summary/summary.py index 419b112..6ff9823 100755 --- a/summary/summary.py +++ b/summary/summary.py @@ -24,7 +24,7 @@ try: except Exception: pass -Channel = namedtuple('Channel', ['total', 'ours', 'theirs', 'pid', 'private', 'connected', 'scid', 'avail', 'base' ,'permil']) +Channel = namedtuple('Channel', ['total', 'ours', 'theirs', 'pid', 'private', 'connected', 'scid', 'avail', 'base', 'permil']) Charset = namedtuple('Charset', ['double_left', 'left', 'bar', 'mid', 'right', 'double_right', 'empty']) if have_utf8: draw = Charset('╟', '├', '─', '┼', '┤', '╢', '║') @@ -216,11 +216,11 @@ def summary(plugin, exclude=''): else: extra += '_' s += '[{}] '.format(extra) - + # append fees s += ' {:5}'.format(c.base.millisatoshis) s += ' {:6} '.format(c.permil) - + # append 24hr availability s += '{:4.0%} '.format(c.avail) @@ -265,7 +265,7 @@ def init_db(plugin, retry_time=4, sleep_time=1): retry += 1 if db is None: - raise Error("db initialization error") + raise RuntimeError("db initialization error") return db