commit 962628ac3d3d409a124c10f0b11960829cc575df
parent 11c0c0d5a1eb03680ef88926f2d15b60f4a95bd2
Author: SomberNight <somber.night@protonmail.com>
Date: Tue, 26 Feb 2019 16:31:09 +0100
lnworker: minor clean-up re payment_completed
Diffstat:
3 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/electrum/gui/qt/request_list.py b/electrum/gui/qt/request_list.py
@@ -178,7 +178,7 @@ class RequestList(MyTreeView):
if request_type == REQUEST_TYPE_BITCOIN:
req = self.wallet.receive_requests.get(addr)
elif request_type == REQUEST_TYPE_LN:
- req = self.wallet.lnworker.invoices[addr][1]
+ req = self.wallet.lnworker.invoices[addr][0]
if req is None:
self.update()
return
diff --git a/electrum/lnchannel.py b/electrum/lnchannel.py
@@ -119,7 +119,8 @@ class Channel(PrintError):
except:
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 = {}
if not payment_completed:
payment_completed = lambda this, x, y, z: None
diff --git a/electrum/lnworker.py b/electrum/lnworker.py
@@ -125,11 +125,12 @@ class LNWorker(PrintError):
self.storage.write()
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
- preimage = _preimage if _preimage else self.get_preimage(htlc.payment_hash)
- timestamp = time.time()
- self.save_preimage(htlc.payment_hash, preimage, timestamp)
+ preimage = preimage if preimage else self.get_preimage(htlc.payment_hash)
+ timestamp = int(time.time())
+ self.save_preimage(htlc.payment_hash, preimage, timestamp=timestamp)
self.network.trigger_callback('ln_payment_completed', timestamp, direction, htlc, preimage, chan_id)
def get_invoice_status(self, payment_hash):
@@ -552,11 +553,13 @@ class LNWorker(PrintError):
+ routing_hints),
self.node_keypair.privkey)
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
- 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
+ if timestamp is not None:
+ timestamp = int(timestamp)
key = bh2u(payment_hash)
self.preimages[key] = bh2u(preimage), timestamp
self.storage.put('lightning_preimages', self.preimages)