lnbits-legend/lnbits/extensions/jukebox/tasks.py

23 lines
581 B
Python
Raw Normal View History

2021-10-10 23:57:15 +01:00
import asyncio
2021-10-10 16:23:39 +01:00
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 update_jukebox_payment
2021-10-10 16:23:39 +01:00
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:
2022-07-15 18:11:11 +01:00
if payment.extra.get("tag") != "jukebox":
2021-10-10 16:23:39 +01:00
# not a jukebox invoice
return
await update_jukebox_payment(payment.payment_hash, paid=True)