diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py index f2d000b7a..b8c062181 100644 --- a/electrum/gui/qt/main_window.py +++ b/electrum/gui/qt/main_window.py @@ -1278,7 +1278,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): bip21_lightning = lnaddr if self.config.get('bip21_lightning', False) else None URI = req.get_bip21_URI(lightning=bip21_lightning) lightning_online = self.wallet.lnworker and self.wallet.lnworker.num_peers() > 0 - can_receive_lightning = self.wallet.lnworker and req.get_amount_sat() <= self.wallet.lnworker.num_sats_can_receive() + can_receive_lightning = self.wallet.lnworker and (req.get_amount_sat() or 0) <= self.wallet.lnworker.num_sats_can_receive() if lnaddr is None: ln_help = _('This request does not have a Lightning invoice.') lnaddr = '' diff --git a/electrum/invoices.py b/electrum/invoices.py index f9e13538d..e6b557125 100644 --- a/electrum/invoices.py +++ b/electrum/invoices.py @@ -161,7 +161,9 @@ class Invoice(StoredObject): def get_bip21_URI(self, lightning=None): from electrum.util import create_bip21_uri addr = self.get_address() - amount = int(self.get_amount_sat()) + amount = self.get_amount_sat() + if amount is not None: + amount = int(amount) message = self.message extra = {} if self.time and self.exp: diff --git a/electrum/lnworker.py b/electrum/lnworker.py index eecfe5a0f..fed3a479e 100644 --- a/electrum/lnworker.py +++ b/electrum/lnworker.py @@ -1098,7 +1098,7 @@ class LNWallet(LNWorker): def can_pay_invoice(self, invoice: Invoice) -> bool: assert invoice.is_lightning() - return invoice.get_amount_sat() <= self.num_sats_can_send() + return (invoice.get_amount_sat() or 0) <= self.num_sats_can_send() @log_exceptions async def pay_invoice( @@ -2126,7 +2126,7 @@ class LNWallet(LNWorker): def can_receive_invoice(self, invoice: Invoice) -> bool: assert invoice.is_lightning() - return invoice.get_amount_sat() <= self.num_sats_can_receive() + return (invoice.get_amount_sat() or 0) <= self.num_sats_can_receive() async def close_channel(self, chan_id): chan = self._channels[chan_id] diff --git a/electrum/submarine_swaps.py b/electrum/submarine_swaps.py index 4c3d7dc2a..75f1e57a2 100644 --- a/electrum/submarine_swaps.py +++ b/electrum/submarine_swaps.py @@ -419,7 +419,7 @@ class SwapManager(Logger): raise Exception("rswap check failed: locktime too close") # verify invoice preimage_hash lnaddr = self.lnworker._check_invoice(invoice) - invoice_amount = lnaddr.get_amount_sat() + invoice_amount = int(lnaddr.get_amount_sat()) if lnaddr.paymenthash != preimage_hash: raise Exception("rswap check failed: inconsistent RHASH and invoice") # check that the lightning amount is what we requested diff --git a/electrum/wallet.py b/electrum/wallet.py index 217431b07..48a6eb1b0 100644 --- a/electrum/wallet.py +++ b/electrum/wallet.py @@ -2167,7 +2167,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC): def get_onchain_request_status(self, r: Invoice) -> Tuple[bool, Optional[int]]: address = r.get_address() - amount = r.get_amount_sat() + amount = int(r.get_amount_sat() or 0) received, sent = self.get_addr_io(address) l = [] for txo, x in received.items():