From 58c3b05e29bc1043f6659163875fb985e891b32e Mon Sep 17 00:00:00 2001 From: calle <93376500+callebtc@users.noreply.github.com> Date: Mon, 3 Apr 2023 15:15:34 +0200 Subject: [PATCH] fix internal payment check (#1604) --- lnbits/core/crud.py | 3 ++- lnbits/core/services.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lnbits/core/crud.py b/lnbits/core/crud.py index f9224911..1b807b78 100644 --- a/lnbits/core/crud.py +++ b/lnbits/core/crud.py @@ -597,6 +597,7 @@ async def check_internal( async def check_internal_pending( payment_hash: str, conn: Optional[Connection] = None ) -> bool: + """Returns False if the internal payment is not pending anymore (and thus paid), otherwise True""" row = await (conn or db).fetchone( """ SELECT pending FROM apipayments @@ -605,7 +606,7 @@ async def check_internal_pending( (payment_hash,), ) if not row: - return False + return True else: return row["pending"] diff --git a/lnbits/core/services.py b/lnbits/core/services.py index 3ff64131..8c782b86 100644 --- a/lnbits/core/services.py +++ b/lnbits/core/services.py @@ -154,10 +154,11 @@ async def pay_invoice( extra=extra, ) + # we check if an internal invoice exists that has already been paid (not pending anymore) if not await check_internal_pending(invoice.payment_hash, conn=conn): raise PaymentFailure("Internal invoice already paid.") - # check_internal() returns the checking_id of the invoice we're waiting for + # check_internal() returns the checking_id of the invoice we're waiting for (pending only) internal_checking_id = await check_internal(invoice.payment_hash, conn=conn) if internal_checking_id: logger.debug(f"creating temporary internal payment with id {internal_id}")