Browse Source

lnworker: minor clean-up re payment_completed

regtest_lnd
SomberNight 6 years ago
parent
commit
1b8bf7a167
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 2
      electrum/gui/qt/request_list.py
  2. 3
      electrum/lnchannel.py
  3. 15
      electrum/lnworker.py

2
electrum/gui/qt/request_list.py

@ -178,7 +178,7 @@ class RequestList(MyTreeView):
if request_type == REQUEST_TYPE_BITCOIN: if request_type == REQUEST_TYPE_BITCOIN:
req = self.wallet.receive_requests.get(addr) req = self.wallet.receive_requests.get(addr)
elif request_type == REQUEST_TYPE_LN: elif request_type == REQUEST_TYPE_LN:
req = self.wallet.lnworker.invoices[addr][1] req = self.wallet.lnworker.invoices[addr][0]
if req is None: if req is None:
self.update() self.update()
return return

3
electrum/lnchannel.py

@ -119,7 +119,8 @@ class Channel(PrintError):
except: except:
return super().diagnostic_name() return super().diagnostic_name()
def __init__(self, state, sweep_address = None, name = None, payment_completed : Optional[Callable[[Direction, UpdateAddHtlc, bytes], None]] = None): def __init__(self, state, *, sweep_address=None, name=None,
payment_completed: Optional[Callable[['Channel', Direction, UpdateAddHtlc, bytes], None]] = None):
self.preimages = {} self.preimages = {}
if not payment_completed: if not payment_completed:
payment_completed = lambda this, x, y, z: None payment_completed = lambda this, x, y, z: None

15
electrum/lnworker.py

@ -125,11 +125,12 @@ class LNWorker(PrintError):
self.storage.write() self.storage.write()
self.print_error('saved lightning gossip timestamp') self.print_error('saved lightning gossip timestamp')
def payment_completed(self, chan, direction, htlc, _preimage): def payment_completed(self, chan: Channel, direction: Direction,
htlc: UpdateAddHtlc, preimage: Optional[bytes]):
chan_id = chan.channel_id chan_id = chan.channel_id
preimage = _preimage if _preimage else self.get_preimage(htlc.payment_hash) preimage = preimage if preimage else self.get_preimage(htlc.payment_hash)
timestamp = time.time() timestamp = int(time.time())
self.save_preimage(htlc.payment_hash, preimage, timestamp) self.save_preimage(htlc.payment_hash, preimage, timestamp=timestamp)
self.network.trigger_callback('ln_payment_completed', timestamp, direction, htlc, preimage, chan_id) self.network.trigger_callback('ln_payment_completed', timestamp, direction, htlc, preimage, chan_id)
def get_invoice_status(self, payment_hash): def get_invoice_status(self, payment_hash):
@ -552,11 +553,13 @@ class LNWorker(PrintError):
+ routing_hints), + routing_hints),
self.node_keypair.privkey) self.node_keypair.privkey)
self.save_invoice(payment_hash, invoice, RECEIVED) self.save_invoice(payment_hash, invoice, RECEIVED)
self.save_preimage(payment_hash, payment_preimage, 0) self.save_preimage(payment_hash, payment_preimage, timestamp=None)
return invoice return invoice
def save_preimage(self, payment_hash:bytes, preimage:bytes, timestamp:int): def save_preimage(self, payment_hash: bytes, preimage: bytes, *, timestamp: Optional[int]):
assert sha256(preimage) == payment_hash assert sha256(preimage) == payment_hash
if timestamp is not None:
timestamp = int(timestamp)
key = bh2u(payment_hash) key = bh2u(payment_hash)
self.preimages[key] = bh2u(preimage), timestamp self.preimages[key] = bh2u(preimage), timestamp
self.storage.put('lightning_preimages', self.preimages) self.storage.put('lightning_preimages', self.preimages)

Loading…
Cancel
Save