register channel listeners instead of callbacks.
makes for a little less black magic and more reasonable use of nurseries and less unnecessary pseudo-requests.
This commit is contained in:
@@ -7,8 +7,8 @@ lnurlp_ext: Blueprint = Blueprint("lnurlp", __name__, static_folder="static", te
|
||||
from .views_api import * # noqa
|
||||
from .views import * # noqa
|
||||
from .lnurl import * # noqa
|
||||
from .tasks import on_invoice_paid
|
||||
from .tasks import register_listeners
|
||||
|
||||
from lnbits.tasks import register_invoice_listener
|
||||
from lnbits.tasks import record_async
|
||||
|
||||
register_invoice_listener("lnurlp", on_invoice_paid)
|
||||
lnurlp_ext.record(record_async(register_listeners))
|
||||
|
||||
@@ -1,10 +1,23 @@
|
||||
import trio # type: ignore
|
||||
import httpx
|
||||
|
||||
from lnbits.core.models import Payment
|
||||
from lnbits.tasks import run_on_pseudo_request, register_invoice_listener
|
||||
|
||||
from .crud import get_pay_link_by_invoice, mark_webhook_sent
|
||||
|
||||
|
||||
async def register_listeners():
|
||||
invoice_paid_chan_send, invoice_paid_chan_recv = trio.open_memory_channel(2)
|
||||
register_invoice_listener(invoice_paid_chan_send)
|
||||
await wait_for_paid_invoices(invoice_paid_chan_recv)
|
||||
|
||||
|
||||
async def wait_for_paid_invoices(invoice_paid_chan: trio.MemoryReceiveChannel):
|
||||
async for payment in invoice_paid_chan:
|
||||
await run_on_pseudo_request(on_invoice_paid, payment)
|
||||
|
||||
|
||||
async def on_invoice_paid(payment: Payment) -> None:
|
||||
islnurlp = "lnurlp" == payment.extra.get("tag")
|
||||
if islnurlp:
|
||||
|
||||
Reference in New Issue
Block a user