tadd labels to lightning history - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit e53ecb9b77d4c50034e6bde4bb3e21eff63c638d DIR parent c4081284bdf82e1f9a9c18338153c436dafe5aa4 HTML Author: ThomasV <thomasv@electrum.org> Date: Mon, 6 May 2019 16:52:25 +0200 add labels to lightning history Diffstat: M electrum/gui/qt/invoice_list.py | 6 +----- M electrum/gui/qt/request_list.py | 6 +----- M electrum/lnaddr.py | 8 ++++++++ M electrum/lnworker.py | 12 ++++++++++-- 4 files changed, 20 insertions(+), 12 deletions(-) --- DIR diff --git a/electrum/gui/qt/invoice_list.py b/electrum/gui/qt/invoice_list.py t@@ -100,11 +100,7 @@ class InvoiceList(MyTreeView): lnaddr = lndecode(invoice, expected_hrp=constants.net.SEGWIT_HRP) amount_sat = lnaddr.amount*COIN if lnaddr.amount else None amount_str = self.parent.format_amount(amount_sat) if amount_sat else '' - description = '' - for k,v in lnaddr.tags: - if k == 'd': - description = v - break + description = lnaddr.get_description() date_str = format_time(lnaddr.date) labels = [date_str, description, amount_str, pr_tooltips.get(status,'')] items = [QStandardItem(e) for e in labels] DIR diff --git a/electrum/gui/qt/request_list.py b/electrum/gui/qt/request_list.py t@@ -144,11 +144,7 @@ class RequestList(MyTreeView): lnaddr = lndecode(invoice, expected_hrp=constants.net.SEGWIT_HRP) amount_sat = lnaddr.amount*COIN if lnaddr.amount else None amount_str = self.parent.format_amount(amount_sat) if amount_sat else '' - description = '' - for k,v in lnaddr.tags: - if k == 'd': - description = v - break + description = lnaddr.get_description() date = format_time(lnaddr.date) labels = [date, description, amount_str, pr_tooltips.get(status,'')] items = [QStandardItem(e) for e in labels] DIR diff --git a/electrum/lnaddr.py b/electrum/lnaddr.py t@@ -258,6 +258,14 @@ class LnAddr(object): def get_min_final_cltv_expiry(self) -> int: return self._min_final_cltv_expiry + def get_description(self): + description = '' + for k,v in self.tags: + if k == 'd': + description = v + break + return description + def lndecode(a, verbose=False, expected_hrp=None): if expected_hrp is None: DIR diff --git a/electrum/lnworker.py b/electrum/lnworker.py t@@ -305,8 +305,8 @@ class LNWallet(LNWorker): chan_id, htlc, _direction, status = plist[0] direction = 'sent' if _direction == SENT else 'received' amount_msat= int(_direction) * htlc.amount_msat - label = '' timestamp = htlc.timestamp + label = self.get_invoice_label(bfh(payment_hash)) else: # assume forwarding direction = 'forwarding' t@@ -742,6 +742,14 @@ class LNWallet(LNWorker): except KeyError as e: raise UnknownPaymentHash(payment_hash) from e + def get_invoice_label(self, payment_hash: bytes) -> str: + try: + lnaddr = self.get_invoice(payment_hash) + label = lnaddr.get_description() + except: + label = '' + return label + def _calc_routing_hints_for_invoice(self, amount_sat): """calculate routing hints (BOLT-11 'r' field)""" self.channel_db.load_data() t@@ -800,7 +808,7 @@ class LNWallet(LNWorker): # we output the funding_outpoint instead of the channel_id because lnd uses channel_point (funding outpoint) to identify channels for channel_id, chan in self.channels.items(): yield { - 'local_htlcs': json.loads(encoder.encode(chan.hm.log[LOCAL ])), + 'local_htlcs': json.loads(encoder.encode(chan.hm.log[LOCAL])), 'remote_htlcs': json.loads(encoder.encode(chan.hm.log[REMOTE])), 'channel_id': bh2u(chan.short_channel_id) if chan.short_channel_id else None, 'full_channel_id': bh2u(chan.channel_id),