2022-09-16 13:20:42 +01:00
|
|
|
import asyncio
|
|
|
|
import json
|
|
|
|
|
2022-10-21 15:31:24 +02:00
|
|
|
from cashu.core.migrations import migrate_databases
|
|
|
|
from cashu.mint import migrations
|
|
|
|
|
2022-09-16 13:20:42 +01:00
|
|
|
from lnbits.core.models import Payment
|
2022-10-14 01:01:43 +02:00
|
|
|
from lnbits.tasks import register_invoice_listener
|
2022-09-16 13:20:42 +01:00
|
|
|
|
2022-10-12 23:16:39 +02:00
|
|
|
from . import db, ledger
|
2022-10-21 15:31:24 +02:00
|
|
|
from .crud import get_cashu
|
2022-10-12 23:16:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
async def startup_cashu_mint():
|
2022-10-13 00:24:15 +02:00
|
|
|
await migrate_databases(db, migrations)
|
2022-10-12 23:16:39 +02:00
|
|
|
await ledger.load_used_proofs()
|
|
|
|
await ledger.init_keysets()
|
|
|
|
pass
|
|
|
|
|
2022-10-07 11:17:02 +03:00
|
|
|
|
2022-09-16 13:20:42 +01: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-11-24 15:25:37 +01:00
|
|
|
if payment.extra and not payment.extra.get("tag") == "cashu":
|
2022-09-16 13:20:42 +01:00
|
|
|
return
|
|
|
|
return
|