From e7a6e86e7add238dce56f438aab491893e329a7e Mon Sep 17 00:00:00 2001 From: calle <93376500+callebtc@users.noreply.github.com> Date: Sun, 18 Sep 2022 16:27:03 +0300 Subject: [PATCH] Fix/duplicate payments (#973) * check if wallet exists * check wallet existence in key check * fix duplicate removal --- lnbits/core/crud.py | 9 +++++++++ lnbits/core/services.py | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lnbits/core/crud.py b/lnbits/core/crud.py index 4122f9026..ecc27a9cf 100644 --- a/lnbits/core/crud.py +++ b/lnbits/core/crud.py @@ -452,6 +452,15 @@ async def delete_payment(checking_id: str, conn: Optional[Connection] = None) -> ) +async def delete_wallet_payment( + checking_id: str, wallet_id: str, conn: Optional[Connection] = None +) -> None: + await (conn or db).execute( + "DELETE FROM apipayments WHERE checking_id = ? AND wallet = ?", + (checking_id, wallet_id), + ) + + async def check_internal( payment_hash: str, conn: Optional[Connection] = None ) -> Optional[str]: diff --git a/lnbits/core/services.py b/lnbits/core/services.py index a6e0b43a3..10693f4b9 100644 --- a/lnbits/core/services.py +++ b/lnbits/core/services.py @@ -28,7 +28,7 @@ from . import db from .crud import ( check_internal, create_payment, - delete_payment, + delete_wallet_payment, get_wallet, get_wallet_payment, update_payment_details, @@ -221,7 +221,7 @@ async def pay_invoice( logger.warning(f"backend sent payment failure") async with db.connect() as conn: logger.debug(f"deleting temporary payment {temp_id}") - await delete_payment(temp_id, conn=conn) + await delete_wallet_payment(temp_id, wallet_id, conn=conn) raise PaymentFailure( f"payment failed: {payment.error_message}" or "payment failed, but backend didn't give us an error message"