From 57ec8f51c817aeef92e9cd5e1cec8d67c4681d09 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Fri, 2 Aug 2019 11:43:05 +0200 Subject: [PATCH] lnpay: check whether invoice has been paid --- electrum/lnworker.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/electrum/lnworker.py b/electrum/lnworker.py index a3bf448b8..2069a9ce6 100644 --- a/electrum/lnworker.py +++ b/electrum/lnworker.py @@ -724,9 +724,13 @@ class LNWallet(LNWorker): def pay(self, invoice, attempts=1, amount_sat=None, timeout=10): """ Can be called from other threads - Raises timeout exception if htlc is not fulfilled + Raises exception after timeout """ - addr = self._check_invoice(invoice, amount_sat) + addr = lndecode(invoice, expected_hrp=constants.net.SEGWIT_HRP) + status = self.get_invoice_status(bh2u(addr.paymenthash)) + if status == PR_PAID: + raise PaymentFailure(_("This invoice has been paid already")) + self._check_invoice(invoice, amount_sat) self.save_invoice(addr.paymenthash, invoice, SENT, is_paid=False) self.wallet.set_label(bh2u(addr.paymenthash), addr.get_description()) fut = asyncio.run_coroutine_threadsafe( @@ -768,6 +772,8 @@ class LNWallet(LNWorker): @staticmethod def _check_invoice(invoice, amount_sat=None): addr = lndecode(invoice, expected_hrp=constants.net.SEGWIT_HRP) + if addr.is_expired(): + raise InvoiceError(_("This invoice has expired")) if amount_sat: addr.amount = Decimal(amount_sat) / COIN if addr.amount is None: @@ -776,9 +782,6 @@ class LNWallet(LNWorker): raise InvoiceError("{}\n{}".format( _("Invoice wants us to risk locking funds for unreasonably long."), f"min_final_cltv_expiry: {addr.get_min_final_cltv_expiry()}")) - #now = int(time.time()) - #if addr.date + addr.get_expiry() > now: - # raise InvoiceError(_('Invoice expired')) return addr async def _create_route_from_invoice(self, decoded_invoice) -> List[RouteEdge]: