follow-up invoice changes: fix "Add lightning invoice to bitcoin URIs"
follow-up 719b468eee
This commit is contained in:
@@ -166,27 +166,6 @@ class BaseInvoice(StoredObject):
|
|||||||
return amount_msat
|
return amount_msat
|
||||||
return int(amount_msat // 1000)
|
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
|
@amount_msat.validator
|
||||||
def _validate_amount(self, attribute, value):
|
def _validate_amount(self, attribute, value):
|
||||||
if value is None:
|
if value is None:
|
||||||
@@ -316,6 +295,30 @@ class Request(BaseInvoice):
|
|||||||
assert self.is_lightning()
|
assert self.is_lightning()
|
||||||
return self.payment_hash.hex()
|
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:
|
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)
|
outputs_str = "\n".join(f"{txout.scriptpubkey.hex()}, {txout.value}" for txout in outputs)
|
||||||
|
|||||||
@@ -2362,8 +2362,10 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
|||||||
raise Exception("this wallet cannot delete addresses")
|
raise Exception("this wallet cannot delete addresses")
|
||||||
|
|
||||||
def get_request_URI(self, req: Request) -> Optional[str]:
|
def get_request_URI(self, req: Request) -> Optional[str]:
|
||||||
include_lightning = bool(self.config.get('bip21_lightning', False))
|
lightning_invoice = None
|
||||||
return req.get_bip21_URI(include_lightning=include_lightning)
|
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):
|
def check_expired_status(self, r: BaseInvoice, status):
|
||||||
#if r.is_lightning() and r.exp == 0:
|
#if r.is_lightning() and r.exp == 0:
|
||||||
|
|||||||
Reference in New Issue
Block a user