2021-07-30 12:49:23 +02:00
|
|
|
import os
|
2021-10-02 23:13:19 +02:00
|
|
|
import grpc
|
2021-07-30 12:49:23 +02:00
|
|
|
from time import sleep
|
|
|
|
|
2021-10-02 23:13:19 +02:00
|
|
|
from output import format_channel_error, format_error, clear_screen, format_channel
|
2021-07-30 12:49:23 +02:00
|
|
|
|
|
|
|
LOOP_SLEEP_TIME = 10
|
|
|
|
|
|
|
|
|
|
|
|
class Status:
|
2021-07-30 14:48:00 +02:00
|
|
|
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
|
2021-07-30 14:48:00 +02:00
|
|
|
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-10-02 23:13:19 +02:00
|
|
|
try:
|
|
|
|
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)
|
|
|
|
except grpc.RpcError as e:
|
|
|
|
self.output.print_line(format_channel_error(channelID, e.details()))
|
|
|
|
except Exception as error:
|
|
|
|
self.output.print_line(format_channel_error(channelID, repr(error)))
|
|
|
|
|
2021-07-30 14:48:00 +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))
|