1
0

follow-up invoice changes: fix "Add lightning invoice to bitcoin URIs"

follow-up 719b468eee
This commit is contained in:
SomberNight
2023-03-03 16:14:35 +00:00
parent 9e81aba578
commit 81bd6f7d1b
2 changed files with 28 additions and 23 deletions

View File

@@ -166,27 +166,6 @@ class BaseInvoice(StoredObject):
return amount_msat
return int(amount_msat // 1000)
def get_bip21_URI(self, *, include_lightning: bool = False) -> Optional[str]:
from electrum.util import create_bip21_uri
addr = self.get_address()
amount = self.get_amount_sat()
if amount is not None:
amount = int(amount)
message = self.message
extra = {}
if self.time and self.exp:
extra['time'] = str(int(self.time))
extra['exp'] = str(int(self.exp))
lightning = self.lightning_invoice if include_lightning else None
if lightning:
extra['lightning'] = lightning
if not addr and lightning:
return "bitcoin:?lightning="+lightning
if not addr and not lightning:
return None
uri = create_bip21_uri(addr, amount, message, extra_query_params=extra)
return str(uri)
@amount_msat.validator
def _validate_amount(self, attribute, value):
if value is None:
@@ -316,6 +295,30 @@ class Request(BaseInvoice):
assert self.is_lightning()
return self.payment_hash.hex()
def get_bip21_URI(
self,
*,
lightning_invoice: Optional[str] = None,
) -> Optional[str]:
from electrum.util import create_bip21_uri
addr = self.get_address()
amount = self.get_amount_sat()
if amount is not None:
amount = int(amount)
message = self.message
extra = {}
if self.time and self.exp:
extra['time'] = str(int(self.time))
extra['exp'] = str(int(self.exp))
if lightning_invoice:
extra['lightning'] = lightning_invoice
if not addr and lightning_invoice:
return "bitcoin:?lightning="+lightning_invoice
if not addr and not lightning_invoice:
return None
uri = create_bip21_uri(addr, amount, message, extra_query_params=extra)
return str(uri)
def get_id_from_onchain_outputs(outputs: Sequence[PartialTxOutput], *, timestamp: int) -> str:
outputs_str = "\n".join(f"{txout.scriptpubkey.hex()}, {txout.value}" for txout in outputs)