filter public/private in suez.py not in clients

This commit is contained in:
Pavol Rusnak 2023-02-26 13:17:44 +01:00
parent b85e72bbeb
commit cd23289d4c
No known key found for this signature in database
GPG key ID: 91F3B339B9A02A3D
3 changed files with 11 additions and 31 deletions

View file

@ -5,20 +5,10 @@ from channel import Channel
class ClnClient:
def __init__(self, client_args, include_private, include_public):
def __init__(self, client_args):
self.client_args = client_args
self.include_private = include_private
self.include_public = include_public
self.refresh()
def should_exclude(self, c):
return (
c["private"]
and not self.include_private
or not c["private"]
and not self.include_public
)
def refresh(self):
gi = self._run("getinfo")
self.local_pubkey = gi["id"]
@ -31,8 +21,6 @@ class ClnClient:
for p in peers:
if p["channels"]:
for c in p["channels"]:
if self.should_exclude(c):
continue
chan = Channel()
chan.chan_id = c.get("short_channel_id")
chan.active = c["state"] == "CHANNELD_NORMAL"

View file

@ -5,10 +5,8 @@ from channel import Channel
class LndClient(abc.ABC):
def __init__(self, client_args, include_private, include_public):
def __init__(self, client_args):
self.client_args = client_args
self.include_private = include_private
self.include_public = include_public
self.refresh()
@abc.abstractmethod
@ -35,14 +33,6 @@ class LndClient(abc.ABC):
def updatechanpolicy(self, channel_point, policy):
pass
def should_exclude(self, c):
return (
c["private"]
and not self.include_private
or not c["private"]
and not self.include_public
)
def refresh(self):
gi = self.getinfo()
self.local_pubkey = gi["identity_pubkey"]
@ -51,8 +41,6 @@ class LndClient(abc.ABC):
channels = self.listchannels()["channels"]
for c in channels:
if self.should_exclude(c):
continue
chan = Channel()
chan.chan_id = c["chan_id"]
chan.active = c["active"]

14
suez.py
View file

@ -233,10 +233,7 @@ def suez(
"lnd-rest": LndRestClient,
}
include_private = channels in ["all", "private", "split"]
include_public = channels in ["all", "public", "split"]
ln = clients[client](client_args, include_private, include_public)
ln = clients[client](client_args)
score = Score() if show_scores else None
@ -282,8 +279,15 @@ def suez(
console.print(private_info)
console.print()
else:
if channels == "public":
show_channels = [c for c in ln.channels.values() if not c.private]
elif channels == "private":
show_channels = [c for c in ln.channels.values() if c.private]
else: # all
show_channels = ln.channels.values()
table = channel_table(
ln.channels.values(),
show_channels,
score,
show_remote_fees,
show_chan_ids,