payment_identifier: if a bip21 uri contains a lightning invoice without fallback address,
and an address is present in the bip21 uri path, register the on-chain address in the Invoice.outputs field to allow paying onchain from a saved Invoice later (when the PI is unavailable). Fixes #8654
This commit is contained in:
@@ -304,7 +304,7 @@ class Invoice(BaseInvoice):
|
|||||||
|
|
||||||
def can_be_paid_onchain(self) -> bool:
|
def can_be_paid_onchain(self) -> bool:
|
||||||
if self.is_lightning():
|
if self.is_lightning():
|
||||||
return bool(self._lnaddr.get_fallback_address())
|
return bool(self._lnaddr.get_fallback_address()) or (bool(self.outputs))
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
@@ -257,6 +257,11 @@ class PaymentIdentifier(Logger):
|
|||||||
if bolt11:
|
if bolt11:
|
||||||
try:
|
try:
|
||||||
self.bolt11 = Invoice.from_bech32(bolt11)
|
self.bolt11 = Invoice.from_bech32(bolt11)
|
||||||
|
# carry BIP21 onchain address in Invoice.outputs in case bolt11 doesn't contain a fallback
|
||||||
|
# address but the BIP21 URI has one.
|
||||||
|
if bip21_address := self.bip21.get('address'):
|
||||||
|
amount = self.bip21.get('amount', 0)
|
||||||
|
self.bolt11.outputs = [PartialTxOutput.from_address_and_value(bip21_address, amount)]
|
||||||
except InvoiceError as e:
|
except InvoiceError as e:
|
||||||
self.logger.debug(self._get_error_from_invoiceerror(e))
|
self.logger.debug(self._get_error_from_invoiceerror(e))
|
||||||
self.set_state(PaymentIdentifierState.AVAILABLE)
|
self.set_state(PaymentIdentifierState.AVAILABLE)
|
||||||
|
|||||||
Reference in New Issue
Block a user