This commit is contained in:
dni ⚡ 2024-09-30 13:14:25 +02:00 committed by Vlad Stan
parent 3dc906a70b
commit 7c19dfbc83
3 changed files with 11 additions and 9 deletions

View File

@ -992,23 +992,22 @@ async def check_internal(
return row["checking_id"]
async def check_internal_pending(
async def check_internal_status(
payment_hash: str, conn: Optional[Connection] = None
) -> bool:
"""
Returns False if the internal payment is not pending anymore
(and thus paid), otherwise True
Returns True if the internal payment was successful
"""
row: dict = await (conn or db).fetchone(
"""
SELECT status FROM apipayments
WHERE payment_hash = :hash AND amount > 0
WHERE payment_hash = :payment_hash AND amount > 0
""",
{"hash": payment_hash},
{"payment_hash": payment_hash},
)
if not row:
return True
return row["status"] == PaymentState.PENDING.value
return row["status"] == PaymentState.SUCCESS.value
async def mark_webhook_sent(payment_hash: str, status: int) -> None:

View File

@ -557,8 +557,11 @@ async def m023_add_column_column_to_apipayments(db):
"""
renames hash to payment_hash and drops unused index
"""
await db.execute("ALTER TABLE apipayments DROP COLUMN pending")
await db.execute("DROP INDEX by_hash")
await db.execute("ALTER TABLE apipayments RENAME COLUMN hash TO payment_hash")
await db.execute("ALTER TABLE apipayments RENAME COLUMN wallet TO wallet_id")
await db.execute("ALTER TABLE accounts RENAME COLUMN pass TO password_hash")
async def m023_drop_pending(db):
await db.execute("ALTER TABLE apipayments DROP COLUMN pending")

View File

@ -46,7 +46,7 @@ from lnbits.wallets.base import (
from .crud import (
check_internal,
check_internal_pending,
check_internal_status,
create_account,
create_admin_settings,
create_payment,
@ -242,7 +242,7 @@ async def pay_invoice(
# 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):
if await check_internal_status(invoice.payment_hash, conn=conn):
raise PaymentError("Internal invoice already paid.", status="failed")
# check_internal() returns the checking_id of the invoice we're waiting for