Checks wallet balance is at threshold
This commit is contained in:
parent
410689e04b
commit
0ab158992e
1 changed files with 33 additions and 28 deletions
|
|
@ -2,10 +2,10 @@ import asyncio
|
|||
import json
|
||||
import httpx
|
||||
|
||||
from lnbits.core.crud import get_wallet
|
||||
from lnbits.core import db as core_db
|
||||
from lnbits.core.models import Payment
|
||||
from lnbits.tasks import register_invoice_listener
|
||||
from lnbits.core.api import api_wallet
|
||||
|
||||
from .crud import get_lnurlpayout
|
||||
|
||||
|
|
@ -20,12 +20,15 @@ async def wait_for_paid_invoices():
|
|||
|
||||
|
||||
async def on_invoice_paid(payment: Payment) -> None:
|
||||
try:
|
||||
# Check its got a payout associated with it
|
||||
lnurlpayout_link = await get_lnurlpayout(payment.extra.get("link", -1))
|
||||
|
||||
if lnurlpayout_link:
|
||||
# Check the wallet balance is more than the threshold
|
||||
|
||||
wallet = api_wallet(payment.wallet_id)
|
||||
if wallet.balance < lnurlpayout_link.threshold:
|
||||
return
|
||||
# Get the invoice from the LNURL to pay
|
||||
async with httpx.AsyncClient() as client:
|
||||
try:
|
||||
|
|
@ -50,3 +53,5 @@ async def on_invoice_paid(payment: Payment) -> None:
|
|||
|
||||
except Exception:
|
||||
raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="Failed to save LNURLPayout")
|
||||
except:
|
||||
return
|
||||
Loading…
Add table
Add a link
Reference in a new issue