From eeee55b19dca180795ebbca03870f02b4f8ef7c5 Mon Sep 17 00:00:00 2001 From: StijnBTC Date: Fri, 30 Jul 2021 14:48:00 +0200 Subject: [PATCH] Fee output added to overview when using -f flag --- output.py | 9 +++++++-- ringtools.py | 24 ++++++++++++++++++++---- status.py | 13 ++++++------- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/output.py b/output.py index 408477e..7d2f548 100644 --- a/output.py +++ b/output.py @@ -2,6 +2,8 @@ import os import sys from yachalk import chalk +ALIAS_LENGTH = 32 + class Output: def __init__(self, lnd): @@ -26,8 +28,11 @@ def format_error(error): return chalk.red(error) -def format_channel(channel_id, node1_alias, node2_alias, chanDisabled): - text = f'{channel_id:<18} {format_alias(node1_alias):<32} {format_alias(node2_alias):<32}' +def format_channel(channel, node1_alias, node2_alias, chanDisabled, show_fees): + text = f'{channel.channel_id:<18} {format_alias(node1_alias):<40} {format_alias(node2_alias):<40}' + if show_fees: + text += f'base {channel.node1_policy.fee_base_msat:<5} rate {channel.node1_policy.fee_rate_milli_msat:<5} '\ + f'base {channel.node2_policy.fee_base_msat:<5} rate {channel.node2_policy.fee_rate_milli_msat:<5} ' if chanDisabled: return chalk.bg_red(text) else: diff --git a/ringtools.py b/ringtools.py index b25611e..b0f8588 100644 --- a/ringtools.py +++ b/ringtools.py @@ -13,9 +13,12 @@ class RingTools: self.arguments = arguments def start(self): - print(self.arguments.function) if self.arguments.function == "status": - Status(self.lnd, self.output, self.arguments.channels_file, self.arguments.loop).run() + Status(self.lnd, + self.output, + self.arguments.channels_file, + self.arguments.loop, + self.arguments.show_fees).run() pass @@ -28,6 +31,13 @@ def main(): def get_argument_parser(): parser = argparse.ArgumentParser() # This is needed for the cert and macaroon of LND + parser.add_argument( + dest="function", + choices=['status'], + help="Choose which function of the RingTools you would " + "like to use", + default="help", + ) parser.add_argument( "--lnddir", default="~/.lnd", @@ -40,14 +50,13 @@ def get_argument_parser(): dest="grpc", help="(default localhost:10009) lnd gRPC endpoint", ) - parser.add_argument(dest="function", choices=['status']) status_group = parser.add_argument_group( "status", "Get the current status of all channels", ) status_group.add_argument( "-channels-file", - "-f", + "-c", default="./channels.txt", dest="channels_file", help="(default ./channels.txt) channels file" @@ -59,6 +68,13 @@ def get_argument_parser(): dest="loop", help="(default False) Keeps checking channel status" ) + status_group.add_argument( + '-f', + '--show-fees', + action="store_true", + dest="show_fees", + help="(default False) Shows fees in status screen" + ) return parser diff --git a/status.py b/status.py index f055aab..04e5ef5 100644 --- a/status.py +++ b/status.py @@ -1,19 +1,18 @@ import os -import re from time import sleep -from output import format_error, Output, format_alias, clear_screen, format_channel +from output import format_error, clear_screen, format_channel LOOP_SLEEP_TIME = 10 class Status: - def __init__(self, lnd, output, channels_file, keep_loop): + def __init__(self, lnd, output, channels_file, keep_loop, show_fees): self.lnd = lnd self.output = output self.channels_file = channels_file self.keep_loop = keep_loop - print(channels_file) + self.show_fees = show_fees def read_file(self, file): if not os.path.isfile(file): @@ -41,10 +40,10 @@ class Status: node1 = self.lnd.get_node(response.node1_pub) node2 = self.lnd.get_node(response.node2_pub) disabled = response.node1_policy.disabled or response.node2_policy.disabled - self.print_channel(response.channel_id, node1.alias, node2.alias, disabled) + self.print_channel(response, node1.alias, node2.alias, disabled) - def print_channel(self, channel_id, node1_alias, node2_alias, chan_disabled): - self.output.print_line(format_channel(channel_id, node1_alias, node2_alias, chan_disabled)) + def print_channel(self, channel, node1_alias, node2_alias, chan_disabled): + self.output.print_line(format_channel(channel, node1_alias, node2_alias, chan_disabled, self.show_fees)) def handle_error(self, error): self.output.print_line(format_error(error))