mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-30 08:51:32 +00:00
save lightning invoice descriptions as labels and allow user to edit them
This commit is contained in:
parent
b1f8c42424
commit
95376226e8
3 changed files with 12 additions and 13 deletions
|
@ -104,6 +104,9 @@ class HistorySortModel(QSortFilterProxyModel):
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def get_item_key(tx_item):
|
||||||
|
return tx_item.get('txid') or tx_item['payment_hash']
|
||||||
|
|
||||||
class HistoryModel(QAbstractItemModel, Logger):
|
class HistoryModel(QAbstractItemModel, Logger):
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
|
@ -253,7 +256,7 @@ class HistoryModel(QAbstractItemModel, Logger):
|
||||||
|
|
||||||
def update_label(self, row):
|
def update_label(self, row):
|
||||||
tx_item = self.transactions.value_from_pos(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)
|
topLeft = bottomRight = self.createIndex(row, 2)
|
||||||
self.dataChanged.emit(topLeft, bottomRight, [Qt.DisplayRole])
|
self.dataChanged.emit(topLeft, bottomRight, [Qt.DisplayRole])
|
||||||
|
|
||||||
|
@ -586,7 +589,7 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
|
||||||
index = self.model().mapToSource(index)
|
index = self.model().mapToSource(index)
|
||||||
row, column = index.row(), index.column()
|
row, column = index.row(), index.column()
|
||||||
tx_item = self.hm.transactions.value_from_pos(row)
|
tx_item = self.hm.transactions.value_from_pos(row)
|
||||||
key = tx_item['txid']
|
key = get_item_key(tx_item)
|
||||||
if column == HistoryColumns.DESCRIPTION:
|
if column == HistoryColumns.DESCRIPTION:
|
||||||
if self.wallet.set_label(key, text): #changed
|
if self.wallet.set_label(key, text): #changed
|
||||||
self.hm.update_label(row)
|
self.hm.update_label(row)
|
||||||
|
@ -758,4 +761,4 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
|
||||||
def text_txid_from_coordinate(self, row, col):
|
def text_txid_from_coordinate(self, row, col):
|
||||||
idx = self.model().mapToSource(self.model().index(row, col))
|
idx = self.model().mapToSource(self.model().index(row, col))
|
||||||
tx_item = self.hm.transactions.value_from_pos(idx.row())
|
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)
|
||||||
|
|
|
@ -306,7 +306,7 @@ class LNWallet(LNWorker):
|
||||||
direction = 'sent' if _direction == SENT else 'received'
|
direction = 'sent' if _direction == SENT else 'received'
|
||||||
amount_msat= int(_direction) * htlc.amount_msat
|
amount_msat= int(_direction) * htlc.amount_msat
|
||||||
timestamp = htlc.timestamp
|
timestamp = htlc.timestamp
|
||||||
label = self.get_invoice_label(bfh(payment_hash))
|
label = self.wallet.get_label(payment_hash)
|
||||||
else:
|
else:
|
||||||
# assume forwarding
|
# assume forwarding
|
||||||
direction = 'forwarding'
|
direction = 'forwarding'
|
||||||
|
@ -606,6 +606,8 @@ class LNWallet(LNWorker):
|
||||||
|
|
||||||
async def _pay(self, invoice, amount_sat=None, same_thread=False):
|
async def _pay(self, invoice, amount_sat=None, same_thread=False):
|
||||||
addr = self._check_invoice(invoice, amount_sat)
|
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)
|
route = await self._create_route_from_invoice(decoded_invoice=addr)
|
||||||
peer = self.peers[route[0].node_id]
|
peer = self.peers[route[0].node_id]
|
||||||
if not self.get_channel_by_short_id(route[0].short_channel_id):
|
if not self.get_channel_by_short_id(route[0].short_channel_id):
|
||||||
|
@ -618,7 +620,6 @@ class LNWallet(LNWorker):
|
||||||
if not chan:
|
if not chan:
|
||||||
raise Exception("PathFinder returned path with short_channel_id {} that is not in channel list".format(bh2u(short_channel_id)))
|
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]
|
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())
|
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)
|
self.network.trigger_callback('htlc_added', htlc, addr, SENT)
|
||||||
|
|
||||||
|
@ -704,6 +705,7 @@ class LNWallet(LNWorker):
|
||||||
self.node_keypair.privkey)
|
self.node_keypair.privkey)
|
||||||
self.save_invoice(payment_hash, invoice, RECEIVED, is_paid=False)
|
self.save_invoice(payment_hash, invoice, RECEIVED, is_paid=False)
|
||||||
self.save_preimage(payment_hash, payment_preimage)
|
self.save_preimage(payment_hash, payment_preimage)
|
||||||
|
self.wallet.set_label(bh2u(payment_hash), message)
|
||||||
return invoice
|
return invoice
|
||||||
|
|
||||||
def save_preimage(self, payment_hash: bytes, preimage: bytes):
|
def save_preimage(self, payment_hash: bytes, preimage: bytes):
|
||||||
|
@ -742,14 +744,6 @@ class LNWallet(LNWorker):
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
raise UnknownPaymentHash(payment_hash) from 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):
|
def _calc_routing_hints_for_invoice(self, amount_sat):
|
||||||
"""calculate routing hints (BOLT-11 'r' field)"""
|
"""calculate routing hints (BOLT-11 'r' field)"""
|
||||||
self.channel_db.load_data()
|
self.channel_db.load_data()
|
||||||
|
|
|
@ -75,6 +75,8 @@ class MockStorage:
|
||||||
|
|
||||||
class MockWallet:
|
class MockWallet:
|
||||||
storage = MockStorage()
|
storage = MockStorage()
|
||||||
|
def set_label(self, x, y):
|
||||||
|
pass
|
||||||
|
|
||||||
class MockLNWallet:
|
class MockLNWallet:
|
||||||
def __init__(self, remote_keypair, local_keypair, chan, tx_queue):
|
def __init__(self, remote_keypair, local_keypair, chan, tx_queue):
|
||||||
|
|
Loading…
Add table
Reference in a new issue