Refresh LN status in GUI using network callback.
This commit is contained in:
parent
4e95f5e4c0
commit
38f0f25f8e
@ -125,6 +125,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||
|
||||
self.create_status_bar()
|
||||
self.need_update = threading.Event()
|
||||
self.need_update_ln = threading.Event()
|
||||
|
||||
self.decimal_point = config.get('decimal_point', 5)
|
||||
self.num_zeros = int(config.get('num_zeros',0))
|
||||
@ -186,7 +187,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||
self.network_signal.connect(self.on_network_qt)
|
||||
interests = ['updated', 'new_transaction', 'status',
|
||||
'banner', 'verified', 'fee', 'on_quotes',
|
||||
'on_history', 'channel', 'channels']
|
||||
'on_history', 'channel', 'channels', 'ln_status']
|
||||
# To avoid leaking references to "self" that prevent the
|
||||
# window from being GC-ed when closed, callbacks should be
|
||||
# methods of this class only, and specifically not be
|
||||
@ -302,6 +303,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||
self.channels_list.update_rows.emit(*args)
|
||||
elif event == 'channel':
|
||||
self.channels_list.update_single_row.emit(*args)
|
||||
elif event == 'ln_status':
|
||||
self.need_update_ln.set()
|
||||
else:
|
||||
self.print_error("unexpected network message:", event, args)
|
||||
|
||||
@ -645,6 +648,9 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||
if self.need_update.is_set():
|
||||
self.need_update.clear()
|
||||
self.update_wallet()
|
||||
if self.need_update_ln.is_set():
|
||||
self.need_update_ln.clear()
|
||||
self.channels_list.update_status()
|
||||
# resolve aliases
|
||||
# FIXME this is a blocking network call that has a timeout of 5 sec
|
||||
self.payto_e.resolve()
|
||||
|
||||
@ -65,10 +65,11 @@ class ChannelsList(MyTreeWidget):
|
||||
h.addWidget(b)
|
||||
return h
|
||||
|
||||
def on_update(self):
|
||||
def update_status(self):
|
||||
n = len(self.parent.network.lightning_nodes)
|
||||
nc = len(self.parent.network.channel_db)
|
||||
np = len(self.parent.wallet.lnworker.peers)
|
||||
self.status.setText(_('{} peers, {} nodes').format(np, n))
|
||||
self.status.setText(_('{} peers, {} nodes, {} channels').format(np, n, nc))
|
||||
|
||||
def new_channel_dialog(self):
|
||||
d = WindowModalDialog(self.parent, _('Open Channel'))
|
||||
|
||||
@ -282,7 +282,6 @@ def aiosafe(f):
|
||||
class Peer(PrintError):
|
||||
|
||||
def __init__(self, lnworker, host, port, pubkey, request_initial_sync=False):
|
||||
self.channel_update_event = asyncio.Event()
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.pubkey = pubkey
|
||||
@ -457,17 +456,17 @@ class Peer(PrintError):
|
||||
'addresses': addresses
|
||||
}
|
||||
self.print_error('node announcement', binascii.hexlify(pubkey), alias, addresses)
|
||||
self.network.trigger_callback('ln_status')
|
||||
|
||||
def on_init(self, payload):
|
||||
pass
|
||||
|
||||
def on_channel_update(self, payload):
|
||||
self.channel_db.on_channel_update(payload)
|
||||
self.channel_update_event.set()
|
||||
|
||||
def on_channel_announcement(self, payload):
|
||||
self.channel_db.on_channel_announcement(payload)
|
||||
self.channel_update_event.set()
|
||||
self.network.trigger_callback('ln_status')
|
||||
|
||||
def on_announcement_signatures(self, payload):
|
||||
channel_id = payload['channel_id']
|
||||
|
||||
@ -100,6 +100,9 @@ class ChannelDB(PrintError):
|
||||
self._id_to_channel_info = {}
|
||||
self._channels_for_node = defaultdict(set) # node -> set(short_channel_id)
|
||||
|
||||
def __len__(self):
|
||||
return len(self._id_to_channel_info)
|
||||
|
||||
def get_channel_info(self, channel_id):
|
||||
return self._id_to_channel_info.get(channel_id, None)
|
||||
|
||||
|
||||
@ -57,7 +57,7 @@ class LNWorker(PrintError):
|
||||
peer = Peer(self, host, int(port), node_id, request_initial_sync=self.config.get("request_initial_sync", True))
|
||||
self.network.futures.append(asyncio.run_coroutine_threadsafe(peer.main_loop(), asyncio.get_event_loop()))
|
||||
self.peers[node_id] = peer
|
||||
self.lock = threading.Lock()
|
||||
self.network.trigger_callback('ln_status')
|
||||
|
||||
def save_channel(self, openchannel):
|
||||
assert type(openchannel) is HTLCStateMachine
|
||||
|
||||
Loading…
Reference in New Issue
Block a user