electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 95376226e8567adb4b7bd4eea298e623f58c26e4
parent b1f8c424241f16a745940302a700478e89417955
Author: ThomasV <thomasv@electrum.org>
Date:   Wed,  8 May 2019 12:41:57 +0200

save lightning invoice descriptions as labels and allow user to edit them

Diffstat:
Melectrum/gui/qt/history_list.py | 9++++++---
Melectrum/lnworker.py | 14++++----------
Melectrum/tests/test_lnpeer.py | 2++
3 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/electrum/gui/qt/history_list.py b/electrum/gui/qt/history_list.py @@ -104,6 +104,9 @@ class HistorySortModel(QSortFilterProxyModel): except: return False +def get_item_key(tx_item): + return tx_item.get('txid') or tx_item['payment_hash'] + class HistoryModel(QAbstractItemModel, Logger): def __init__(self, parent): @@ -253,7 +256,7 @@ class HistoryModel(QAbstractItemModel, Logger): def update_label(self, row): tx_item = self.transactions.value_from_pos(row) - tx_item['label'] = self.parent.wallet.get_label(tx_item['txid']) + tx_item['label'] = self.parent.wallet.get_label(get_item_key(tx_item)) topLeft = bottomRight = self.createIndex(row, 2) self.dataChanged.emit(topLeft, bottomRight, [Qt.DisplayRole]) @@ -586,7 +589,7 @@ class HistoryList(MyTreeView, AcceptFileDragDrop): index = self.model().mapToSource(index) row, column = index.row(), index.column() tx_item = self.hm.transactions.value_from_pos(row) - key = tx_item['txid'] + key = get_item_key(tx_item) if column == HistoryColumns.DESCRIPTION: if self.wallet.set_label(key, text): #changed self.hm.update_label(row) @@ -758,4 +761,4 @@ class HistoryList(MyTreeView, AcceptFileDragDrop): def text_txid_from_coordinate(self, row, col): idx = self.model().mapToSource(self.model().index(row, col)) tx_item = self.hm.transactions.value_from_pos(idx.row()) - return self.hm.data(idx, Qt.DisplayRole).value(), tx_item['txid'] + return self.hm.data(idx, Qt.DisplayRole).value(), get_item_key(tx_item) diff --git a/electrum/lnworker.py b/electrum/lnworker.py @@ -306,7 +306,7 @@ class LNWallet(LNWorker): direction = 'sent' if _direction == SENT else 'received' amount_msat= int(_direction) * htlc.amount_msat timestamp = htlc.timestamp - label = self.get_invoice_label(bfh(payment_hash)) + label = self.wallet.get_label(payment_hash) else: # assume forwarding direction = 'forwarding' @@ -606,6 +606,8 @@ class LNWallet(LNWorker): async def _pay(self, invoice, amount_sat=None, same_thread=False): addr = self._check_invoice(invoice, amount_sat) + self.save_invoice(addr.paymenthash, invoice, SENT, is_paid=False) + self.wallet.set_label(bh2u(addr.paymenthash), addr.get_description()) route = await self._create_route_from_invoice(decoded_invoice=addr) peer = self.peers[route[0].node_id] if not self.get_channel_by_short_id(route[0].short_channel_id): @@ -618,7 +620,6 @@ class LNWallet(LNWorker): if not chan: raise Exception("PathFinder returned path with short_channel_id {} that is not in channel list".format(bh2u(short_channel_id))) peer = self.peers[route[0].node_id] - self.save_invoice(addr.paymenthash, pay_req, SENT, is_paid=False) htlc = await peer.pay(route, chan, int(addr.amount * COIN * 1000), addr.paymenthash, addr.get_min_final_cltv_expiry()) self.network.trigger_callback('htlc_added', htlc, addr, SENT) @@ -704,6 +705,7 @@ class LNWallet(LNWorker): self.node_keypair.privkey) self.save_invoice(payment_hash, invoice, RECEIVED, is_paid=False) self.save_preimage(payment_hash, payment_preimage) + self.wallet.set_label(bh2u(payment_hash), message) return invoice def save_preimage(self, payment_hash: bytes, preimage: bytes): @@ -742,14 +744,6 @@ 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() diff --git a/electrum/tests/test_lnpeer.py b/electrum/tests/test_lnpeer.py @@ -75,6 +75,8 @@ class MockStorage: class MockWallet: storage = MockStorage() + def set_label(self, x, y): + pass class MockLNWallet: def __init__(self, remote_keypair, local_keypair, chan, tx_queue):