refactor: simplify logic

This commit is contained in:
Vlad Stan 2025-05-30 14:01:49 +03:00
parent b89e30896f
commit a7c72577cf

View File

@ -200,15 +200,17 @@ async def invoice_callback_dispatcher(checking_id: str, is_internal: bool = Fals
invoice_listeners from core and extensions.
"""
payment = await get_standalone_payment(checking_id, incoming=True)
if payment and payment.is_in:
status = await payment.check_status()
payment.fee = status.fee_msat or 0
# only overwrite preimage if status.preimage provides it
payment.preimage = status.preimage or payment.preimage
payment.status = PaymentState.SUCCESS
await update_payment(payment)
internal = "internal" if is_internal else ""
logger.success(f"{internal} invoice {checking_id} settled")
for name, send_chan in invoice_listeners.items():
logger.trace(f"invoice listeners: sending to `{name}`")
await send_chan.put(payment)
if not payment or payment.is_out:
return
status = await payment.check_status()
payment.fee = status.fee_msat or 0
# only overwrite preimage if status.preimage provides it
payment.preimage = status.preimage or payment.preimage
payment.status = PaymentState.SUCCESS
await update_payment(payment)
internal = "internal" if is_internal else ""
logger.success(f"{internal} invoice {checking_id} settled")
for name, send_chan in invoice_listeners.items():
logger.trace(f"invoice listeners: sending to `{name}`")
await send_chan.put(payment)