This commit is contained in:
ben 2022-10-07 23:18:57 +01:00
parent 8d4337679f
commit 0057d75422
7 changed files with 23 additions and 16 deletions

View File

@ -13,11 +13,13 @@ lnurldevice_ext: APIRouter = APIRouter(prefix="/lnurldevice", tags=["lnurldevice
def lnurldevice_renderer(): def lnurldevice_renderer():
return template_renderer(["lnbits/extensions/lnurldevice/templates"]) return template_renderer(["lnbits/extensions/lnurldevice/templates"])
from .tasks import wait_for_paid_invoices from .tasks import wait_for_paid_invoices
from .lnurl import * # noqa from .lnurl import * # noqa
from .views import * # noqa from .views import * # noqa
from .views_api import * # noqa from .views_api import * # noqa
def lnurldevice_start(): def lnurldevice_start():
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
loop.create_task(catch_everything_and_restart(wait_for_paid_invoices)) loop.create_task(catch_everything_and_restart(wait_for_paid_invoices))

View File

@ -80,8 +80,11 @@ async def m002_redux(db):
except: except:
return return
async def m003_redux(db): async def m003_redux(db):
""" """
Add 'meta' for storing various metadata about the wallet Add 'meta' for storing various metadata about the wallet
""" """
await db.execute("ALTER TABLE lnurldevice.lnurldevices ADD COLUMN amount INT DEFAULT 0;") await db.execute(
"ALTER TABLE lnurldevice.lnurldevices ADD COLUMN amount INT DEFAULT 0;"
)

View File

@ -35,9 +35,7 @@ class lnurldevices(BaseModel):
return cls(**dict(row)) return cls(**dict(row))
def lnurl(self, req: Request) -> Lnurl: def lnurl(self, req: Request) -> Lnurl:
url = req.url_for( url = req.url_for("lnurldevice.lnurl_v1_params", device_id=self.id)
"lnurldevice.lnurl_v1_params", device_id=self.id
)
return lnurl_encode(url) return lnurl_encode(url)
async def lnurlpay_metadata(self) -> LnurlPayMetadata: async def lnurlpay_metadata(self) -> LnurlPayMetadata:

View File

@ -16,6 +16,7 @@ from .crud import get_lnurldevice, get_lnurldevicepayment, update_lnurldevicepay
from .views import updater from .views import updater
from loguru import logger from loguru import logger
async def wait_for_paid_invoices(): async def wait_for_paid_invoices():
invoice_queue = asyncio.Queue() invoice_queue = asyncio.Queue()
register_invoice_listener(invoice_queue, get_current_extension_name()) register_invoice_listener(invoice_queue, get_current_extension_name())
@ -24,6 +25,7 @@ async def wait_for_paid_invoices():
payment = await invoice_queue.get() payment = await invoice_queue.get()
await on_invoice_paid(payment) await on_invoice_paid(payment)
async def on_invoice_paid(payment: Payment) -> None: async def on_invoice_paid(payment: Payment) -> None:
# (avoid loops) # (avoid loops)
if "Switch" == payment.extra.get("tag"): if "Switch" == payment.extra.get("tag"):

View File

@ -57,6 +57,7 @@ async def displaypin(request: Request, paymentid: str = Query(None)):
{"request": request, "pin": "filler", "not_paid": True}, {"request": request, "pin": "filler", "not_paid": True},
) )
@lnurldevice_ext.get("/img/{lnurldevice_id}", response_class=StreamingResponse) @lnurldevice_ext.get("/img/{lnurldevice_id}", response_class=StreamingResponse)
async def img(request: Request, lnurldevice_id): async def img(request: Request, lnurldevice_id):
lnurldevice = await get_lnurldevice(lnurldevice_id) lnurldevice = await get_lnurldevice(lnurldevice_id)
@ -110,4 +111,3 @@ async def updater(lnurldevice_id):
if not lnurldevice: if not lnurldevice:
return return
await manager.send_personal_message(f"{lnurldevice.amount}", lnurldevice_id) await manager.send_personal_message(f"{lnurldevice.amount}", lnurldevice_id)

View File

@ -46,7 +46,9 @@ async def api_lnurldevice_create_or_update(
@lnurldevice_ext.get("/api/v1/lnurlpos") @lnurldevice_ext.get("/api/v1/lnurlpos")
async def api_lnurldevices_retrieve(req: Request, wallet: WalletTypeInfo = Depends(get_key_type)): async def api_lnurldevices_retrieve(
req: Request, wallet: WalletTypeInfo = Depends(get_key_type)
):
wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids
try: try:
return [ return [