mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-20 02:24:20 +01:00
* auth server * cleaning up * auth ledger class * class variables -> instance variables * annotations * add models and api route * custom amount and api prefix * add auth db * blind auth token working * jwt working * clean up * JWT works * using openid connect server * use oauth server with password flow * new realm * add keycloak docker * hopefully not garbage * auth works * auth kinda working * fix cli * auth works for send and receive * pass auth_db to Wallet * auth in info * refactor * fix supported * cache mint info * fix settings and endpoints * add description to .env.example * track changes for openid connect client * store mint in db * store credentials * clean up v1_api.py * load mint info into auth wallet * fix first login * authenticate if refresh token fails * clear auth also middleware * use regex * add cli command * pw works * persist keyset amounts * add errors.py * do not start auth server if disabled in config * upadte poetry * disvoery url * fix test * support device code flow * adopt latest spec changes * fix code flow * mint max bat dynamic * mypy ignore * fix test * do not serialize amount in authproof * all auth flows working * fix tests * submodule * refactor * test * dont sleep * test * add wallet auth tests * test differently * test only keycloak for now * fix creds * daemon * fix test * install everything * install jinja * delete wallet for every test * auth: use global rate limiter * test auth rate limit * keycloak hostname * move keycloak test data * reactivate all tests * add readme * load proofs * remove unused code * remove unused code * implement change suggestions by ok300 * add error codes * test errors
59 lines
2.3 KiB
Python
59 lines
2.3 KiB
Python
import asyncio
|
|
from typing import List
|
|
|
|
from loguru import logger
|
|
|
|
from ..core.base import MintQuoteState
|
|
from ..lightning.base import LightningBackend
|
|
from .protocols import SupportsBackends, SupportsDb, SupportsEvents
|
|
|
|
|
|
class LedgerTasks(SupportsDb, SupportsBackends, SupportsEvents):
|
|
async def dispatch_listeners(self) -> List[asyncio.Task]:
|
|
tasks = []
|
|
for method, unitbackends in self.backends.items():
|
|
for unit, backend in unitbackends.items():
|
|
logger.debug(
|
|
f"Dispatching backend invoice listener for {method} {unit} {backend.__class__.__name__}"
|
|
)
|
|
tasks.append(asyncio.create_task(self.invoice_listener(backend)))
|
|
return tasks
|
|
|
|
async def invoice_listener(self, backend: LightningBackend) -> None:
|
|
if backend.supports_incoming_payment_stream:
|
|
while True:
|
|
try:
|
|
async for checking_id in backend.paid_invoices_stream():
|
|
await self.invoice_callback_dispatcher(checking_id)
|
|
except Exception as e:
|
|
logger.error(f"Error in invoice listener: {e}")
|
|
logger.info("Restarting invoice listener...")
|
|
await asyncio.sleep(1)
|
|
|
|
async def invoice_callback_dispatcher(self, checking_id: str) -> None:
|
|
logger.debug(f"Invoice callback dispatcher: {checking_id}")
|
|
async with self.db.get_connection(
|
|
lock_table="mint_quotes",
|
|
lock_select_statement=f"checking_id='{checking_id}'",
|
|
lock_timeout=5,
|
|
) as conn:
|
|
quote = await self.crud.get_mint_quote(
|
|
checking_id=checking_id, db=self.db, conn=conn
|
|
)
|
|
if not quote:
|
|
logger.error(f"Quote not found for {checking_id}")
|
|
return
|
|
|
|
logger.trace(
|
|
f"Invoice callback dispatcher: quote {quote} trying to set as {MintQuoteState.paid}"
|
|
)
|
|
# set the quote as paid
|
|
if quote.unpaid:
|
|
quote.state = MintQuoteState.paid
|
|
await self.crud.update_mint_quote(quote=quote, db=self.db, conn=conn)
|
|
logger.trace(
|
|
f"Quote {quote.quote} with {MintQuoteState.unpaid} set as {quote.state.value}"
|
|
)
|
|
|
|
await self.events.submit(quote)
|