BUG: proper exception for already paid internal invoices (#1593)
* BUG: proper exception for paid interal invoices * test should now fail, because we pay invoice twice, and should also work in regtest * sorting * unpack check_internal * introduce another crud fn for checking internal paid payment * rename --------- Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
This commit is contained in:
@@ -604,6 +604,22 @@ async def check_internal(
|
||||
return row["checking_id"]
|
||||
|
||||
|
||||
async def check_internal_pending(
|
||||
payment_hash: str, conn: Optional[Connection] = None
|
||||
) -> bool:
|
||||
row = await (conn or db).fetchone(
|
||||
"""
|
||||
SELECT pending FROM apipayments
|
||||
WHERE hash = ? AND amount > 0
|
||||
""",
|
||||
(payment_hash,),
|
||||
)
|
||||
if not row:
|
||||
return False
|
||||
else:
|
||||
return row["pending"]
|
||||
|
||||
|
||||
# balance_check
|
||||
# -------------
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ from lnbits.wallets.base import PaymentResponse, PaymentStatus
|
||||
from . import db
|
||||
from .crud import (
|
||||
check_internal,
|
||||
check_internal_pending,
|
||||
create_account,
|
||||
create_admin_settings,
|
||||
create_payment,
|
||||
@@ -153,6 +154,9 @@ async def pay_invoice(
|
||||
extra=extra,
|
||||
)
|
||||
|
||||
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
|
||||
internal_checking_id = await check_internal(invoice.payment_hash, conn=conn)
|
||||
if internal_checking_id:
|
||||
|
||||
Reference in New Issue
Block a user