mirror of
https://github.com/StijnBTC/Ringtools.git
synced 2024-11-19 00:50:03 +01:00
Auto-create channels.txt from established channels
This commit is contained in:
parent
b8284ba9b7
commit
e32a460835
11
checkring.py
11
checkring.py
@ -7,11 +7,13 @@ from yachalk import chalk
|
||||
|
||||
|
||||
class CheckRing:
|
||||
def __init__(self, lnd, output, pubkeys_file, show_fees):
|
||||
def __init__(self, lnd, output, pubkeys_file, write_channels, show_fees, channels_file):
|
||||
self.lnd = lnd
|
||||
self.output = output
|
||||
self.pubkeys_file = pubkeys_file
|
||||
self.show_fees = show_fees
|
||||
self.write_channels = write_channels
|
||||
self.channels_file = channels_file
|
||||
|
||||
def read_file(self, file):
|
||||
if not os.path.isfile(file):
|
||||
@ -26,6 +28,7 @@ class CheckRing:
|
||||
|
||||
def once(self):
|
||||
pubkeys = self.read_file(self.pubkeys_file)
|
||||
channelList = []
|
||||
|
||||
for idx, pubkeyInfo in enumerate(pubkeys):
|
||||
# pubkeys format is <pubkey>,<telegram username> to be able to mimic the manual pubkey overview with usernames
|
||||
@ -46,6 +49,7 @@ class CheckRing:
|
||||
hasChannel = True
|
||||
channelId = channel.channel_id
|
||||
channelInfo = channel
|
||||
channelList.append(channelId)
|
||||
|
||||
if hasChannel:
|
||||
outputHas = chalk.green('✅')
|
||||
@ -71,6 +75,11 @@ class CheckRing:
|
||||
except Exception as error:
|
||||
self.output.print_line(
|
||||
format_channel_error(pubkey, repr(error)))
|
||||
if self.write_channels:
|
||||
f = open(self.channels_file, "w")
|
||||
for c in channelList:
|
||||
f.write(str(c) + "\r\n")
|
||||
f.close()
|
||||
|
||||
def print_channel(self, channel, node1_alias, node2_alias, chan_disabled):
|
||||
self.output.print_line(format_channel(
|
||||
|
28
ringtools.py
28
ringtools.py
@ -24,7 +24,10 @@ class RingTools:
|
||||
CheckRing(self.lnd,
|
||||
self.output,
|
||||
self.arguments.pubkeys_file,
|
||||
self.arguments.show_fees).run()
|
||||
self.arguments.write_channels,
|
||||
self.arguments.show_fees,
|
||||
self.arguments.channels_file
|
||||
).run()
|
||||
pass
|
||||
|
||||
|
||||
@ -61,17 +64,31 @@ def get_argument_parser():
|
||||
dest="grpc",
|
||||
help="(default localhost:10009) lnd gRPC endpoint",
|
||||
)
|
||||
check_group = parser.add_argument(
|
||||
|
||||
status_group = parser.add_argument_group(
|
||||
"status",
|
||||
"Get the current status of all channels",
|
||||
)
|
||||
check_group = parser.add_argument_group(
|
||||
"check",
|
||||
"Check if channels are open with pubkey list",
|
||||
)
|
||||
|
||||
check_group.add_argument(
|
||||
"-pubkeys-file",
|
||||
"-pk",
|
||||
default="./pubkeys.txt",
|
||||
dest="pubkeys_file",
|
||||
help="(default ./pubkeys.txt) pubkeys file"
|
||||
)
|
||||
status_group = parser.add_argument_group(
|
||||
"status",
|
||||
"Get the current status of all channels",
|
||||
check_group.add_argument(
|
||||
'-w',
|
||||
'--write-channels',
|
||||
action="store_true",
|
||||
dest="write_channels",
|
||||
help="(default False) Write channels.txt"
|
||||
)
|
||||
|
||||
status_group.add_argument(
|
||||
"-channels-file",
|
||||
"-c",
|
||||
@ -94,6 +111,7 @@ def get_argument_parser():
|
||||
dest="show_fees",
|
||||
help="(default False) Shows fees in status screen"
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user