1
0

payment_identifier: fix _on_finalize params, fix lnurlp send comment instead of description,

refactor payment_identifier.get_invoice to standalone invoice_from_payment_identifier
This commit is contained in:
Sander van Grieken
2023-07-11 14:15:17 +02:00
parent b6863b4854
commit d15050a2bf
2 changed files with 32 additions and 24 deletions

View File

@@ -370,7 +370,7 @@ class PaymentIdentifier(Logger):
on_finished: Callable[['PaymentIdentifier'], None] = None,
):
assert self._state == PaymentIdentifierState.LNURLP_FINALIZE
coro = self._do_finalize(amount_sat, comment, on_finished=on_finished)
coro = self._do_finalize(amount_sat=amount_sat, comment=comment, on_finished=on_finished)
asyncio.run_coroutine_threadsafe(coro, get_asyncio_loop())
@log_exceptions
@@ -665,22 +665,28 @@ class PaymentIdentifier(Logger):
return bool(expires) and expires < time.time()
return False
def get_invoice(self, amount_sat, message):
# FIXME: this should not be a PI method
# ideally, PI should not have a reference to wallet.
if self.is_lightning():
invoice = self.bolt11
if not invoice:
return
if invoice.amount_msat is None:
invoice.amount_msat = int(amount_sat * 1000)
return invoice
else:
outputs = self.get_onchain_outputs(amount_sat)
message = self.bip21.get('message') if self.bip21 else message
bip70_data = self.bip70_data if self.bip70 else None
return self.wallet.create_invoice(
outputs=outputs,
message=message,
pr=bip70_data,
URI=self.bip21)
def invoice_from_payment_identifier(
pi: 'PaymentIdentifier',
wallet: 'Abstract_Wallet',
amount_sat: int,
message: str = None
):
# FIXME: this should not be a PI method
# ideally, PI should not have a reference to wallet.
if pi.is_lightning():
invoice = pi.bolt11
if not invoice:
return
if invoice.amount_msat is None:
invoice.amount_msat = int(amount_sat * 1000)
return invoice
else:
outputs = pi.get_onchain_outputs(amount_sat)
message = pi.bip21.get('message') if pi.bip21 else message
bip70_data = self.bip70_data if self.bip70 else None
return wallet.create_invoice(
outputs=outputs,
message=message,
pr=bip70_data,
URI=pi.bip21)