From b9ff95a9cf0baf47246c213f34ea936dd2f600ad Mon Sep 17 00:00:00 2001 From: benarc Date: Thu, 14 Oct 2021 23:08:09 +0100 Subject: [PATCH] Satsdice loading, needs finishing --- lnbits/extensions/satsdice/__init__.py | 9 ++++----- lnbits/extensions/satsdice/crud.py | 2 ++ .../satsdice/templates/satsdice/_api_docs.html | 12 ++++++------ .../satsdice/templates/satsdice/index.html | 4 ++-- lnbits/extensions/satsdice/views.py | 18 ++++++++---------- lnbits/extensions/satsdice/views_api.py | 4 +++- 6 files changed, 25 insertions(+), 24 deletions(-) diff --git a/lnbits/extensions/satsdice/__init__.py b/lnbits/extensions/satsdice/__init__.py index b70b570e7..2149760f7 100644 --- a/lnbits/extensions/satsdice/__init__.py +++ b/lnbits/extensions/satsdice/__init__.py @@ -6,7 +6,7 @@ from lnbits.db import Database from lnbits.helpers import template_renderer from lnbits.tasks import catch_everything_and_restart -db = Database("satsdice_ext") +db = Database("ext_satsdice") satsdice_ext: APIRouter = APIRouter(prefix="/satsdice", tags=["satsdice"]) @@ -22,9 +22,8 @@ def satsdice_renderer(): from .views_api import * # noqa from .views import * # noqa from .lnurl import * # noqa -from .tasks import wait_for_paid_invoices -def satsdice_start(): - loop = asyncio.get_event_loop() - loop.create_task(catch_everything_and_restart(wait_for_paid_invoices)) +# def satsdice_start(): +# loop = asyncio.get_event_loop() +# loop.create_task(catch_everything_and_restart(wait_for_paid_invoices)) diff --git a/lnbits/extensions/satsdice/crud.py b/lnbits/extensions/satsdice/crud.py index c5434b39c..a834b5427 100644 --- a/lnbits/extensions/satsdice/crud.py +++ b/lnbits/extensions/satsdice/crud.py @@ -9,6 +9,8 @@ from .models import ( satsdiceLink, satsdicePayment, CreateSatsDiceLink, + CreateSatsDicePayment, + CreateSatsDiceWithdraw, ) from lnbits.helpers import urlsafe_short_hash diff --git a/lnbits/extensions/satsdice/templates/satsdice/_api_docs.html b/lnbits/extensions/satsdice/templates/satsdice/_api_docs.html index 0f22784e6..7d73ae7e4 100644 --- a/lnbits/extensions/satsdice/templates/satsdice/_api_docs.html +++ b/lnbits/extensions/satsdice/templates/satsdice/_api_docs.html @@ -18,7 +18,7 @@
Curl example
curl -X GET {{ request.url_root }}api/v1/links -H "X-Api-Key: {{ - g.user.wallets[0].inkey }}" + user.wallets[0].inkey }}" @@ -45,7 +45,7 @@
Curl example
curl -X GET {{ request.url_root }}api/v1/links/<satsdice_id> -H - "X-Api-Key: {{ g.user.wallets[0].inkey }}" + "X-Api-Key: {{ user.wallets[0].inkey }}" @@ -78,7 +78,7 @@ "max_satsdiceable": <integer>, "uses": <integer>, "wait_time": <integer>, "is_unique": <boolean>}' -H "Content-type: application/json" -H "X-Api-Key: {{ - g.user.wallets[0].adminkey }}" + user.wallets[0].adminkey }}" @@ -114,7 +114,7 @@ "max_satsdiceable": <integer>, "uses": <integer>, "wait_time": <integer>, "is_unique": <boolean>}' -H "Content-type: application/json" -H "X-Api-Key: {{ - g.user.wallets[0].adminkey }}" + user.wallets[0].adminkey }}" @@ -138,7 +138,7 @@
Curl example
curl -X DELETE {{ request.url_root }}api/v1/links/<satsdice_id> - -H "X-Api-Key: {{ g.user.wallets[0].adminkey }}" + -H "X-Api-Key: {{ user.wallets[0].adminkey }}" @@ -166,7 +166,7 @@ curl -X GET {{ request.url_root }}api/v1/links/<the_hash>/<lnurl_id> -H "X-Api-Key: {{ - g.user.wallets[0].inkey }}" + user.wallets[0].inkey }}" diff --git a/lnbits/extensions/satsdice/templates/satsdice/index.html b/lnbits/extensions/satsdice/templates/satsdice/index.html index d92d43be0..160a82d3a 100644 --- a/lnbits/extensions/satsdice/templates/satsdice/index.html +++ b/lnbits/extensions/satsdice/templates/satsdice/index.html @@ -92,9 +92,9 @@ - {% include "lnurlp/_api_docs.html" %} + {% include "satsdice/_api_docs.html" %} - {% include "lnurlp/_lnurl.html" %} + {% include "satsdice/_lnurl.html" %} diff --git a/lnbits/extensions/satsdice/views.py b/lnbits/extensions/satsdice/views.py index ca7c302d7..52d3ca3e0 100644 --- a/lnbits/extensions/satsdice/views.py +++ b/lnbits/extensions/satsdice/views.py @@ -15,8 +15,9 @@ from fastapi.templating import Jinja2Templates from starlette.exceptions import HTTPException from starlette.responses import HTMLResponse from lnbits.core.models import User, Payment -from .views_api import api_get_jukebox_device_check +from fastapi.params import Depends +from fastapi.param_functions import Query templates = Jinja2Templates(directory="templates") @@ -38,7 +39,7 @@ async def display(link_id): chance=link.chance, multiplier=link.multiplier, lnurl=link.lnurl, - unique=True,{"request": request, "user": user.dict()} + unique=True, ) @@ -57,7 +58,7 @@ async def displaywin(link_id, payment_hash): multiplier=satsdicelink.multiplier, lnurl=withdrawLink.lnurl, paid=False, - lost=False + lost=False, ) payment = await get_standalone_payment(payment_hash) or abort( @@ -72,8 +73,7 @@ async def displaywin(link_id, payment_hash): if payment.pending == 1: print("pending") return satsdice_renderer().TemplateResponse( - "satsdice/error.html", - link=satsdicelink.id, paid=False, lost=False + "satsdice/error.html", link=satsdicelink.id, paid=False, lost=False ) await update_satsdice_payment(payment_hash, paid=1) @@ -85,8 +85,7 @@ async def displaywin(link_id, payment_hash): if paylink.lost == 1: print("lost") return satsdice_renderer().TemplateResponse( - "satsdice/error.html", - link=satsdicelink.id, paid=False, lost=True + "satsdice/error.html", link=satsdicelink.id, paid=False, lost=True ) rand = random.randint(0, 100) chance = satsdicelink.chance @@ -94,8 +93,7 @@ async def displaywin(link_id, payment_hash): await update_satsdice_payment(payment_hash, lost=1) return satsdice_renderer().TemplateResponse( - "satsdice/error.html", - link=satsdicelink.id, paid=False, lost=True + "satsdice/error.html", link=satsdicelink.id, paid=False, lost=True ) withdrawLink = await create_satsdice_withdraw( @@ -131,5 +129,5 @@ async def img(link_id): "Cache-Control": "no-cache, no-store, must-revalidate", "Pragma": "no-cache", "Expires": "0", - } + }, ) diff --git a/lnbits/extensions/satsdice/views_api.py b/lnbits/extensions/satsdice/views_api.py index efd7c055b..9eef79158 100644 --- a/lnbits/extensions/satsdice/views_api.py +++ b/lnbits/extensions/satsdice/views_api.py @@ -5,10 +5,12 @@ from starlette.exceptions import HTTPException from starlette.responses import HTMLResponse, JSONResponse # type: ignore from lnbits.core.crud import get_user from lnbits.decorators import api_validate_post_request -from .models import CreateSatsDiceLink, CreateSatsDiceWithdraws +from .models import CreateSatsDiceLink, CreateSatsDiceWithdraws, CreateSatsDicePayment from . import satsdice_ext from fastapi import FastAPI, Request from fastapi.params import Depends +from typing import Optional +from fastapi.param_functions import Query from .crud import ( create_satsdice_pay, get_satsdice_pay,