Fix/duplicate payments (#973)

* check if wallet exists

* check wallet existence in key check

* fix duplicate removal
This commit is contained in:
calle 2022-09-18 16:27:03 +03:00 committed by GitHub
parent 232d50baaa
commit e7a6e86e7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View file

@ -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( async def check_internal(
payment_hash: str, conn: Optional[Connection] = None payment_hash: str, conn: Optional[Connection] = None
) -> Optional[str]: ) -> Optional[str]:

View file

@ -28,7 +28,7 @@ from . import db
from .crud import ( from .crud import (
check_internal, check_internal,
create_payment, create_payment,
delete_payment, delete_wallet_payment,
get_wallet, get_wallet,
get_wallet_payment, get_wallet_payment,
update_payment_details, update_payment_details,
@ -221,7 +221,7 @@ async def pay_invoice(
logger.warning(f"backend sent payment failure") logger.warning(f"backend sent payment failure")
async with db.connect() as conn: async with db.connect() as conn:
logger.debug(f"deleting temporary payment {temp_id}") 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( raise PaymentFailure(
f"payment failed: {payment.error_message}" f"payment failed: {payment.error_message}"
or "payment failed, but backend didn't give us an error message" or "payment failed, but backend didn't give us an error message"