Fee output added to overview when using -f flag

This commit is contained in:
StijnBTC 2021-07-30 14:48:00 +02:00
parent 4c92ebb47a
commit eeee55b19d
No known key found for this signature in database
GPG key ID: B1E4DFC4452D1E7F
3 changed files with 33 additions and 13 deletions

View file

@ -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:

View file

@ -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

View file

@ -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))