Merge pull request #10614 from f321x/lnaddr_rename
bolt11: rename *lnaddr* -> *bolt11*
This commit is contained in:
+3
-3
@@ -7,7 +7,7 @@ from typing import Optional
|
||||
from . import bitcoin
|
||||
from .util import format_satoshis_plain
|
||||
from .bitcoin import COIN, TOTAL_COIN_SUPPLY_LIMIT_IN_BTC
|
||||
from .lnaddr import lndecode, LnDecodeException
|
||||
from .bolt11 import decode_bolt11_invoice, BOLT11DecodeException
|
||||
|
||||
# note: when checking against these, use .lower() to support case-insensitivity
|
||||
BITCOIN_BIP21_URI_SCHEME = 'bitcoin'
|
||||
@@ -93,8 +93,8 @@ def parse_bip21_URI(uri: str) -> dict:
|
||||
raise InvalidBitcoinURI(f"failed to parse 'sig' field: {repr(e)}") from e
|
||||
if 'lightning' in out:
|
||||
try:
|
||||
lnaddr = lndecode(out['lightning'])
|
||||
except LnDecodeException as e:
|
||||
lnaddr = decode_bolt11_invoice(out['lightning'])
|
||||
except BOLT11DecodeException as e:
|
||||
raise InvalidBitcoinURI(f"Failed to decode 'lightning' field: {e!r}") from e
|
||||
amount_sat = out.get('amount')
|
||||
if amount_sat:
|
||||
|
||||
@@ -23,9 +23,9 @@ if TYPE_CHECKING:
|
||||
from .lnutil import LnFeatures
|
||||
|
||||
|
||||
class LnInvoiceException(Exception): pass
|
||||
class LnDecodeException(LnInvoiceException): pass
|
||||
class LnEncodeException(LnInvoiceException): pass
|
||||
class BOLT11InvoiceException(Exception): pass
|
||||
class BOLT11DecodeException(BOLT11InvoiceException): pass
|
||||
class BOLT11EncodeException(BOLT11InvoiceException): pass
|
||||
|
||||
|
||||
# BOLT #11:
|
||||
@@ -68,7 +68,7 @@ def unshorten_amount(amount) -> Decimal:
|
||||
# A reader SHOULD fail if `amount` contains a non-digit, or is followed by
|
||||
# anything except a `multiplier` in the table above.
|
||||
if not re.fullmatch("\\d+[pnum]?", str(amount)):
|
||||
raise LnDecodeException("Invalid amount '{}'".format(amount))
|
||||
raise BOLT11DecodeException("Invalid amount '{}'".format(amount))
|
||||
|
||||
if unit in units.keys():
|
||||
return Decimal(amount[:-1]) / units[unit]
|
||||
@@ -88,7 +88,7 @@ def encode_fallback_addr(fallback: str, net: Type[AbstractNet]) -> Sequence[int]
|
||||
elif addrtype == net.ADDRTYPE_P2SH:
|
||||
wver = 18
|
||||
else:
|
||||
raise LnEncodeException(f"Unknown address type {addrtype} for {net}")
|
||||
raise BOLT11EncodeException(f"Unknown address type {addrtype} for {net}")
|
||||
wprog = addr
|
||||
data5 = convertbits(wprog, 8, 5)
|
||||
assert data5 is not None
|
||||
@@ -156,7 +156,7 @@ def pull_tagged(data5: bytearray) -> Tuple[str, Sequence[int]]:
|
||||
return ret
|
||||
|
||||
|
||||
def lnencode(addr: 'LnAddr', privkey) -> str:
|
||||
def encode_bolt11_invoice(addr: 'BOLT11Addr', privkey) -> str:
|
||||
if addr.amount:
|
||||
amount = addr.net.BOLT11_HRP + shorten_amount(addr.amount)
|
||||
else:
|
||||
@@ -185,7 +185,7 @@ def lnencode(addr: 'LnAddr', privkey) -> str:
|
||||
# A writer MUST NOT include more than one `d`, `h`, `n` or `x` fields,
|
||||
if k in ('d', 'h', 'n', 'x', 'p', 's', '9'):
|
||||
if k in tags_set:
|
||||
raise LnEncodeException("Duplicate '{}' tag".format(k))
|
||||
raise BOLT11EncodeException("Duplicate '{}' tag".format(k))
|
||||
|
||||
if k == 'r':
|
||||
route = bytearray()
|
||||
@@ -228,7 +228,7 @@ def lnencode(addr: 'LnAddr', privkey) -> str:
|
||||
data5 += tagged5('9', feature_bits)
|
||||
else:
|
||||
# FIXME: Support unknown tags?
|
||||
raise LnEncodeException("Unknown tag {}".format(k))
|
||||
raise BOLT11EncodeException("Unknown tag {}".format(k))
|
||||
|
||||
tags_set.add(k)
|
||||
|
||||
@@ -254,7 +254,7 @@ def lnencode(addr: 'LnAddr', privkey) -> str:
|
||||
return bech32_encode(segwit_addr.Encoding.BECH32, hrp, data5)
|
||||
|
||||
|
||||
class LnAddr(object):
|
||||
class BOLT11Addr:
|
||||
def __init__(self, *, paymenthash: bytes = None, amount=None, net: Type[AbstractNet] = None, tags=None, date=None,
|
||||
payment_secret: bytes = None):
|
||||
self.date = int(time.time()) if not date else int(date)
|
||||
@@ -274,16 +274,16 @@ class LnAddr(object):
|
||||
@amount.setter
|
||||
def amount(self, value):
|
||||
if not (isinstance(value, Decimal) or value is None):
|
||||
raise LnInvoiceException(f"amount must be Decimal or None, not {value!r}")
|
||||
raise BOLT11InvoiceException(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 LnInvoiceException(f"amount is out-of-bounds: {value!r} BTC")
|
||||
raise BOLT11InvoiceException(f"amount is out-of-bounds: {value!r} BTC")
|
||||
if value * 10**12 % 10:
|
||||
# max resolution is millisatoshi
|
||||
raise LnInvoiceException(f"Cannot encode {value!r}: too many decimal places")
|
||||
raise BOLT11InvoiceException(f"Cannot encode {value!r}: too many decimal places")
|
||||
self._amount = value
|
||||
|
||||
def get_amount_sat(self) -> Optional[Decimal]:
|
||||
@@ -332,7 +332,8 @@ class LnAddr(object):
|
||||
def validate_and_compare_features(self, myfeatures: 'LnFeatures') -> None:
|
||||
"""Raises IncompatibleOrInsaneFeatures.
|
||||
|
||||
note: these checks are not done by the parser (in lndecode), as then when we started requiring a new feature,
|
||||
note: these checks are not done by the parser (in decode_bolt11_invoice),
|
||||
as then when we started requiring a new feature,
|
||||
old saved already paid invoices could no longer be parsed.
|
||||
"""
|
||||
from .lnutil import validate_features, ln_compare_features
|
||||
@@ -341,7 +342,7 @@ class LnAddr(object):
|
||||
ln_compare_features(myfeatures.for_invoice(), invoice_features)
|
||||
|
||||
def __str__(self):
|
||||
return "LnAddr[{}, amount={}{} tags=[{}]]".format(
|
||||
return "BOLT11Addr[{}, amount={}{} tags=[{}]]".format(
|
||||
hexlify(self.pubkey.serialize()).decode('utf-8') if self.pubkey else None,
|
||||
self.amount, self.net.BOLT11_HRP,
|
||||
", ".join([k + '=' + str(v) for k, v in self.tags])
|
||||
@@ -403,9 +404,9 @@ class SerializableKey:
|
||||
return self.pubkey.get_public_key_bytes(True)
|
||||
|
||||
|
||||
def lndecode(invoice: str, *, verbose=False, net=None) -> LnAddr:
|
||||
"""Parses a string into an LnAddr object.
|
||||
Can raise LnDecodeException or IncompatibleOrInsaneFeatures.
|
||||
def decode_bolt11_invoice(invoice: str, *, verbose=False, net=None) -> BOLT11Addr:
|
||||
"""Parses a string into a BOLT11Addr object.
|
||||
Can raise BOLT11DecodeException or IncompatibleOrInsaneFeatures.
|
||||
"""
|
||||
if net is None:
|
||||
net = constants.net
|
||||
@@ -413,27 +414,27 @@ def lndecode(invoice: str, *, verbose=False, net=None) -> LnAddr:
|
||||
hrp = decoded_bech32.hrp
|
||||
data5 = decoded_bech32.data # "5" as in list of 5-bit integers
|
||||
if decoded_bech32.encoding is None:
|
||||
raise LnDecodeException("Bad bech32 checksum")
|
||||
raise BOLT11DecodeException("Bad bech32 checksum")
|
||||
if decoded_bech32.encoding != segwit_addr.Encoding.BECH32:
|
||||
raise LnDecodeException("Bad bech32 encoding: must be using vanilla BECH32")
|
||||
raise BOLT11DecodeException("Bad bech32 encoding: must be using vanilla BECH32")
|
||||
|
||||
# BOLT #11:
|
||||
#
|
||||
# A reader MUST fail if it does not understand the `prefix`.
|
||||
if not hrp.startswith('ln'):
|
||||
raise LnDecodeException("Does not start with ln")
|
||||
raise BOLT11DecodeException("Does not start with ln")
|
||||
|
||||
if not hrp[2:].startswith(net.BOLT11_HRP):
|
||||
raise LnDecodeException(f"Wrong Lightning invoice HRP {hrp[2:]}, should be {net.BOLT11_HRP}")
|
||||
raise BOLT11DecodeException(f"Wrong Lightning invoice HRP {hrp[2:]}, should be {net.BOLT11_HRP}")
|
||||
|
||||
# Final signature 65 bytes, split it off.
|
||||
if len(data5) < 65*8//5:
|
||||
raise LnDecodeException("Too short to contain signature")
|
||||
raise BOLT11DecodeException("Too short to contain signature")
|
||||
sigdecoded = bytes(convertbits(data5[-65*8//5:], 5, 8, False))
|
||||
data5 = data5[:-65*8//5]
|
||||
data5_remaining = bytearray(data5) # note: bytearray is faster than list of ints
|
||||
|
||||
addr = LnAddr()
|
||||
addr = BOLT11Addr()
|
||||
addr.pubkey = None
|
||||
addr.net = net
|
||||
|
||||
@@ -580,7 +581,7 @@ def lndecode(invoice: str, *, verbose=False, net=None) -> LnAddr:
|
||||
# A reader MUST use the `n` field to validate the signature instead of
|
||||
# performing signature recovery if a valid `n` field is provided.
|
||||
if not ecc.ECPubkey(addr.pubkey).ecdsa_verify(sigdecoded[:64], hrp_hash):
|
||||
raise LnDecodeException("bad signature")
|
||||
raise BOLT11DecodeException("bad signature")
|
||||
pubkey_copy = addr.pubkey
|
||||
|
||||
class WrappedBytesKey:
|
||||
@@ -3,16 +3,12 @@ from typing import TYPE_CHECKING, Sequence
|
||||
import PyQt6.QtGui as QtGui
|
||||
import PyQt6.QtWidgets as QtWidgets
|
||||
import PyQt6.QtCore as QtCore
|
||||
from PyQt6.QtWidgets import QLabel, QLineEdit, QHBoxLayout, QGridLayout
|
||||
from PyQt6.QtWidgets import QLabel, QHBoxLayout
|
||||
|
||||
from electrum.util import EventListener, ShortID
|
||||
from electrum.util import ShortID
|
||||
from electrum.i18n import _
|
||||
from electrum.util import format_time
|
||||
from electrum.lnutil import format_short_channel_id, LOCAL, REMOTE, UpdateAddHtlc, Direction
|
||||
from electrum.lnchannel import htlcsum, Channel, AbstractChannel, HTLCWithStatus
|
||||
from electrum.lnaddr import LnAddr, lndecode
|
||||
from electrum.bitcoin import COIN
|
||||
from electrum.wallet import Abstract_Wallet
|
||||
from electrum.lnutil import LOCAL, REMOTE, UpdateAddHtlc, Direction
|
||||
from electrum.lnchannel import Channel, AbstractChannel, HTLCWithStatus
|
||||
|
||||
from electrum.gui.common_qt.util import QtEventListener, qt_event_listener
|
||||
from .util import Buttons, CloseButton, ShowQRLineEdit, MessageBoxMixin, WWLabel, VLine
|
||||
|
||||
@@ -73,7 +73,7 @@ from electrum.exchange_rate import FxThread
|
||||
from electrum.simple_config import SimpleConfig
|
||||
from electrum.logging import Logger
|
||||
from electrum.lntransport import extract_nodeid, ConnStringFormatError
|
||||
from electrum.lnaddr import lndecode, LnAddr
|
||||
from electrum.bolt11 import decode_bolt11_invoice, BOLT11Addr
|
||||
from electrum.submarine_swaps import SwapServerTransport, NostrTransport
|
||||
from electrum.fee_policy import FeePolicy
|
||||
|
||||
@@ -1678,7 +1678,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
|
||||
|
||||
def show_lightning_invoice(self, invoice: Invoice):
|
||||
from electrum.util import format_short_id
|
||||
lnaddr = lndecode(invoice.lightning_invoice)
|
||||
lnaddr = decode_bolt11_invoice(invoice.lightning_invoice)
|
||||
d = WindowModalDialog(self, _("Lightning Invoice"))
|
||||
vbox = QVBoxLayout(d)
|
||||
grid = QGridLayout()
|
||||
@@ -1713,7 +1713,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
|
||||
grid.addWidget(QLabel(_('Text') + ':'), 8, 0)
|
||||
grid.addWidget(invoice_e, 8, 1)
|
||||
r_tags = lnaddr.get_routing_info('r')
|
||||
r_tags = '\n'.join(repr(r) for r in LnAddr.format_bolt11_routing_info_as_human_readable(r_tags))
|
||||
r_tags = '\n'.join(repr(r) for r in BOLT11Addr.format_bolt11_routing_info_as_human_readable(r_tags))
|
||||
routing_e = QTextEdit(str(r_tags))
|
||||
routing_e.setReadOnly(True)
|
||||
grid.addWidget(QLabel(_("Routing Hints") + ':'), 9, 0)
|
||||
|
||||
@@ -50,9 +50,9 @@ def parse_bip21(text):
|
||||
|
||||
|
||||
def parse_bolt11(text):
|
||||
from electrum.lnaddr import lndecode
|
||||
from electrum.bolt11 import decode_bolt11_invoice
|
||||
try:
|
||||
return lndecode(text)
|
||||
return decode_bolt11_invoice(text)
|
||||
except Exception:
|
||||
return
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ from .i18n import _
|
||||
from .util import age, InvoiceError, format_satoshis
|
||||
from .bip21 import create_bip21_uri
|
||||
from .lnutil import hex_to_bytes
|
||||
from .lnaddr import lndecode, LnAddr
|
||||
from .bolt11 import decode_bolt11_invoice, BOLT11Addr
|
||||
from . import constants
|
||||
from .bitcoin import COIN, TOTAL_COIN_SUPPLY_LIMIT_IN_BTC
|
||||
from .bitcoin import address_to_script
|
||||
@@ -213,7 +213,7 @@ class BaseInvoice(StoredObject):
|
||||
Might raise InvoiceError.
|
||||
"""
|
||||
try:
|
||||
lnaddr = lndecode(invoice)
|
||||
lnaddr = decode_bolt11_invoice(invoice)
|
||||
except Exception as e:
|
||||
raise InvoiceError(e) from e
|
||||
amount_msat = lnaddr.get_amount_msat()
|
||||
@@ -275,9 +275,9 @@ class Invoice(BaseInvoice):
|
||||
return address
|
||||
|
||||
@property
|
||||
def _lnaddr(self) -> LnAddr:
|
||||
def _lnaddr(self) -> BOLT11Addr:
|
||||
if self.__lnaddr is None:
|
||||
self.__lnaddr = lndecode(self.lightning_invoice)
|
||||
self.__lnaddr = decode_bolt11_invoice(self.lightning_invoice)
|
||||
return self.__lnaddr
|
||||
|
||||
@property
|
||||
@@ -288,7 +288,7 @@ class Invoice(BaseInvoice):
|
||||
@lightning_invoice.validator
|
||||
def _validate_invoice_str(self, attribute, value):
|
||||
if value is not None:
|
||||
lnaddr = lndecode(value) # this checks the str can be decoded
|
||||
lnaddr = decode_bolt11_invoice(value) # this checks the str can be decoded
|
||||
self.__lnaddr = lnaddr # save it, just to avoid having to recompute later
|
||||
|
||||
def can_be_paid_onchain(self) -> bool:
|
||||
|
||||
+5
-5
@@ -12,7 +12,7 @@ import aiohttp.client_exceptions
|
||||
|
||||
from electrum import segwit_addr, util
|
||||
from electrum.segwit_addr import bech32_decode, Encoding, convertbits, bech32_encode
|
||||
from electrum.lnaddr import LnDecodeException, LnEncodeException
|
||||
from electrum.bolt11 import BOLT11DecodeException, BOLT11EncodeException
|
||||
from electrum.network import Network
|
||||
from electrum.logging import get_logger
|
||||
from electrum.i18n import _
|
||||
@@ -47,11 +47,11 @@ def decode_lnurl(lnurl: str) -> str:
|
||||
hrp = decoded_bech32.hrp
|
||||
data = decoded_bech32.data
|
||||
if decoded_bech32.encoding is None:
|
||||
raise LnDecodeException("Bad bech32 checksum")
|
||||
raise BOLT11DecodeException("Bad bech32 checksum")
|
||||
if decoded_bech32.encoding != Encoding.BECH32:
|
||||
raise LnDecodeException("Bad bech32 encoding: must be using vanilla BECH32")
|
||||
raise BOLT11DecodeException("Bad bech32 encoding: must be using vanilla BECH32")
|
||||
if not hrp.startswith("lnurl"):
|
||||
raise LnDecodeException("Does not start with lnurl")
|
||||
raise BOLT11DecodeException("Does not start with lnurl")
|
||||
data = convertbits(data, 5, 8, False)
|
||||
url = bytes(data).decode("utf-8")
|
||||
return url
|
||||
@@ -62,7 +62,7 @@ def encode_lnurl(url: str) -> str:
|
||||
try:
|
||||
url = url.encode("utf-8")
|
||||
except UnicodeError as e:
|
||||
raise LnEncodeException("invalid url") from e
|
||||
raise BOLT11EncodeException("invalid url") from e
|
||||
bech32_data = convertbits(url, 8, 5, True)
|
||||
assert bech32_data
|
||||
lnurl = bech32_encode(
|
||||
|
||||
+11
-11
@@ -64,7 +64,7 @@ from .lntransport import (
|
||||
ConnStringFormatError
|
||||
)
|
||||
from .lnpeer import Peer, LN_P2P_NETWORK_TIMEOUT
|
||||
from .lnaddr import lnencode, LnAddr, lndecode
|
||||
from .bolt11 import encode_bolt11_invoice, BOLT11Addr, decode_bolt11_invoice
|
||||
from .lnchannel import Channel, AbstractChannel, ChannelState, PeerState, HTLCWithStatus, ChannelBackup
|
||||
from .lnrater import LNRater
|
||||
from .lnutil import (
|
||||
@@ -123,7 +123,7 @@ class PaymentInfo:
|
||||
|
||||
- Historically, we used to store "bolt11, direction, status", but deserializing bolt11 was too slow.
|
||||
(even deserializing just once - all bolt11 during wallet-open - was slow)
|
||||
- note: the deserialization code in lnaddr.py has been significantly sped up since
|
||||
- note: the deserialization code in bolt11.py has been significantly sped up since
|
||||
- For incoming payments, for unpaid requests, ~every time the user displays the unpaid bolt11,
|
||||
we get a chance to display a new bolt11, with same payment_hash/amount, but with updated
|
||||
routing_hints (channels might get closed/opened, or just liquidity changed drastically).
|
||||
@@ -1930,7 +1930,7 @@ class LNWallet(Logger):
|
||||
f"pay_to_node starting session for RHASH={payment_hash.hex()}. "
|
||||
f"using_trampoline={self.uses_trampoline()}. "
|
||||
f"invoice_features={paysession.invoice_features.get_names()}. "
|
||||
f"r_tags={LnAddr.format_bolt11_routing_info_as_human_readable(r_tags)}. "
|
||||
f"r_tags={BOLT11Addr.format_bolt11_routing_info_as_human_readable(r_tags)}. "
|
||||
f"{amount_to_pay=} msat. {budget=}")
|
||||
if not self.uses_trampoline():
|
||||
self.logger.info(
|
||||
@@ -2219,11 +2219,11 @@ class LNWallet(Logger):
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
def _check_bolt11_invoice(self, bolt11_invoice: str, *, amount_msat: int = None) -> LnAddr:
|
||||
"""Parses and validates a bolt11 invoice str into a LnAddr.
|
||||
def _check_bolt11_invoice(self, bolt11_invoice: str, *, amount_msat: int = None) -> BOLT11Addr:
|
||||
"""Parses and validates a bolt11 invoice str into a BOLT11Addr.
|
||||
Includes pre-payment checks external to the parser.
|
||||
"""
|
||||
addr = lndecode(bolt11_invoice)
|
||||
addr = decode_bolt11_invoice(bolt11_invoice)
|
||||
if addr.is_expired():
|
||||
raise InvoiceError(_("This invoice has expired"))
|
||||
# check amount
|
||||
@@ -2563,7 +2563,7 @@ class LNWallet(Logger):
|
||||
message: str,
|
||||
fallback_address: Optional[str],
|
||||
channels: Optional[Sequence[Channel]] = None,
|
||||
) -> Tuple[LnAddr, str]:
|
||||
) -> Tuple[BOLT11Addr, str]:
|
||||
amount_msat = payment_info.amount_msat
|
||||
pair = self._bolt11_cache.get(payment_info.payment_hash)
|
||||
if pair:
|
||||
@@ -2580,12 +2580,12 @@ class LNWallet(Logger):
|
||||
# TODO: make invoice_features dynamic depending on available trampoline channels
|
||||
only_trampoline=payment_info.invoice_features.supports(LnFeatures.OPTION_TRAMPOLINE_ROUTING_OPT_ELECTRUM),
|
||||
)
|
||||
formatted_r_hints = LnAddr.format_bolt11_routing_info_as_human_readable(routing_hints, has_explicit_r_tagtype=True)
|
||||
formatted_r_hints = BOLT11Addr.format_bolt11_routing_info_as_human_readable(routing_hints, has_explicit_r_tagtype=True)
|
||||
self.logger.info(f"creating bolt11 invoice with routing_hints: {formatted_r_hints}, sat: {(amount_msat or 0) // 1000}")
|
||||
payment_secret = self.get_payment_secret(payment_info.payment_hash)
|
||||
amount_btc = amount_msat/Decimal(COIN*1000) if amount_msat else None
|
||||
min_final_cltv_delta = payment_info.min_final_cltv_delta + MIN_FINAL_CLTV_DELTA_BUFFER_INVOICE
|
||||
lnaddr = LnAddr(
|
||||
lnaddr = BOLT11Addr(
|
||||
paymenthash=payment_info.payment_hash,
|
||||
amount=amount_btc,
|
||||
tags=[
|
||||
@@ -2597,7 +2597,7 @@ class LNWallet(Logger):
|
||||
] + routing_hints,
|
||||
date=timestamp,
|
||||
payment_secret=payment_secret)
|
||||
invoice = lnencode(lnaddr, self.node_keypair.privkey)
|
||||
invoice = encode_bolt11_invoice(lnaddr, self.node_keypair.privkey)
|
||||
pair = lnaddr, invoice
|
||||
self._bolt11_cache[payment_info.payment_hash] = pair
|
||||
return pair
|
||||
@@ -3971,7 +3971,7 @@ class LNWallet(Logger):
|
||||
invoice_features = payload["invoice_features"]["invoice_features"]
|
||||
invoice_routing_info = payload["invoice_routing_info"]["invoice_routing_info"]
|
||||
r_tags = decode_routing_info(invoice_routing_info)
|
||||
self.logger.info(f'r_tags {LnAddr.format_bolt11_routing_info_as_human_readable(r_tags)}')
|
||||
self.logger.info(f'r_tags {BOLT11Addr.format_bolt11_routing_info_as_human_readable(r_tags)}')
|
||||
# TODO legacy mpp payment, use total_msat from trampoline onion
|
||||
else:
|
||||
self.logger.info('forward_trampoline: end-to-end')
|
||||
|
||||
@@ -18,7 +18,7 @@ from .lnurl import (decode_lnurl, request_lnurl, callback_lnurl, LNURLError,
|
||||
lightning_address_to_url, try_resolve_lnurlpay, LNURL6Data,
|
||||
LNURL3Data, LNURLData, SUPPORTED_LNURL_SCHEMES)
|
||||
from .bitcoin import opcodes, construct_script
|
||||
from .lnaddr import LnInvoiceException
|
||||
from .bolt11 import BOLT11InvoiceException
|
||||
from .lnutil import IncompatibleOrInsaneFeatures
|
||||
from .bip21 import parse_bip21_URI, InvalidBitcoinURI, LIGHTNING_URI_SCHEME, BITCOIN_BIP21_URI_SCHEME
|
||||
from .segwit_addr import bech32_decode
|
||||
@@ -520,7 +520,7 @@ class PaymentIdentifier(Logger):
|
||||
error = _("Error parsing Lightning invoice") + f":\n{e!r}"
|
||||
if e.args and len(e.args):
|
||||
arg = e.args[0]
|
||||
if isinstance(arg, LnInvoiceException):
|
||||
if isinstance(arg, BOLT11InvoiceException):
|
||||
error = _("Error parsing Lightning invoice") + f":\n{e}"
|
||||
elif isinstance(arg, IncompatibleOrInsaneFeatures):
|
||||
error = _("Invoice requires unknown or incompatible Lightning feature") + f":\n{e!r}"
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
import os
|
||||
import asyncio
|
||||
from collections import defaultdict
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from aiohttp import web
|
||||
|
||||
from electrum.util import log_exceptions, ignore_exceptions
|
||||
from electrum.logging import Logger
|
||||
from electrum.util import EventListener
|
||||
from electrum.lnaddr import lndecode
|
||||
from electrum.daemon import AuthenticatedServer
|
||||
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ from .util import (
|
||||
)
|
||||
from . import lnutil
|
||||
from .lnutil import hex_to_bytes, REDEEM_AFTER_DOUBLE_SPENT_DELAY, Keypair
|
||||
from .lnaddr import lndecode
|
||||
from .bolt11 import decode_bolt11_invoice
|
||||
from .json_db import StoredObject, stored_in
|
||||
from . import constants
|
||||
from .address_synchronizer import (TX_HEIGHT_LOCAL, TX_HEIGHT_FUTURE, TX_HEIGHT_UNCONFIRMED,
|
||||
@@ -997,7 +997,7 @@ class SwapManager(Logger):
|
||||
}
|
||||
await transport.send_request_to_server('addswapinvoice', request_data)
|
||||
# wait for funding tx
|
||||
lnaddr = lndecode(invoice)
|
||||
lnaddr = decode_bolt11_invoice(invoice)
|
||||
while swap.funding_txid is None and not lnaddr.is_expired():
|
||||
await asyncio.sleep(0.1)
|
||||
return swap.funding_txid
|
||||
|
||||
@@ -905,7 +905,7 @@ class WalletDBUpgrader(Logger):
|
||||
self.data['seed_version'] = 44
|
||||
|
||||
def _convert_version_45(self):
|
||||
from .lnaddr import lndecode
|
||||
from .bolt11 import decode_bolt11_invoice
|
||||
if not self._is_upgrade_method_needed(44, 44):
|
||||
return
|
||||
swaps = self.data.get('submarine_swaps', {})
|
||||
@@ -921,7 +921,7 @@ class WalletDBUpgrader(Logger):
|
||||
outputs = item['outputs'] if not is_lightning else None
|
||||
bip70 = item['bip70'] if not is_lightning else None
|
||||
if is_lightning:
|
||||
lnaddr = lndecode(item['invoice'])
|
||||
lnaddr = decode_bolt11_invoice(item['invoice'])
|
||||
amount_msat = lnaddr.get_amount_msat()
|
||||
timestamp = lnaddr.date
|
||||
exp_delay = lnaddr.get_expiry()
|
||||
@@ -974,7 +974,7 @@ class WalletDBUpgrader(Logger):
|
||||
self.data['seed_version'] = 46
|
||||
|
||||
def _convert_version_47(self):
|
||||
from .lnaddr import lndecode
|
||||
from .bolt11 import decode_bolt11_invoice
|
||||
if not self._is_upgrade_method_needed(46, 46):
|
||||
return
|
||||
# recalc keys of requests
|
||||
@@ -982,7 +982,7 @@ class WalletDBUpgrader(Logger):
|
||||
for key, item in list(requests.items()):
|
||||
lnaddr = item.get('lightning_invoice')
|
||||
if lnaddr:
|
||||
lnaddr = lndecode(lnaddr)
|
||||
lnaddr = decode_bolt11_invoice(lnaddr)
|
||||
rhash = lnaddr.paymenthash.hex()
|
||||
if key != rhash:
|
||||
requests[rhash] = item
|
||||
@@ -1023,7 +1023,7 @@ class WalletDBUpgrader(Logger):
|
||||
self.data['seed_version'] = 50
|
||||
|
||||
def _convert_version_51(self):
|
||||
from .lnaddr import lndecode
|
||||
from .bolt11 import decode_bolt11_invoice
|
||||
if not self._is_upgrade_method_needed(50, 50):
|
||||
return
|
||||
requests = self.data.get('payment_requests', {})
|
||||
@@ -1032,7 +1032,7 @@ class WalletDBUpgrader(Logger):
|
||||
if lightning_invoice is None:
|
||||
payment_hash = None
|
||||
else:
|
||||
lnaddr = lndecode(lightning_invoice)
|
||||
lnaddr = decode_bolt11_invoice(lightning_invoice)
|
||||
payment_hash = lnaddr.paymenthash.hex()
|
||||
item['payment_hash'] = payment_hash
|
||||
self.data['seed_version'] = 51
|
||||
|
||||
Reference in New Issue
Block a user