From 762f0ba404fc2150616cdf71a53a0fe595e6e2e1 Mon Sep 17 00:00:00 2001 From: benarc Date: Sun, 17 Oct 2021 23:19:42 +0100 Subject: [PATCH] copilot lnurls fetching --- lnbits/extensions/copilot/lnurl.py | 4 +++- lnbits/extensions/copilot/models.py | 4 +++- lnbits/extensions/copilot/views_api.py | 6 ++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lnbits/extensions/copilot/lnurl.py b/lnbits/extensions/copilot/lnurl.py index c7b99f406..d1c1fc957 100644 --- a/lnbits/extensions/copilot/lnurl.py +++ b/lnbits/extensions/copilot/lnurl.py @@ -23,7 +23,9 @@ from fastapi.params import Depends from fastapi.param_functions import Query -@copilot_ext.get("/lnurl/{cp_id}", response_class=HTMLResponse) +@copilot_ext.get( + "/lnurl/{cp_id}", response_class=HTMLResponse, name="copilot.lnurl_response" +) async def lnurl_response(req: Request, cp_id: str = Query(None)): cp = await get_copilot(cp_id) if not cp: diff --git a/lnbits/extensions/copilot/models.py b/lnbits/extensions/copilot/models.py index ce463d59c..a279879dc 100644 --- a/lnbits/extensions/copilot/models.py +++ b/lnbits/extensions/copilot/models.py @@ -5,6 +5,8 @@ from typing import Optional, Dict from lnbits.lnurl import encode as lnurl_encode # type: ignore from lnurl.types import LnurlPayMetadata # type: ignore from pydantic import BaseModel +import json +from sqlite3 import Row class CreateCopilotData(BaseModel): @@ -58,5 +60,5 @@ class Copilots(BaseModel): success_url: str = Query(None) def lnurl(self, req: Request) -> str: - url = req.url_for("copilot.lnurl_response", link_id=self.id) + url = req.url_for("copilot.lnurl_response", cp_id=self.id) return lnurl_encode(url) diff --git a/lnbits/extensions/copilot/views_api.py b/lnbits/extensions/copilot/views_api.py index 8083e77a6..e87a39a2f 100644 --- a/lnbits/extensions/copilot/views_api.py +++ b/lnbits/extensions/copilot/views_api.py @@ -49,7 +49,9 @@ async def api_copilots_retrieve( @copilot_ext.get("/api/v1/copilot/{copilot_id}") async def api_copilot_retrieve( - copilot_id: str = Query(None), wallet: WalletTypeInfo = Depends(get_key_type) + req: Request, + copilot_id: str = Query(None), + wallet: WalletTypeInfo = Depends(get_key_type), ): copilot = await get_copilot(copilot_id) if not copilot: @@ -58,7 +60,7 @@ async def api_copilot_retrieve( ) if not copilot.lnurl_toggle: return copilot.dict() - return {**copilot.dict(), **{"lnurl": copilot.lnurl}} + return {**copilot.dict(), **{"lnurl": copilot.lnurl(req)}} @copilot_ext.post("/api/v1/copilot")