SomberNight
4 years ago
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
3 changed files with
13 additions and
10 deletions
-
electrum/gui/qt/main_window.py
-
electrum/invoices.py
-
electrum/lnaddr.py
|
|
@ -79,7 +79,7 @@ from electrum.exchange_rate import FxThread |
|
|
|
from electrum.simple_config import SimpleConfig |
|
|
|
from electrum.logging import Logger |
|
|
|
from electrum.lnutil import ln_dummy_address, extract_nodeid, ConnStringFormatError |
|
|
|
from electrum.lnaddr import lndecode, LnDecodeException, LnAddressError |
|
|
|
from electrum.lnaddr import lndecode, LnDecodeException |
|
|
|
|
|
|
|
from .exception_window import Exception_Hook |
|
|
|
from .amountedit import AmountEdit, BTCAmountEdit, FreezableLineEdit, FeerateEdit |
|
|
@ -1240,7 +1240,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): |
|
|
|
if not key: |
|
|
|
return |
|
|
|
self.address_list.update() |
|
|
|
except (InvoiceError, LnAddressError) as e: |
|
|
|
except InvoiceError as e: |
|
|
|
self.show_error(_('Error creating payment request') + ':\n' + str(e)) |
|
|
|
return |
|
|
|
|
|
|
|
|
|
@ -212,7 +212,14 @@ class LNInvoice(Invoice): |
|
|
|
|
|
|
|
@classmethod |
|
|
|
def from_bech32(cls, invoice: str) -> 'LNInvoice': |
|
|
|
amount_msat = lndecode(invoice).get_amount_msat() |
|
|
|
"""Constructs LNInvoice object from BOLT-11 string. |
|
|
|
Might raise InvoiceError. |
|
|
|
""" |
|
|
|
try: |
|
|
|
lnaddr = lndecode(invoice) |
|
|
|
except Exception as e: |
|
|
|
raise InvoiceError(e) from e |
|
|
|
amount_msat = lnaddr.get_amount_msat() |
|
|
|
return LNInvoice( |
|
|
|
type=PR_TYPE_LN, |
|
|
|
invoice=invoice, |
|
|
|
|
|
@ -22,10 +22,6 @@ if TYPE_CHECKING: |
|
|
|
from .lnutil import LnFeatures |
|
|
|
|
|
|
|
|
|
|
|
class LnAddressError(Exception): |
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
# BOLT #11: |
|
|
|
# |
|
|
|
# A writer MUST encode `amount` as a positive decimal integer with no |
|
|
@ -291,16 +287,16 @@ class LnAddr(object): |
|
|
|
@amount.setter |
|
|
|
def amount(self, value): |
|
|
|
if not (isinstance(value, Decimal) or value is None): |
|
|
|
raise LnAddressError(f"amount must be Decimal or None, not {value!r}") |
|
|
|
raise ValueError(f"amount must be Decimal or None, not {value!r}") |
|
|
|
if value is None: |
|
|
|
self._amount = None |
|
|
|
return |
|
|
|
assert isinstance(value, Decimal) |
|
|
|
if value.is_nan() or not (0 <= value <= TOTAL_COIN_SUPPLY_LIMIT_IN_BTC): |
|
|
|
raise LnAddressError(f"amount is out-of-bounds: {value!r} BTC") |
|
|
|
raise ValueError(f"amount is out-of-bounds: {value!r} BTC") |
|
|
|
if value * 10**12 % 10: |
|
|
|
# max resolution is millisatoshi |
|
|
|
raise LnAddressError(f"Cannot encode {value!r}: too many decimal places") |
|
|
|
raise ValueError(f"Cannot encode {value!r}: too many decimal places") |
|
|
|
self._amount = value |
|
|
|
|
|
|
|
def get_amount_sat(self) -> Optional[Decimal]: |
|
|
|