2022-12-20 06:28:43 -06:00
|
|
|
import asyncio
|
2022-12-30 09:46:45 +01:00
|
|
|
|
|
|
|
from loguru import logger
|
2022-12-20 06:28:43 -06:00
|
|
|
|
|
|
|
from lnbits.core.models import Payment
|
2022-12-30 09:46:45 +01:00
|
|
|
from lnbits.tasks import register_invoice_listener
|
2022-12-20 06:28:43 -06:00
|
|
|
|
2022-12-24 05:40:34 -06:00
|
|
|
from .crud import activate_address
|
2022-12-20 06:28:43 -06:00
|
|
|
|
|
|
|
|
|
|
|
async def wait_for_paid_invoices():
|
|
|
|
invoice_queue = asyncio.Queue()
|
|
|
|
register_invoice_listener(invoice_queue)
|
|
|
|
|
|
|
|
while True:
|
|
|
|
payment = await invoice_queue.get()
|
|
|
|
await on_invoice_paid(payment)
|
|
|
|
|
|
|
|
|
|
|
|
async def on_invoice_paid(payment: Payment) -> None:
|
2022-12-30 09:46:45 +01:00
|
|
|
if not payment.extra:
|
|
|
|
return
|
2022-12-20 06:28:43 -06:00
|
|
|
if payment.extra.get("tag") != "nostrnip5":
|
|
|
|
return
|
|
|
|
|
|
|
|
domain_id = payment.extra.get("domain_id")
|
|
|
|
address_id = payment.extra.get("address_id")
|
|
|
|
|
2022-12-30 09:46:45 +01:00
|
|
|
if domain_id and address_id:
|
|
|
|
logger.info("Activating NOSTR NIP-05")
|
|
|
|
logger.info(domain_id)
|
|
|
|
logger.info(address_id)
|
|
|
|
await activate_address(domain_id, address_id)
|
2022-12-20 06:28:43 -06:00
|
|
|
|
|
|
|
return
|