Browse Source

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

follow-up 719b468eee
master
SomberNight 3 years ago
parent
commit
81bd6f7d1b
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 45
      electrum/invoices.py
  2. 6
      electrum/wallet.py

45
electrum/invoices.py

@ -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)

6
electrum/wallet.py

@ -2362,8 +2362,10 @@ class Abstract_Wallet(ABC, Logger, EventListener):
raise Exception("this wallet cannot delete addresses")
def get_request_URI(self, req: Request) -> Optional[str]:
include_lightning = bool(self.config.get('bip21_lightning', False))
return req.get_bip21_URI(include_lightning=include_lightning)
lightning_invoice = None
if self.config.get('bip21_lightning', False):
lightning_invoice = self.get_bolt11_invoice(req)
return req.get_bip21_URI(lightning_invoice=lightning_invoice)
def check_expired_status(self, r: BaseInvoice, status):
#if r.is_lightning() and r.exp == 0:

Loading…
Cancel
Save