2021-10-10 23:57:15 +01:00
|
|
|
import asyncio
|
2021-10-10 16:23:39 +01:00
|
|
|
import json
|
2021-10-10 23:57:15 +01:00
|
|
|
import httpx
|
2021-10-10 16:23:39 +01:00
|
|
|
|
|
|
|
from lnbits.core import db as core_db
|
2021-10-10 23:57:15 +01:00
|
|
|
from lnbits.core.models import Payment
|
|
|
|
from lnbits.tasks import register_invoice_listener
|
2021-10-10 16:23:39 +01:00
|
|
|
|
|
|
|
from .crud import get_jukebox, update_jukebox_payment
|
|
|
|
|
|
|
|
|
2021-10-10 23:57:15 +01:00
|
|
|
async def wait_for_paid_invoices():
|
|
|
|
invoice_queue = asyncio.Queue()
|
|
|
|
register_invoice_listener(invoice_queue)
|
2021-10-10 16:23:39 +01:00
|
|
|
|
2021-10-10 23:57:15 +01:00
|
|
|
while True:
|
|
|
|
payment = await invoice_queue.get()
|
2021-10-10 16:23:39 +01:00
|
|
|
await on_invoice_paid(payment)
|
|
|
|
|
|
|
|
|
|
|
|
async def on_invoice_paid(payment: Payment) -> None:
|
|
|
|
if "jukebox" != payment.extra.get("tag"):
|
|
|
|
# not a jukebox invoice
|
|
|
|
return
|
|
|
|
await update_jukebox_payment(payment.payment_hash, paid=True)
|