fix: return preimages for Phoenixd invoices and settled payments (#4068)
Some checks are pending
codeql / analyze (push) Waiting to run

This commit is contained in:
Rob 2026-07-22 01:33:22 +09:00 committed by GitHub
parent f3f5c89113
commit 2223733c2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 3 deletions

View file

@ -632,7 +632,7 @@ async def check_transaction_status(
return PaymentPendingStatus()
if payment.status == PaymentState.SUCCESS.value:
return PaymentSuccessStatus(fee_msat=payment.fee)
return PaymentSuccessStatus(fee_msat=payment.fee, preimage=payment.preimage)
return await check_payment_status(payment)
@ -640,7 +640,7 @@ async def check_transaction_status(
async def check_payment_status(payment: Payment) -> PaymentStatus:
if payment.is_internal:
if payment.success:
return PaymentSuccessStatus()
return PaymentSuccessStatus(fee_msat=payment.fee, preimage=payment.preimage)
if payment.failed:
return PaymentFailedStatus()
if payment.is_in and payment.fiat_provider:

View file

@ -98,6 +98,24 @@ class PhoenixdWallet(Wallet):
logger.warning(exc)
return StatusResponse(f"Unable to connect to {self.endpoint}.", 0)
async def _incoming_preimage(self, payment_hash: str) -> str | None:
"""Fetch preimage from Phoenixd incoming payment (createinvoice omits it)."""
try:
r = await self.client.get(
f"/payments/incoming/{payment_hash}",
timeout=40,
)
if r.is_error:
return None
return r.json().get("preimage") or None
except Exception as exc:
logger.warning(
"Phoenixd: could not fetch preimage for %s: %s",
payment_hash,
exc,
)
return None
async def create_invoice(
self,
amount: int,
@ -147,7 +165,10 @@ class PhoenixdWallet(Wallet):
checking_id = data["paymentHash"]
payment_request = data["serialized"]
preimage = data.get("paymentPreimage", None) # if available
# Phoenixd createinvoice often omits paymentPreimage.
preimage = data.get("paymentPreimage") or await self._incoming_preimage(
checking_id
)
return InvoiceResponse(
ok=True,
checking_id=checking_id,