2021-07-30 12:49:23 +02:00
|
|
|
import argparse
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from lnd import Lnd
|
|
|
|
from output import Output
|
|
|
|
from status import Status
|
2021-08-02 15:20:55 +02:00
|
|
|
from utils import is_umbrel
|
2021-10-03 02:14:53 +02:00
|
|
|
from checkring import CheckRing
|
2021-07-30 12:49:23 +02:00
|
|
|
|
|
|
|
class RingTools:
|
|
|
|
def __init__(self, arguments):
|
|
|
|
self.lnd = Lnd(arguments.lnddir, arguments.grpc)
|
|
|
|
self.output = Output(self.lnd)
|
|
|
|
self.arguments = arguments
|
|
|
|
|
|
|
|
def start(self):
|
|
|
|
if self.arguments.function == "status":
|
2021-07-30 14:48:00 +02:00
|
|
|
Status(self.lnd,
|
|
|
|
self.output,
|
|
|
|
self.arguments.channels_file,
|
|
|
|
self.arguments.loop,
|
|
|
|
self.arguments.show_fees).run()
|
2021-10-03 02:14:53 +02:00
|
|
|
elif self.arguments.function == "check":
|
|
|
|
CheckRing(self.lnd,
|
|
|
|
self.output,
|
|
|
|
self.arguments.pubkeys_file,
|
2021-10-03 02:29:24 +02:00
|
|
|
self.arguments.write_channels,
|
|
|
|
self.arguments.show_fees,
|
|
|
|
self.arguments.channels_file
|
|
|
|
).run()
|
2021-07-30 12:49:23 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
argument_parser = get_argument_parser()
|
|
|
|
arguments = argument_parser.parse_args()
|
|
|
|
return RingTools(arguments).start()
|
|
|
|
|
|
|
|
|
|
|
|
def get_argument_parser():
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
# This is needed for the cert and macaroon of LND
|
2021-07-30 14:48:00 +02:00
|
|
|
parser.add_argument(
|
|
|
|
dest="function",
|
2021-10-03 02:14:53 +02:00
|
|
|
choices=['status', 'check'],
|
2021-07-30 14:48:00 +02:00
|
|
|
help="Choose which function of the RingTools you would "
|
|
|
|
"like to use",
|
|
|
|
default="help",
|
|
|
|
)
|
2021-08-02 15:20:55 +02:00
|
|
|
#If nodeos is Umbrel use the default umbrel lnd location
|
|
|
|
lnd_dir = "~/.lnd"
|
|
|
|
if is_umbrel():
|
2021-08-24 21:57:51 +02:00
|
|
|
lnd_dir = "~/umbrel/lnd"
|
2021-08-02 15:20:55 +02:00
|
|
|
|
2021-07-30 12:49:23 +02:00
|
|
|
parser.add_argument(
|
|
|
|
"--lnddir",
|
2021-08-02 15:20:55 +02:00
|
|
|
default=lnd_dir,
|
2021-07-30 12:49:23 +02:00
|
|
|
dest="lnddir",
|
2021-08-24 21:57:51 +02:00
|
|
|
help="(default ~/.lnd or ~/umbrel/lnd/ when default umbrel installation) lnd directory",
|
2021-07-30 12:49:23 +02:00
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--grpc",
|
|
|
|
default="localhost:10009",
|
|
|
|
dest="grpc",
|
|
|
|
help="(default localhost:10009) lnd gRPC endpoint",
|
|
|
|
)
|
2021-10-03 02:29:24 +02:00
|
|
|
|
|
|
|
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(
|
2021-10-03 02:14:53 +02:00
|
|
|
"-pubkeys-file",
|
|
|
|
"-pk",
|
|
|
|
default="./pubkeys.txt",
|
|
|
|
dest="pubkeys_file",
|
|
|
|
help="(default ./pubkeys.txt) pubkeys file"
|
|
|
|
)
|
2021-10-03 02:29:24 +02:00
|
|
|
check_group.add_argument(
|
|
|
|
'-w',
|
|
|
|
'--write-channels',
|
|
|
|
action="store_true",
|
|
|
|
dest="write_channels",
|
|
|
|
help="(default False) Write channels.txt"
|
2021-07-30 12:49:23 +02:00
|
|
|
)
|
2021-10-03 02:29:24 +02:00
|
|
|
|
2021-07-30 12:49:23 +02:00
|
|
|
status_group.add_argument(
|
|
|
|
"-channels-file",
|
2021-07-30 14:48:00 +02:00
|
|
|
"-c",
|
2021-07-30 12:49:23 +02:00
|
|
|
default="./channels.txt",
|
|
|
|
dest="channels_file",
|
|
|
|
help="(default ./channels.txt) channels file"
|
|
|
|
)
|
2021-10-03 02:14:53 +02:00
|
|
|
|
2021-07-30 12:49:23 +02:00
|
|
|
status_group.add_argument(
|
|
|
|
"-l",
|
|
|
|
"--loop",
|
|
|
|
action="store_true",
|
|
|
|
dest="loop",
|
|
|
|
help="(default False) Keeps checking channel status"
|
|
|
|
)
|
2021-07-30 14:48:00 +02:00
|
|
|
status_group.add_argument(
|
|
|
|
'-f',
|
|
|
|
'--show-fees',
|
|
|
|
action="store_true",
|
|
|
|
dest="show_fees",
|
|
|
|
help="(default False) Shows fees in status screen"
|
|
|
|
)
|
2021-10-03 02:29:24 +02:00
|
|
|
|
2021-07-30 12:49:23 +02:00
|
|
|
return parser
|
|
|
|
|
|
|
|
|
|
|
|
success = main()
|
|
|
|
if success:
|
|
|
|
sys.exit(0)
|
|
|
|
sys.exit(1)
|