diff --git a/electrum/lnworker.py b/electrum/lnworker.py index f89c2937036b..90f428953c01 100644 --- a/electrum/lnworker.py +++ b/electrum/lnworker.py @@ -217,7 +217,7 @@ def __init__(self, xprv, features: LnFeatures): self.network = None # type: Optional[Network] self.config = None # type: Optional[SimpleConfig] self.stopping_soon = False # whether we are being shut down - + self._labels_cache = {} # txid -> str self.register_callbacks() @property @@ -876,6 +876,9 @@ def get_lightning_history(self): out[payment_hash] = item return out + def get_label_for_txid(self, txid: str) -> str: + return self._labels_cache.get(txid) + def get_onchain_history(self): current_height = self.wallet.adb.get_local_height() out = {} @@ -886,10 +889,11 @@ def get_onchain_history(self): continue funding_txid, funding_height, funding_timestamp = item tx_height = self.wallet.adb.get_tx_height(funding_txid) + self._labels_cache[funding_txid] = _('Open channel') + ' ' + chan.get_id_for_log() item = { 'channel_id': bh2u(chan.channel_id), 'type': 'channel_opening', - 'label': self.wallet.get_label_for_txid(funding_txid) or (_('Open channel') + ' ' + chan.get_id_for_log()), + 'label': self.get_label_for_txid(funding_txid), 'txid': funding_txid, 'amount_msat': chan.balance(LOCAL, ctn=0), 'direction': PaymentDirection.RECEIVED, @@ -906,10 +910,11 @@ def get_onchain_history(self): continue closing_txid, closing_height, closing_timestamp = item tx_height = self.wallet.adb.get_tx_height(closing_txid) + self._labels_cache[closing_txid] = _('Close channel') + ' ' + chan.get_id_for_log() item = { 'channel_id': bh2u(chan.channel_id), 'txid': closing_txid, - 'label': self.wallet.get_label_for_txid(closing_txid) or (_('Close channel') + ' ' + chan.get_id_for_log()), + 'label': self.get_label_for_txid(closing_txid), 'type': 'channel_closure', 'amount_msat': -chan.balance_minus_outgoing_htlcs(LOCAL), 'direction': PaymentDirection.SENT, @@ -942,13 +947,14 @@ def get_onchain_history(self): label += ' (%s)' % _('waiting for funding tx confirmation') if not swap.is_reverse and not swap.is_redeemed and swap.spending_txid is None and delta < 0: label += f' (refundable in {-delta} blocks)' # fixme: only if unspent + self._labels_cache[txid] = label out[txid] = { 'txid': txid, 'group_id': txid, 'amount_msat': 0, #'amount_msat': amount_msat, # must not be added 'type': 'swap', - 'label': self.wallet.get_label_for_txid(txid) or label, + 'label': self.get_label_for_txid(txid), } return out diff --git a/electrum/wallet.py b/electrum/wallet.py index 360f7a0d58af..34258778fd40 100644 --- a/electrum/wallet.py +++ b/electrum/wallet.py @@ -1372,6 +1372,8 @@ def get_label_for_txid(self, tx_hash: str) -> str: return self._labels.get(tx_hash) or self._get_default_label_for_txid(tx_hash) def _get_default_label_for_txid(self, tx_hash: str) -> str: + if self.lnworker and (label:= self.lnworker.get_label_for_txid(tx_hash)): + return label # note: we don't deserialize tx as the history calls us for every tx, and that would be slow if not self.db.get_txi_addresses(tx_hash): # no inputs are ismine -> likely incoming payment -> concat labels of output addresses