mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-31 01:11:35 +00:00
lnworker: minor clean-up re payment_completed
This commit is contained in:
parent
11c0c0d5a1
commit
962628ac3d
3 changed files with 12 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue