lnaddress_ext proposal untested

This commit is contained in:
Tiago vasconcelos
2021-10-29 16:43:26 +01:00
parent a276764f12
commit aff29663af
15 changed files with 2030 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
from http import HTTPStatus
from fastapi import Request
from fastapi.params import Depends
from fastapi.templating import Jinja2Templates
from starlette.exceptions import HTTPException
from starlette.responses import HTMLResponse
from lnbits.core.crud import get_wallet
from lnbits.core.models import User
from lnbits.decorators import check_user_exists
from . import lnaddress_ext, lnaddress_renderer
from .crud import get_domain, purge_addresses
templates = Jinja2Templates(directory="templates")
@lnaddress_ext.get("/", response_class=HTMLResponse)
async def index(request: Request, user: User = Depends(check_user_exists)):
return lnaddress_renderer().TemplateResponse("lnaddress/index.html", {"request": request, "user": user.dict()})
@lnaddress_ext.get("/{domain_id}")
async def display(domain_id, request: Request):
domain = await get_domain(domain_id)
if not domain:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="Domain does not exist."
)
await purge_addresses(domain_id, response_class=HTMLResponse)
wallet = await get_wallet(domain.wallet)
return lnaddress_renderer().TemplateResponse(
"lnaddress/display.html",{
"request": request,
"domain_id":domain.id,
"domain_domain": domain.domain,
"domain_cost": domain.cost,
"domain_wallet_inkey": wallet.inkey
}
)