electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 57ec8f51c817aeef92e9cd5e1cec8d67c4681d09
parent 4b2336304f622e1b81a16ae2a18ba5055ff69ca5
Author: ThomasV <thomasv@electrum.org>
Date:   Fri,  2 Aug 2019 11:43:05 +0200

lnpay: check whether invoice has been paid

Diffstat:
Melectrum/lnworker.py | 13++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)

diff --git 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]: