ringtools-cli/status.py

55 lines
1.7 KiB
Python
Raw Normal View History

2021-07-30 12:49:23 +02:00
import os
from time import sleep
from output import format_error, clear_screen, format_channel
2021-07-30 12:49:23 +02:00
LOOP_SLEEP_TIME = 10
class Status:
def __init__(self, lnd, output, channels_file, keep_loop, show_fees):
2021-07-30 12:49:23 +02:00
self.lnd = lnd
self.output = output
self.channels_file = channels_file
self.keep_loop = keep_loop
self.show_fees = show_fees
2021-07-30 12:49:23 +02:00
def read_file(self, file):
if not os.path.isfile(file):
self.handle_error("File does not exist")
else:
with open(self.channels_file) as file:
return file.read().splitlines()
def run(self):
if self.keep_loop:
self.loop()
else:
self.once()
def loop(self):
while True:
clear_screen()
self.once()
sleep(LOOP_SLEEP_TIME)
def once(self):
channels = self.read_file(self.channels_file)
for channelID in channels:
2021-08-10 22:47:34 +02:00
if len(channelID) != 18:
continue
2021-08-10 23:04:17 +02:00
if not channelID.isnumeric():
continue
2021-07-30 12:49:23 +02:00
response = self.lnd.get_edge(int(channelID))
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, node1.alias, node2.alias, disabled)
2021-07-30 12:49:23 +02:00
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))
2021-07-30 12:49:23 +02:00
def handle_error(self, error):
self.output.print_line(format_error(error))