general cleanup and unused imports removal

This commit is contained in:
Tiago vasconcelos 2021-11-25 18:52:16 +00:00
parent 2b0bd43974
commit cfac70d394
62 changed files with 159 additions and 442 deletions

View file

@ -1,23 +1,15 @@
from http import HTTPStatus
from typing import List from typing import List
import httpx
from collections import defaultdict
from lnbits.decorators import check_user_exists
from .crud import get_copilot
from functools import wraps from fastapi import Request, WebSocket, WebSocketDisconnect
from fastapi.params import Depends
from fastapi.templating import Jinja2Templates
from starlette.responses import HTMLResponse # type: ignore
from lnbits.core.models import User
from lnbits.decorators import check_user_exists from lnbits.decorators import check_user_exists
from . import copilot_ext, copilot_renderer from . import copilot_ext, copilot_renderer
from fastapi import FastAPI, Request, WebSocket, WebSocketDisconnect from .crud import get_copilot
from fastapi.params import Depends
from fastapi.templating import Jinja2Templates
from fastapi.param_functions import Query
from starlette.exceptions import HTTPException
from starlette.responses import HTMLResponse, JSONResponse # type: ignore
from lnbits.core.models import User
import base64
templates = Jinja2Templates(directory="templates") templates = Jinja2Templates(directory="templates")

View file

@ -5,8 +5,8 @@ from fastapi.params import Depends
from starlette.exceptions import HTTPException from starlette.exceptions import HTTPException
from starlette.requests import Request from starlette.requests import Request
from lnbits.core.crud import get_user, get_wallet from lnbits.core.crud import get_user
from lnbits.core.services import check_invoice_status, create_invoice from lnbits.core.services import create_invoice
from lnbits.core.views.api import api_payment from lnbits.core.views.api import api_payment
from lnbits.decorators import WalletTypeInfo, get_key_type from lnbits.decorators import WalletTypeInfo, get_key_type
from lnbits.extensions.events.models import CreateEvent, CreateTicket from lnbits.extensions.events.models import CreateEvent, CreateTicket
@ -33,7 +33,6 @@ from .crud import (
@events_ext.get("/api/v1/events") @events_ext.get("/api/v1/events")
async def api_events( async def api_events(
r: Request,
all_wallets: bool = Query(False), all_wallets: bool = Query(False),
wallet: WalletTypeInfo = Depends(get_key_type), wallet: WalletTypeInfo = Depends(get_key_type),
): ):
@ -89,7 +88,6 @@ async def api_form_delete(event_id, wallet: WalletTypeInfo = Depends(get_key_typ
@events_ext.get("/api/v1/tickets") @events_ext.get("/api/v1/tickets")
async def api_tickets( async def api_tickets(
r: Request,
all_wallets: bool = Query(False), all_wallets: bool = Query(False),
wallet: WalletTypeInfo = Depends(get_key_type), wallet: WalletTypeInfo = Depends(get_key_type),
): ):

View file

@ -1,7 +1,8 @@
import asyncio import asyncio
from fastapi import APIRouter, FastAPI
from fastapi import APIRouter
from fastapi.staticfiles import StaticFiles from fastapi.staticfiles import StaticFiles
from starlette.routing import Mount
from lnbits.db import Database from lnbits.db import Database
from lnbits.helpers import template_renderer from lnbits.helpers import template_renderer
from lnbits.tasks import catch_everything_and_restart from lnbits.tasks import catch_everything_and_restart
@ -23,9 +24,9 @@ def jukebox_renderer():
return template_renderer(["lnbits/extensions/jukebox/templates"]) return template_renderer(["lnbits/extensions/jukebox/templates"])
from .views_api import * # noqa
from .views import * # noqa
from .tasks import wait_for_paid_invoices from .tasks import wait_for_paid_invoices
from .views import * # noqa
from .views_api import * # noqa
def jukebox_start(): def jukebox_start():

View file

@ -1,9 +1,10 @@
from typing import List, Optional from typing import List, Optional
from . import db
from .models import Jukebox, JukeboxPayment, CreateJukeLinkData, CreateJukeboxPayment
from lnbits.helpers import urlsafe_short_hash from lnbits.helpers import urlsafe_short_hash
from . import db
from .models import CreateJukeboxPayment, CreateJukeLinkData, Jukebox, JukeboxPayment
async def create_jukebox( async def create_jukebox(
data: CreateJukeLinkData, inkey: Optional[str] = "" data: CreateJukeLinkData, inkey: Optional[str] = ""
@ -40,8 +41,6 @@ async def update_jukebox(
q = ", ".join([f"{field[0]} = ?" for field in data]) q = ", ".join([f"{field[0]} = ?" for field in data])
items = [f"{field[1]}" for field in data] items = [f"{field[1]}" for field in data]
items.append(juke_id) items.append(juke_id)
print(q)
print(items)
await db.execute(f"UPDATE jukebox.jukebox SET {q} WHERE id = ?", (items)) await db.execute(f"UPDATE jukebox.jukebox SET {q} WHERE id = ?", (items))
row = await db.fetchone("SELECT * FROM jukebox.jukebox WHERE id = ?", (juke_id,)) row = await db.fetchone("SELECT * FROM jukebox.jukebox WHERE id = ?", (juke_id,))
return Jukebox(**row) if row else None return Jukebox(**row) if row else None
@ -61,7 +60,6 @@ async def get_jukeboxs(user: str) -> List[Jukebox]:
rows = await db.fetchall("SELECT * FROM jukebox.jukebox WHERE user = ?", (user,)) rows = await db.fetchall("SELECT * FROM jukebox.jukebox WHERE user = ?", (user,))
for row in rows: for row in rows:
if row.sp_playlists == None: if row.sp_playlists == None:
print("cunt")
await delete_jukebox(row.id) await delete_jukebox(row.id)
rows = await db.fetchall("SELECT * FROM jukebox.jukebox WHERE user = ?", (user,)) rows = await db.fetchall("SELECT * FROM jukebox.jukebox WHERE user = ?", (user,))

View file

@ -1,12 +1,9 @@
import asyncio import asyncio
import json
import httpx
from lnbits.core import db as core_db
from lnbits.core.models import Payment from lnbits.core.models import Payment
from lnbits.tasks import register_invoice_listener from lnbits.tasks import register_invoice_listener
from .crud import get_jukebox, update_jukebox_payment from .crud import update_jukebox_payment
async def wait_for_paid_invoices(): async def wait_for_paid_invoices():

View file

@ -7,7 +7,7 @@ from starlette.exceptions import HTTPException
from starlette.responses import HTMLResponse from starlette.responses import HTMLResponse
from lnbits.core.models import User from lnbits.core.models import User
from lnbits.decorators import WalletTypeInfo, check_user_exists, get_key_type from lnbits.decorators import check_user_exists
from . import jukebox_ext, jukebox_renderer from . import jukebox_ext, jukebox_renderer
from .crud import get_jukebox from .crud import get_jukebox

View file

@ -9,10 +9,9 @@ from fastapi.params import Depends
from starlette.exceptions import HTTPException from starlette.exceptions import HTTPException
from starlette.responses import HTMLResponse # type: ignore from starlette.responses import HTMLResponse # type: ignore
from lnbits.core.crud import get_wallet from lnbits.core.services import create_invoice
from lnbits.core.views.api import api_payment from lnbits.core.views.api import api_payment
from lnbits.core.services import check_invoice_status, create_invoice from lnbits.decorators import WalletTypeInfo, require_admin_key
from lnbits.decorators import WalletTypeInfo, get_key_type, require_admin_key
from . import jukebox_ext from . import jukebox_ext
from .crud import ( from .crud import (
@ -75,7 +74,6 @@ async def api_check_credentials_callbac(
async def api_check_credentials_check( async def api_check_credentials_check(
juke_id: str = Query(None), wallet: WalletTypeInfo = Depends(require_admin_key) juke_id: str = Query(None), wallet: WalletTypeInfo = Depends(require_admin_key)
): ):
print(juke_id)
jukebox = await get_jukebox(juke_id) jukebox = await get_jukebox(juke_id)
return jukebox return jukebox
@ -238,7 +236,7 @@ async def api_get_jukebox_device_check(
async def api_get_jukebox_invoice(juke_id, song_id): async def api_get_jukebox_invoice(juke_id, song_id):
try: try:
jukebox = await get_jukebox(juke_id) jukebox = await get_jukebox(juke_id)
print(jukebox)
except: except:
raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="No jukebox") raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="No jukebox")
try: try:
@ -269,8 +267,7 @@ async def api_get_jukebox_invoice(juke_id, song_id):
invoice=invoice[1], payment_hash=payment_hash, juke_id=juke_id, song_id=song_id invoice=invoice[1], payment_hash=payment_hash, juke_id=juke_id, song_id=song_id
) )
jukebox_payment = await create_jukebox_payment(data) jukebox_payment = await create_jukebox_payment(data)
print(data)
return data return data

View file

@ -19,12 +19,6 @@ async def wait_for_paid_invoices():
await on_invoice_paid(payment) await on_invoice_paid(payment)
# async def register_listeners():
# invoice_paid_chan_send, invoice_paid_chan_recv = trio.open_memory_channel(2)
# register_invoice_listener(invoice_paid_chan_send)
# await wait_for_paid_invoices(invoice_paid_chan_recv)
async def on_invoice_paid(payment: Payment) -> None: async def on_invoice_paid(payment: Payment) -> None:
if "livestream" != payment.extra.get("tag"): if "livestream" != payment.extra.get("tag"):
# not a livestream invoice # not a livestream invoice

View file

@ -24,7 +24,6 @@ async def index(request: Request, user: User = Depends(check_user_exists)):
@livestream_ext.get("/track/{track_id}", name="livestream.track_redirect_download") @livestream_ext.get("/track/{track_id}", name="livestream.track_redirect_download")
async def track_redirect_download(track_id, p: str = Query(...)): async def track_redirect_download(track_id, p: str = Query(...)):
print("BOO", track_id, p)
payment_hash = p payment_hash = p
track = await get_track(track_id) track = await get_track(track_id)
ls = await get_livestream_by_track(track_id) ls = await get_livestream_by_track(track_id)

View file

@ -29,7 +29,7 @@ async def api_livestream_from_wallet(
ls = await get_or_create_livestream_by_wallet(g.wallet.id) ls = await get_or_create_livestream_by_wallet(g.wallet.id)
tracks = await get_tracks(ls.id) tracks = await get_tracks(ls.id)
producers = await get_producers(ls.id) producers = await get_producers(ls.id)
print("INIT", ls, tracks, producers)
try: try:
return { return {
**ls.dict(), **ls.dict(),

View file

@ -44,6 +44,7 @@ async def update_domain(domain_id: str, **kwargs) -> Domains:
return Domains(**row) return Domains(**row)
async def delete_domain(domain_id: str) -> None: async def delete_domain(domain_id: str) -> None:
await db.execute("DELETE FROM lnaddress.domain WHERE id = ?", (domain_id,)) await db.execute("DELETE FROM lnaddress.domain WHERE id = ?", (domain_id,))
async def get_domain(domain_id: str) -> Optional[Domains]: async def get_domain(domain_id: str) -> Optional[Domains]:
@ -103,10 +104,9 @@ async def get_address(address_id: str) -> Optional[Addresses]:
async def get_address_by_username(username: str, domain: str) -> Optional[Addresses]: async def get_address_by_username(username: str, domain: str) -> Optional[Addresses]:
row = await db.fetchone( row = await db.fetchone(
"SELECT a.* FROM lnaddress.address AS a INNER JOIN lnaddress.domain AS d ON a.username = ? AND d.domain = ?", "SELECT a.* FROM lnaddress.address AS a INNER JOIN lnaddress.domain AS d ON a.username = ? AND d.domain = ?",
# "SELECT * FROM lnaddress.address WHERE username = ? AND domain = ?",
(username, domain,), (username, domain,),
) )
print("ADD", row)
return Addresses(**row) if row else None return Addresses(**row) if row else None
async def delete_address(address_id: str) -> None: async def delete_address(address_id: str) -> None:
@ -121,7 +121,6 @@ async def get_addresses(wallet_ids: Union[str, List[str]]) -> List[Addresses]:
f"SELECT * FROM lnaddress.address WHERE wallet IN ({q})", f"SELECT * FROM lnaddress.address WHERE wallet IN ({q})",
(*wallet_ids,), (*wallet_ids,),
) )
print([Addresses(**row) for row in rows])
return [Addresses(**row) for row in rows] return [Addresses(**row) for row in rows]
async def set_address_paid(payment_hash: str) -> Addresses: async def set_address_paid(payment_hash: str) -> Addresses:

View file

@ -47,21 +47,7 @@ async def lnurl_callback(address_id, amount: int = Query(...)):
).dict() ).dict()
amount_received = amount amount_received = amount
# min = 1000
# max = 1000000000
# if amount_received < min:
# return LnurlErrorResponse(
# reason=f"Amount {amount_received} is smaller than minimum."
# ).dict()
# elif amount_received > max:
# return jsonify(
# LnurlErrorResponse(
# reason=f"Amount {amount_received} is greater than maximum."
# ).dict()
# )
domain = await get_domain(address.domain) domain = await get_domain(address.domain)
base_url = address.wallet_endpoint[:-1] if address.wallet_endpoint.endswith('/') else address.wallet_endpoint base_url = address.wallet_endpoint[:-1] if address.wallet_endpoint.endswith('/') else address.wallet_endpoint

View file

@ -36,6 +36,3 @@ async def m002_addresses(db):
); );
""" """
) )
# async def m003_create_unique_indexes(db):
# await db.execute("CREATE UNIQUE INDEX IF NOT EXISTS address_at_domain ON lnaddress.address (domain, username);")

View file

@ -159,7 +159,6 @@ async def api_lnaddress_make_address(domain_id, data: CreateAddress, user=None,
) )
if user: if user:
print("USER", user, domain.domain)
address = await get_address_by_username(user, domain.domain) address = await get_address_by_username(user, domain.domain)
if not address: if not address:

View file

@ -11,7 +11,6 @@ db = Database("ext_lnticket")
lnticket_ext: APIRouter = APIRouter( lnticket_ext: APIRouter = APIRouter(
prefix="/lnticket", prefix="/lnticket",
tags=["LNTicket"] tags=["LNTicket"]
# "lnticket", __name__, static_folder="static", template_folder="templates"
) )
@ -19,9 +18,9 @@ def lnticket_renderer():
return template_renderer(["lnbits/extensions/lnticket/templates"]) return template_renderer(["lnbits/extensions/lnticket/templates"])
from .views_api import * # noqa
from .views import * # noqa
from .tasks import wait_for_paid_invoices from .tasks import wait_for_paid_invoices
from .views import * # noqa
from .views_api import * # noqa
def lnticket_start(): def lnticket_start():

View file

@ -27,5 +27,3 @@ async def on_invoice_paid(payment: Payment) -> None:
await payment.set_pending(False) await payment.set_pending(False)
await set_ticket_paid(payment.payment_hash) await set_ticket_paid(payment.payment_hash)
_ticket = await get_ticket(payment.checking_id)
print("ticket", _ticket)

View file

@ -1,25 +1,23 @@
from http import HTTPStatus
from fastapi import Request
from fastapi.param_functions import Depends from fastapi.param_functions import Depends
from fastapi.params import Depends
from fastapi.templating import Jinja2Templates
from starlette.exceptions import HTTPException from starlette.exceptions import HTTPException
from starlette.responses import HTMLResponse from starlette.responses import HTMLResponse
from lnbits.core.models import User
from lnbits.core.crud import get_wallet from lnbits.core.crud import get_wallet
from lnbits.core.models import User
from lnbits.decorators import check_user_exists from lnbits.decorators import check_user_exists
from http import HTTPStatus
from . import lnticket_ext, lnticket_renderer from . import lnticket_ext, lnticket_renderer
from .crud import get_form from .crud import get_form
from fastapi import FastAPI, Request
from fastapi.params import Depends
from fastapi.templating import Jinja2Templates
templates = Jinja2Templates(directory="templates") templates = Jinja2Templates(directory="templates")
@lnticket_ext.get("/", response_class=HTMLResponse) @lnticket_ext.get("/", response_class=HTMLResponse)
# not needed as we automatically get the user with the given ID
# If no user with this ID is found, an error is raised
# @validate_uuids(["usr"], required=True)
# @check_user_exists()
async def index(request: Request, user: User = Depends(check_user_exists)): async def index(request: Request, user: User = Depends(check_user_exists)):
return lnticket_renderer().TemplateResponse( return lnticket_renderer().TemplateResponse(
"lnticket/index.html", {"request": request, "user": user.dict()} "lnticket/index.html", {"request": request, "user": user.dict()}
@ -33,7 +31,6 @@ async def display(request: Request, form_id):
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="LNTicket does not exist." status_code=HTTPStatus.NOT_FOUND, detail="LNTicket does not exist."
) )
# abort(HTTPStatus.NOT_FOUND, "LNTicket does not exist.")
wallet = await get_wallet(form.wallet) wallet = await get_wallet(form.wallet)

View file

@ -1,17 +1,13 @@
import re import re
from http import HTTPStatus from http import HTTPStatus
from typing import List
from fastapi import Query from fastapi import Query
from fastapi.params import Depends from fastapi.params import Depends
from pydantic import BaseModel
from starlette.exceptions import HTTPException from starlette.exceptions import HTTPException
from starlette.requests import Request
from starlette.responses import HTMLResponse, JSONResponse # type: ignore
from lnbits.core.crud import get_user
from lnbits.core.services import create_invoice
from lnbits.core.views.api import api_payment from lnbits.core.views.api import api_payment
from lnbits.core.crud import get_user, get_wallet
from lnbits.core.services import check_invoice_status, create_invoice
from lnbits.decorators import WalletTypeInfo, get_key_type from lnbits.decorators import WalletTypeInfo, get_key_type
from lnbits.extensions.lnticket.models import CreateFormData, CreateTicketData from lnbits.extensions.lnticket.models import CreateFormData, CreateTicketData
@ -34,7 +30,6 @@ from .crud import (
@lnticket_ext.get("/api/v1/forms") @lnticket_ext.get("/api/v1/forms")
async def api_forms_get( async def api_forms_get(
r: Request,
all_wallets: bool = Query(False), all_wallets: bool = Query(False),
wallet: WalletTypeInfo = Depends(get_key_type), wallet: WalletTypeInfo = Depends(get_key_type),
): ):
@ -48,17 +43,6 @@ async def api_forms_get(
@lnticket_ext.post("/api/v1/forms", status_code=HTTPStatus.CREATED) @lnticket_ext.post("/api/v1/forms", status_code=HTTPStatus.CREATED)
@lnticket_ext.put("/api/v1/forms/{form_id}") @lnticket_ext.put("/api/v1/forms/{form_id}")
# @api_check_wallet_key("invoice")
# @api_validate_post_request(
# schema={
# "wallet": {"type": "string", "empty": False, "required": True},
# "name": {"type": "string", "empty": False, "required": True},
# "webhook": {"type": "string", "required": False},
# "description": {"type": "string", "min": 0, "required": True},
# "amount": {"type": "integer", "min": 0, "required": True},
# "flatrate": {"type": "integer", "required": True},
# }
# )
async def api_form_create( async def api_form_create(
data: CreateFormData, form_id=None, wallet: WalletTypeInfo = Depends(get_key_type) data: CreateFormData, form_id=None, wallet: WalletTypeInfo = Depends(get_key_type)
): ):
@ -69,13 +53,11 @@ async def api_form_create(
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail=f"Form does not exist." status_code=HTTPStatus.NOT_FOUND, detail=f"Form does not exist."
) )
# return {"message": "Form does not exist."}, HTTPStatus.NOT_FOUND
if form.wallet != wallet.wallet.id: if form.wallet != wallet.wallet.id:
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.FORBIDDEN, detail=f"Not your form." status_code=HTTPStatus.FORBIDDEN, detail=f"Not your form."
) )
# return {"message": "Not your form."}, HTTPStatus.FORBIDDEN
form = await update_form(form_id, **data.dict()) form = await update_form(form_id, **data.dict())
else: else:
@ -84,7 +66,6 @@ async def api_form_create(
@lnticket_ext.delete("/api/v1/forms/{form_id}") @lnticket_ext.delete("/api/v1/forms/{form_id}")
# @api_check_wallet_key("invoice")
async def api_form_delete(form_id, wallet: WalletTypeInfo = Depends(get_key_type)): async def api_form_delete(form_id, wallet: WalletTypeInfo = Depends(get_key_type)):
form = await get_form(form_id) form = await get_form(form_id)
@ -92,15 +73,12 @@ async def api_form_delete(form_id, wallet: WalletTypeInfo = Depends(get_key_type
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail=f"Form does not exist." status_code=HTTPStatus.NOT_FOUND, detail=f"Form does not exist."
) )
# return {"message": "Form does not exist."}, HTTPStatus.NOT_FOUND
if form.wallet != wallet.wallet.id: if form.wallet != wallet.wallet.id:
raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail=f"Not your form.") raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail=f"Not your form.")
# return {"message": "Not your form."}, HTTPStatus.FORBIDDEN
await delete_form(form_id) await delete_form(form_id)
# return "", HTTPStatus.NO_CONTENT
raise HTTPException(status_code=HTTPStatus.NO_CONTENT) raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
@ -108,7 +86,6 @@ async def api_form_delete(form_id, wallet: WalletTypeInfo = Depends(get_key_type
@lnticket_ext.get("/api/v1/tickets") @lnticket_ext.get("/api/v1/tickets")
# @api_check_wallet_key("invoice")
async def api_tickets( async def api_tickets(
all_wallets: bool = Query(False), wallet: WalletTypeInfo = Depends(get_key_type) all_wallets: bool = Query(False), wallet: WalletTypeInfo = Depends(get_key_type)
): ):
@ -121,22 +98,12 @@ async def api_tickets(
@lnticket_ext.post("/api/v1/tickets/{form_id}", status_code=HTTPStatus.CREATED) @lnticket_ext.post("/api/v1/tickets/{form_id}", status_code=HTTPStatus.CREATED)
# @api_validate_post_request(
# schema={
# "form": {"type": "string", "empty": False, "required": True},
# "name": {"type": "string", "empty": False, "required": True},
# "email": {"type": "string", "empty": True, "required": True},
# "ltext": {"type": "string", "empty": False, "required": True},
# "sats": {"type": "integer", "min": 0, "required": True},
# }
# )
async def api_ticket_make_ticket(data: CreateTicketData, form_id): async def api_ticket_make_ticket(data: CreateTicketData, form_id):
form = await get_form(form_id) form = await get_form(form_id)
if not form: if not form:
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail=f"LNTicket does not exist." status_code=HTTPStatus.NOT_FOUND, detail=f"LNTicket does not exist."
) )
# return {"message": "LNTicket does not exist."}, HTTPStatus.NOT_FOUND
nwords = len(re.split(r"\s+", data.ltext)) nwords = len(re.split(r"\s+", data.ltext))
@ -149,7 +116,6 @@ async def api_ticket_make_ticket(data: CreateTicketData, form_id):
) )
except Exception as e: except Exception as e:
raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=str(e)) raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=str(e))
# return {"message": str(e)}, HTTPStatus.INTERNAL_SERVER_ERROR
ticket = await create_ticket( ticket = await create_ticket(
payment_hash=payment_hash, wallet=form.wallet, data=data payment_hash=payment_hash, wallet=form.wallet, data=data
@ -159,10 +125,6 @@ async def api_ticket_make_ticket(data: CreateTicketData, form_id):
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="LNTicket could not be fetched." status_code=HTTPStatus.NOT_FOUND, detail="LNTicket could not be fetched."
) )
# return (
# {"message": "LNTicket could not be fetched."},
# HTTPStatus.NOT_FOUND,
# )
return {"payment_hash": payment_hash, "payment_request": payment_request} return {"payment_hash": payment_hash, "payment_request": payment_request}
@ -183,7 +145,6 @@ async def api_ticket_send_ticket(payment_hash):
@lnticket_ext.delete("/api/v1/tickets/{ticket_id}") @lnticket_ext.delete("/api/v1/tickets/{ticket_id}")
# @api_check_wallet_key("invoice")
async def api_ticket_delete(ticket_id, wallet: WalletTypeInfo = Depends(get_key_type)): async def api_ticket_delete(ticket_id, wallet: WalletTypeInfo = Depends(get_key_type)):
ticket = await get_ticket(ticket_id) ticket = await get_ticket(ticket_id)
@ -191,12 +152,9 @@ async def api_ticket_delete(ticket_id, wallet: WalletTypeInfo = Depends(get_key_
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail=f"LNTicket does not exist." status_code=HTTPStatus.NOT_FOUND, detail=f"LNTicket does not exist."
) )
# return {"message": "Paywall does not exist."}, HTTPStatus.NOT_FOUND
if ticket.wallet != wallet.wallet.id: if ticket.wallet != wallet.wallet.id:
raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="Not your ticket.") raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="Not your ticket.")
# return {"message": "Not your ticket."}, HTTPStatus.FORBIDDEN
await delete_ticket(ticket_id) await delete_ticket(ticket_id)
raise HTTPException(status_code=HTTPStatus.NO_CONTENT) raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
# return ""

View file

@ -20,7 +20,6 @@ lnurlp_static_files = [
lnurlp_ext: APIRouter = APIRouter( lnurlp_ext: APIRouter = APIRouter(
prefix="/lnurlp", prefix="/lnurlp",
tags=["lnurlp"] tags=["lnurlp"]
# "lnurlp", __name__, static_folder="static", template_folder="templates"
) )
@ -37,8 +36,3 @@ from .views_api import * # noqa
def lnurlp_start(): def lnurlp_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))
# from lnbits.tasks import record_async
# lnurlp_ext.record(record_async(register_listeners))

View file

@ -110,7 +110,6 @@ async def api_link_create_or_update(
link = await update_pay_link(**data.dict(), link_id=link_id) link = await update_pay_link(**data.dict(), link_id=link_id)
else: else:
link = await create_pay_link(data, wallet_id=wallet.wallet.id) link = await create_pay_link(data, wallet_id=wallet.wallet.id)
print("LINK", link)
return {**link.dict(), "lnurl": link.lnurl} return {**link.dict(), "lnurl": link.lnurl}

View file

@ -1,10 +1,7 @@
import asyncio from fastapi import APIRouter
from fastapi import APIRouter, FastAPI
from fastapi.staticfiles import StaticFiles
from starlette.routing import Mount
from lnbits.db import Database from lnbits.db import Database
from lnbits.helpers import template_renderer from lnbits.helpers import template_renderer
from lnbits.tasks import catch_everything_and_restart
db = Database("ext_lnurlpos") db = Database("ext_lnurlpos")
@ -15,6 +12,6 @@ def lnurlpos_renderer():
return template_renderer(["lnbits/extensions/lnurlpos/templates"]) return template_renderer(["lnbits/extensions/lnurlpos/templates"])
from .views_api import * # noqa
from .views import * # noqa
from .lnurl import * # noqa from .lnurl import * # noqa
from .views import * # noqa
from .views_api import * # noqa

View file

@ -1,15 +1,14 @@
from datetime import datetime
from typing import List, Optional, Union from typing import List, Optional, Union
from lnbits.helpers import urlsafe_short_hash from lnbits.helpers import urlsafe_short_hash
from typing import List, Optional
from . import db from . import db
from .models import lnurlposs, lnurlpospayment, createLnurlpos from .models import createLnurlpos, lnurlpospayment, lnurlposs
###############lnurlposS########################## ###############lnurlposS##########################
async def create_lnurlpos(data: createLnurlpos,) -> lnurlposs: async def create_lnurlpos(data: createLnurlpos,) -> lnurlposs:
print(data)
lnurlpos_id = urlsafe_short_hash() lnurlpos_id = urlsafe_short_hash()
lnurlpos_key = urlsafe_short_hash() lnurlpos_key = urlsafe_short_hash()
await db.execute( await db.execute(

View file

@ -1,30 +1,21 @@
import json
import hashlib import hashlib
import math from http import HTTPStatus
from lnurl import (
LnurlPayResponse,
LnurlPayActionResponse,
LnurlErrorResponse,
) # type: ignore
from lnurl.types import LnurlPayMetadata
from lnbits.core.services import create_invoice
from hashlib import md5
from fastapi import Request from fastapi import Request
from fastapi.param_functions import Query from fastapi.param_functions import Query
from . import lnurlpos_ext from lnurl import LnurlPayActionResponse, LnurlPayResponse # type: ignore
from fastapi.templating import Jinja2Templates
from starlette.exceptions import HTTPException from starlette.exceptions import HTTPException
from starlette.responses import HTMLResponse
from http import HTTPStatus from lnbits.core.services import create_invoice
from fastapi.params import Depends from lnbits.utils.exchange_rates import fiat_amount_as_satoshis
from fastapi.param_functions import Query
from . import lnurlpos_ext
from .crud import ( from .crud import (
get_lnurlpos,
create_lnurlpospayment, create_lnurlpospayment,
get_lnurlpos,
get_lnurlpospayment, get_lnurlpospayment,
update_lnurlpospayment, update_lnurlpospayment,
) )
from lnbits.utils.exchange_rates import fiat_amount_as_satoshis
@lnurlpos_ext.get( @lnurlpos_ext.get(
@ -92,9 +83,7 @@ async def lnurl_response(
name="lnurlpos.lnurl_callback", name="lnurlpos.lnurl_callback",
) )
async def lnurl_callback(request: Request, paymentid: str = Query(None)): async def lnurl_callback(request: Request, paymentid: str = Query(None)):
print("lnurlpospayment")
lnurlpospayment = await get_lnurlpospayment(paymentid) lnurlpospayment = await get_lnurlpospayment(paymentid)
print(lnurlpospayment)
pos = await get_lnurlpos(lnurlpospayment.posid) pos = await get_lnurlpos(lnurlpospayment.posid)
if not pos: if not pos:
raise HTTPException( raise HTTPException(

View file

@ -1,16 +1,14 @@
import json import json
from lnurl import Lnurl, LnurlWithdrawResponse, encode as lnurl_encode # type: ignore
from urllib.parse import urlparse, urlunparse, parse_qs, urlencode, ParseResult
from lnurl.types import LnurlPayMetadata # type: ignore
from lnurl.models import LnurlPaySuccessAction, UrlAction # type: ignore
from sqlite3 import Row from sqlite3 import Row
from typing import NamedTuple, Optional, Dict
import shortuuid # type: ignore
from fastapi.param_functions import Query
from pydantic.main import BaseModel
from pydantic import BaseModel
from typing import Optional from typing import Optional
from fastapi import FastAPI, Request
from fastapi import Request
from lnurl import Lnurl
from lnurl import encode as lnurl_encode # type: ignore
from lnurl.models import LnurlPaySuccessAction, UrlAction # type: ignore
from lnurl.types import LnurlPayMetadata # type: ignore
from pydantic import BaseModel
from pydantic.main import BaseModel
class createLnurlpos(BaseModel): class createLnurlpos(BaseModel):

View file

@ -1,27 +1,19 @@
from http import HTTPStatus from http import HTTPStatus
import httpx
from collections import defaultdict
from lnbits.decorators import check_user_exists
from .crud import get_lnurlpos, get_lnurlpospayment from fastapi import Request
from functools import wraps from fastapi.param_functions import Query
from lnbits.core.crud import get_standalone_payment from fastapi.params import Depends
import hashlib
from lnbits.core.services import check_invoice_status
from lnbits.core.crud import update_payment_status
from lnbits.core.views.api import api_payment
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates from fastapi.templating import Jinja2Templates
from starlette.exceptions import HTTPException from starlette.exceptions import HTTPException
from starlette.responses import HTMLResponse from starlette.responses import HTMLResponse
from fastapi.params import Depends
from fastapi.param_functions import Query
import random
from datetime import datetime from lnbits.core.crud import update_payment_status
from http import HTTPStatus from lnbits.core.models import User
from lnbits.core.views.api import api_payment
from lnbits.decorators import check_user_exists
from . import lnurlpos_ext, lnurlpos_renderer from . import lnurlpos_ext, lnurlpos_renderer
from lnbits.core.models import User, Payment from .crud import get_lnurlpos, get_lnurlpospayment
templates = Jinja2Templates(directory="templates") templates = Jinja2Templates(directory="templates")

View file

@ -32,14 +32,12 @@ async def api_list_currencies_available():
@lnurlpos_ext.post("/api/v1/lnurlpos") @lnurlpos_ext.post("/api/v1/lnurlpos")
@lnurlpos_ext.put("/api/v1/lnurlpos/{lnurlpos_id}") @lnurlpos_ext.put("/api/v1/lnurlpos/{lnurlpos_id}")
async def api_lnurlpos_create_or_update( async def api_lnurlpos_create_or_update(
request: Request,
data: createLnurlpos, data: createLnurlpos,
wallet: WalletTypeInfo = Depends(require_admin_key), wallet: WalletTypeInfo = Depends(require_admin_key),
lnurlpos_id: str = Query(None), lnurlpos_id: str = Query(None),
): ):
if not lnurlpos_id: if not lnurlpos_id:
lnurlpos = await create_lnurlpos(data) lnurlpos = await create_lnurlpos(data)
print(lnurlpos.dict())
return lnurlpos.dict() return lnurlpos.dict()
else: else:
lnurlpos = await update_lnurlpos(data, lnurlpos_id=lnurlpos_id) lnurlpos = await update_lnurlpos(data, lnurlpos_id=lnurlpos_id)
@ -48,7 +46,7 @@ async def api_lnurlpos_create_or_update(
@lnurlpos_ext.get("/api/v1/lnurlpos") @lnurlpos_ext.get("/api/v1/lnurlpos")
async def api_lnurlposs_retrieve( async def api_lnurlposs_retrieve(
request: Request, wallet: WalletTypeInfo = Depends(get_key_type) 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:
@ -75,7 +73,6 @@ async def api_lnurlpos_retrieve(
@lnurlpos_ext.delete("/api/v1/lnurlpos/{lnurlpos_id}") @lnurlpos_ext.delete("/api/v1/lnurlpos/{lnurlpos_id}")
async def api_lnurlpos_delete( async def api_lnurlpos_delete(
request: Request,
wallet: WalletTypeInfo = Depends(require_admin_key), wallet: WalletTypeInfo = Depends(require_admin_key),
lnurlpos_id: str = Query(None), lnurlpos_id: str = Query(None),
): ):

View file

@ -1,10 +1,7 @@
import asyncio from fastapi import APIRouter
from fastapi import APIRouter, FastAPI
from fastapi.staticfiles import StaticFiles
from starlette.routing import Mount
from lnbits.db import Database from lnbits.db import Database
from lnbits.helpers import template_renderer from lnbits.helpers import template_renderer
from lnbits.tasks import catch_everything_and_restart
db = Database("ext_ngrok") db = Database("ext_ngrok")

View file

@ -1,24 +1,21 @@
from http import HTTPStatus
from os import getenv
from fastapi import Request
from fastapi.params import Depends
from fastapi.templating import Jinja2Templates
from pyngrok import conf, ngrok
from lnbits.core.models import User
from lnbits.decorators import check_user_exists from lnbits.decorators import check_user_exists
from . import ngrok_ext, ngrok_renderer from . import ngrok_ext, ngrok_renderer
from fastapi import FastAPI, Request
from fastapi.params import Depends
from fastapi.templating import Jinja2Templates
from starlette.exceptions import HTTPException
from starlette.responses import HTMLResponse
from lnbits.core.models import User
from os import getenv
from pyngrok import conf, ngrok
templates = Jinja2Templates(directory="templates") templates = Jinja2Templates(directory="templates")
def log_event_callback(log): def log_event_callback(log):
string = str(log) string = str(log)
print(string)
string2 = string[string.find('url="https') : string.find('url="https') + 80] string2 = string[string.find('url="https') : string.find('url="https') + 80]
if string2: if string2:
string3 = string2 string3 = string2

View file

@ -1,6 +1,5 @@
from fastapi import APIRouter, FastAPI from fastapi import APIRouter
from fastapi.staticfiles import StaticFiles from fastapi.staticfiles import StaticFiles
from starlette.routing import Mount
from lnbits.db import Database from lnbits.db import Database
from lnbits.helpers import template_renderer from lnbits.helpers import template_renderer
@ -18,13 +17,6 @@ offlineshop_static_files = [
offlineshop_ext: APIRouter = APIRouter( offlineshop_ext: APIRouter = APIRouter(
prefix="/offlineshop", prefix="/offlineshop",
tags=["Offlineshop"], tags=["Offlineshop"],
# routes=[
# Mount(
# "/static",
# app=StaticFiles(directory="lnbits/extensions/offlineshop/static"),
# name="offlineshop_static",
# )
# ],
) )

View file

@ -1,20 +1,19 @@
import hashlib import hashlib
from lnbits.extensions.offlineshop.models import Item
from fastapi.params import Query
from starlette.requests import Request from fastapi.params import Query
from lnbits.helpers import url_for from lnurl import ( # type: ignore
from lnurl import (
LnurlPayResponse,
LnurlPayActionResponse,
LnurlErrorResponse, LnurlErrorResponse,
) # type: ignore LnurlPayActionResponse,
LnurlPayResponse,
)
from starlette.requests import Request
from lnbits.core.services import create_invoice from lnbits.core.services import create_invoice
from lnbits.extensions.offlineshop.models import Item
from lnbits.utils.exchange_rates import fiat_amount_as_satoshis from lnbits.utils.exchange_rates import fiat_amount_as_satoshis
from . import offlineshop_ext from . import offlineshop_ext
from .crud import get_shop, get_item from .crud import get_item, get_shop
@offlineshop_ext.get("/lnurl/{item_id}", name="offlineshop.lnurl_response") @offlineshop_ext.get("/lnurl/{item_id}", name="offlineshop.lnurl_response")

View file

@ -1,6 +1,3 @@
from sqlalchemy.exc import OperationalError # type: ignore
async def m001_initial(db): async def m001_initial(db):
""" """
Initial paywalls table. Initial paywalls table.

View file

@ -59,8 +59,6 @@ async def api_paywall_create_invoice(
wallet: WalletTypeInfo = Depends(get_key_type), wallet: WalletTypeInfo = Depends(get_key_type),
): ):
paywall = await get_paywall(paywall_id) paywall = await get_paywall(paywall_id)
print("PAYW", paywall)
print("DATA", data)
if data.amount < paywall.amount: if data.amount < paywall.amount:
raise HTTPException( raise HTTPException(

View file

@ -1,10 +1,7 @@
import asyncio from fastapi import APIRouter
from fastapi import APIRouter, FastAPI
from fastapi.staticfiles import StaticFiles
from starlette.routing import Mount
from lnbits.db import Database from lnbits.db import Database
from lnbits.helpers import template_renderer from lnbits.helpers import template_renderer
from lnbits.tasks import catch_everything_and_restart
db = Database("ext_satsdice") db = Database("ext_satsdice")
@ -15,11 +12,6 @@ def satsdice_renderer():
return template_renderer(["lnbits/extensions/satsdice/templates"]) return template_renderer(["lnbits/extensions/satsdice/templates"])
from .views_api import * # noqa
from .views import * # noqa
from .lnurl import * # noqa from .lnurl import * # noqa
from .views import * # noqa
from .views_api import * # noqa
# def satsdice_start():
# loop = asyncio.get_event_loop()
# loop.create_task(catch_everything_and_restart(wait_for_paid_invoices))

View file

@ -52,7 +52,6 @@ async def api_lnurlp_callback(
req: Request, link_id: str = Query(None), amount: str = Query(None) req: Request, link_id: str = Query(None), amount: str = Query(None)
): ):
link = await get_satsdice_pay(link_id) link = await get_satsdice_pay(link_id)
print(link)
if not link: if not link:
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="LNURL-pay not found." status_code=HTTPStatus.NOT_FOUND, detail="LNURL-pay not found."
@ -94,7 +93,6 @@ async def api_lnurlp_callback(
await create_satsdice_payment(data) await create_satsdice_payment(data)
payResponse = {"pr": payment_request, "successAction": success_action, "routes": []} payResponse = {"pr": payment_request, "successAction": success_action, "routes": []}
print(json.dumps(payResponse))
return json.dumps(payResponse) return json.dumps(payResponse)
@ -130,7 +128,6 @@ async def api_lnurlw_response(req: Request, unique_hash: str = Query(None)):
# CALLBACK # CALLBACK
@satsdice_ext.get( @satsdice_ext.get(
"/api/v1/lnurlw/cb/{unique_hash}", "/api/v1/lnurlw/cb/{unique_hash}",
status_code=HTTPStatus.OK, status_code=HTTPStatus.OK,
@ -148,7 +145,6 @@ async def api_lnurlw_callback(
return {"status": "ERROR", "reason": "no withdraw"} return {"status": "ERROR", "reason": "no withdraw"}
if link.used: if link.used:
return {"status": "ERROR", "reason": "spent"} return {"status": "ERROR", "reason": "spent"}
print("winner")
paylink = await get_satsdice_pay(link.satsdice_pay) paylink = await get_satsdice_pay(link.satsdice_pay)
await update_satsdice_withdraw(link.id, used=1) await update_satsdice_withdraw(link.id, used=1)

View file

@ -1,10 +1,8 @@
import json import json
from sqlite3 import Row from sqlite3 import Row
from typing import Dict, NamedTuple, Optional from typing import Dict, Optional
from urllib.parse import ParseResult, parse_qs, urlencode, urlparse, urlunparse
import shortuuid # type: ignore from fastapi import Request
from fastapi import FastAPI, Request
from fastapi.param_functions import Query from fastapi.param_functions import Query
from lnurl import Lnurl, LnurlWithdrawResponse from lnurl import Lnurl, LnurlWithdrawResponse
from lnurl import encode as lnurl_encode # type: ignore from lnurl import encode as lnurl_encode # type: ignore

View file

@ -1,24 +1,16 @@
import random import random
from datetime import datetime
from http import HTTPStatus from http import HTTPStatus
from fastapi import FastAPI, Request from fastapi import Request
from fastapi.param_functions import Query from fastapi.param_functions import Query
from fastapi.params import Depends from fastapi.params import Depends
from fastapi.templating import Jinja2Templates from fastapi.templating import Jinja2Templates
from starlette.exceptions import HTTPException from starlette.exceptions import HTTPException
from starlette.responses import HTMLResponse from starlette.responses import HTMLResponse
from lnbits.core.crud import ( from lnbits.core.models import User
delete_expired_invoices,
get_balance_checks,
get_payments,
get_standalone_payment,
)
from lnbits.core.models import Payment, User
from lnbits.core.services import check_invoice_status
from lnbits.core.views.api import api_payment from lnbits.core.views.api import api_payment
from lnbits.decorators import WalletTypeInfo, check_user_exists, get_key_type from lnbits.decorators import check_user_exists
from . import satsdice_ext, satsdice_renderer from . import satsdice_ext, satsdice_renderer
from .crud import ( from .crud import (

View file

@ -7,20 +7,15 @@ from lnurl.exceptions import InvalidUrl as LnurlInvalidUrl # type: ignore
from starlette.exceptions import HTTPException from starlette.exceptions import HTTPException
from lnbits.core.crud import get_user from lnbits.core.crud import get_user
from lnbits.decorators import WalletTypeInfo, get_key_type, require_admin_key from lnbits.decorators import WalletTypeInfo, get_key_type
from . import satsdice_ext from . import satsdice_ext
from .crud import ( from .crud import (
create_satsdice_pay, create_satsdice_pay,
create_satsdice_withdraw,
delete_satsdice_pay, delete_satsdice_pay,
delete_satsdice_withdraw,
get_satsdice_pay, get_satsdice_pay,
get_satsdice_pays, get_satsdice_pays,
get_satsdice_withdraw,
get_satsdice_withdraws,
update_satsdice_pay, update_satsdice_pay,
update_satsdice_withdraw,
) )
from .models import CreateSatsDiceLink, CreateSatsDiceWithdraws, satsdiceLink from .models import CreateSatsDiceLink, CreateSatsDiceWithdraws, satsdiceLink
@ -51,7 +46,6 @@ async def api_links(
@satsdice_ext.get("/api/v1/links/{link_id}") @satsdice_ext.get("/api/v1/links/{link_id}")
async def api_link_retrieve( async def api_link_retrieve(
data: CreateSatsDiceLink,
link_id: str = Query(None), link_id: str = Query(None),
wallet: WalletTypeInfo = Depends(get_key_type), wallet: WalletTypeInfo = Depends(get_key_type),
): ):

View file

@ -1,5 +1,3 @@
import asyncio
from fastapi import APIRouter from fastapi import APIRouter
from lnbits.db import Database from lnbits.db import Database
@ -15,5 +13,5 @@ def satspay_renderer():
return template_renderer(["lnbits/extensions/satspay/templates"]) return template_renderer(["lnbits/extensions/satspay/templates"])
from .views_api import * # noqa
from .views import * # noqa from .views import * # noqa
from .views_api import * # noqa

View file

@ -1,16 +1,17 @@
from typing import List, Optional, Union from typing import List, Optional
import httpx
from lnbits.core.services import create_invoice
from lnbits.core.views.api import api_payment
from lnbits.helpers import urlsafe_short_hash
from ..watchonly.crud import get_fresh_address, get_mempool, get_watch_wallet
# from lnbits.db import open_ext_db # from lnbits.db import open_ext_db
from . import db from . import db
from .models import Charges, CreateCharge from .models import Charges, CreateCharge
from lnbits.helpers import urlsafe_short_hash
import httpx
from lnbits.core.services import create_invoice, check_invoice_status
from ..watchonly.crud import get_watch_wallet, get_fresh_address, get_mempool
from lnbits.core.views.api import api_payment
###############CHARGES########################## ###############CHARGES##########################

View file

@ -1,13 +1,13 @@
from fastapi.param_functions import Depends
from starlette.exceptions import HTTPException
from starlette.responses import HTMLResponse
from starlette.requests import Request
from lnbits.core.models import User
from lnbits.core.crud import get_wallet
from lnbits.decorators import check_user_exists
from http import HTTPStatus from http import HTTPStatus
from fastapi.param_functions import Depends
from fastapi.templating import Jinja2Templates from fastapi.templating import Jinja2Templates
from starlette.exceptions import HTTPException
from starlette.requests import Request
from starlette.responses import HTMLResponse
from lnbits.core.models import User
from lnbits.decorators import check_user_exists
from . import satspay_ext, satspay_renderer from . import satspay_ext, satspay_renderer
from .crud import get_charge from .crud import get_charge

View file

@ -7,7 +7,7 @@ from starlette.exceptions import HTTPException
from lnbits.decorators import WalletTypeInfo, get_key_type, require_admin_key from lnbits.decorators import WalletTypeInfo, get_key_type, require_admin_key
from lnbits.extensions.satspay import satspay_ext from lnbits.extensions.satspay import satspay_ext
from lnbits.core.views.api import api_payment
from .crud import ( from .crud import (
check_address_balance, check_address_balance,
create_charge, create_charge,

View file

@ -1,7 +1,8 @@
import asyncio import asyncio
from fastapi import APIRouter, FastAPI
from fastapi import APIRouter
from fastapi.staticfiles import StaticFiles from fastapi.staticfiles import StaticFiles
from starlette.routing import Mount
from lnbits.db import Database from lnbits.db import Database
from lnbits.helpers import template_renderer from lnbits.helpers import template_renderer
from lnbits.tasks import catch_everything_and_restart from lnbits.tasks import catch_everything_and_restart
@ -23,14 +24,9 @@ splitpayments_ext: APIRouter = APIRouter(
def splitpayments_renderer(): def splitpayments_renderer():
return template_renderer(["lnbits/extensions/splitpayments/templates"]) return template_renderer(["lnbits/extensions/splitpayments/templates"])
# from lnbits.tasks import record_async
# splitpayments_ext.record(record_async(register_listeners))
from .views_api import * # noqa
from .views import * # noqa
from .tasks import wait_for_paid_invoices from .tasks import wait_for_paid_invoices
from .views import * # noqa
from .views_api import * # noqa
def splitpayments_start(): def splitpayments_start():

View file

@ -1,21 +1,15 @@
import asyncio
import json import json
from lnbits.core.models import Payment
from lnbits.core.crud import create_payment
from lnbits.core import db as core_db from lnbits.core import db as core_db
from lnbits.tasks import register_invoice_listener, internal_invoice_queue from lnbits.core.crud import create_payment
from lnbits.core.models import Payment
from lnbits.helpers import urlsafe_short_hash from lnbits.helpers import urlsafe_short_hash
from lnbits.tasks import internal_invoice_queue, register_invoice_listener
from .crud import get_targets from .crud import get_targets
import asyncio
import httpx
from lnbits.core import db as core_db
from lnbits.core.models import Payment
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) register_invoice_listener(invoice_queue)

View file

@ -26,7 +26,6 @@ async def api_targets_set(
targets = [] targets = []
data = TargetPut.parse_obj(body["targets"]) data = TargetPut.parse_obj(body["targets"])
for entry in data.__root__: for entry in data.__root__:
print("ENTRY", entry)
wallet = await get_wallet(entry.wallet) wallet = await get_wallet(entry.wallet)
if not wallet: if not wallet:
wallet = await get_wallet_for_key(entry.wallet, "invoice") wallet = await get_wallet_for_key(entry.wallet, "invoice")

View file

@ -97,7 +97,6 @@ async def post_donation(donation_id: str) -> tuple:
} }
async with httpx.AsyncClient() as client: async with httpx.AsyncClient() as client:
response = await client.post(url, data=data) response = await client.post(url, data=data)
print(response.json())
status = [s for s in list(HTTPStatus) if s == response.status_code][0] status = [s for s in list(HTTPStatus) if s == response.status_code][0]
elif service.servicename == "StreamElements": elif service.servicename == "StreamElements":
return {"message": "StreamElements not yet supported!"} return {"message": "StreamElements not yet supported!"}
@ -191,10 +190,8 @@ async def authenticate_service(service_id, code, redirect_uri):
"client_secret": service.client_secret, "client_secret": service.client_secret,
"redirect_uri": redirect_uri, "redirect_uri": redirect_uri,
} }
print(data)
async with httpx.AsyncClient() as client: async with httpx.AsyncClient() as client:
response = (await client.post(url, data=data)).json() response = (await client.post(url, data=data)).json()
print(response)
token = response["access_token"] token = response["access_token"]
success = await service_add_token(service_id, token) success = await service_add_token(service_id, token)
return f"/streamalerts/?usr={user}", success return f"/streamalerts/?usr={user}", success

View file

@ -77,7 +77,6 @@ async def get_subdomainBySubdomain(subdomain: str) -> Optional[Subdomains]:
"SELECT s.*, d.domain as domain_name FROM subdomains.subdomain s INNER JOIN domain d ON (s.domain = d.id) WHERE s.subdomain = ?", "SELECT s.*, d.domain as domain_name FROM subdomains.subdomain s INNER JOIN domain d ON (s.domain = d.id) WHERE s.subdomain = ?",
(subdomain,), (subdomain,),
) )
print(row)
return Subdomains(**row) if row else None return Subdomains(**row) if row else None

View file

@ -18,17 +18,6 @@ async def wait_for_paid_invoices():
await on_invoice_paid(payment) await on_invoice_paid(payment)
# async def register_listeners():
# invoice_paid_chan_send, invoice_paid_chan_recv = trio.open_memory_channel(2)
# register_invoice_listener(invoice_paid_chan_send)
# await wait_for_paid_invoices(invoice_paid_chan_recv)
# async def wait_for_paid_invoices(invoice_paid_chan: trio.MemoryReceiveChannel):
# async for payment in invoice_paid_chan:
# await on_invoice_paid(payment)
async def on_invoice_paid(payment: Payment) -> None: async def on_invoice_paid(payment: Payment) -> None:
if "lnsubdomain" != payment.extra.get("tag"): if "lnsubdomain" != payment.extra.get("tag"):
# not an lnurlp invoice # not an lnurlp invoice

View file

@ -1,11 +1,7 @@
from lnbits.extensions.subdomains.models import Subdomains
# Python3 program to validate
# domain name
# using regular expression
import re import re
import socket import socket
# Function to validate domain name. # Function to validate domain name.
def isValidDomain(str): def isValidDomain(str):
# Regex to check valid # Regex to check valid

View file

@ -1,12 +1,11 @@
from . import db
from .models import Tip, TipJar, createTip, createTipJar
from ..satspay.crud import delete_charge # type: ignore
from typing import Optional from typing import Optional
from lnbits.db import SQLITE from lnbits.db import SQLITE
from ..satspay.crud import delete_charge # type: ignore
from . import db
from .models import Tip, TipJar, createTipJar
async def create_tip( async def create_tip(
id: int, wallet: str, message: str, name: str, sats: int, tipjar: str id: int, wallet: str, message: str, name: str, sats: int, tipjar: str

View file

@ -1,6 +1,6 @@
from lnbits.core.crud import get_wallet from lnbits.core.crud import get_wallet
from .crud import get_tipjar from .crud import get_tipjar
import json
async def get_charge_details(tipjar_id): async def get_charge_details(tipjar_id):

View file

@ -1,15 +1,9 @@
import json
from lnurl import Lnurl, LnurlWithdrawResponse, encode as lnurl_encode # type: ignore
from urllib.parse import urlparse, urlunparse, parse_qs, urlencode, ParseResult
from lnurl.types import LnurlPayMetadata # type: ignore
from sqlite3 import Row from sqlite3 import Row
from typing import NamedTuple, Optional, Dict from typing import NamedTuple, Optional
import shortuuid # type: ignore
from fastapi.param_functions import Query from fastapi.param_functions import Query
from pydantic.main import BaseModel
from pydantic import BaseModel from pydantic import BaseModel
from typing import Optional, NamedTuple from pydantic.main import BaseModel
from fastapi import FastAPI, Request
class CreateCharge(BaseModel): class CreateCharge(BaseModel):

View file

@ -1,26 +1,16 @@
from .crud import get_tipjar
from http import HTTPStatus from http import HTTPStatus
import httpx
from collections import defaultdict
from lnbits.decorators import check_user_exists
from functools import wraps from fastapi import Request
import hashlib from fastapi.param_functions import Query
from lnbits.core.services import check_invoice_status from fastapi.params import Depends
from lnbits.core.crud import update_payment_status, get_standalone_payment
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates from fastapi.templating import Jinja2Templates
from starlette.exceptions import HTTPException from starlette.exceptions import HTTPException
from starlette.responses import HTMLResponse
from fastapi.params import Depends
from fastapi.param_functions import Query
import random
from datetime import datetime from lnbits.core.models import User
from http import HTTPStatus from lnbits.decorators import check_user_exists
from . import tipjar_ext, tipjar_renderer from . import tipjar_ext, tipjar_renderer
from lnbits.core.models import User, Payment from .crud import get_tipjar
templates = Jinja2Templates(directory="templates") templates = Jinja2Templates(directory="templates")
@ -36,7 +26,6 @@ async def index(request: Request, user: User = Depends(check_user_exists)):
async def tip(request: Request, tipjar_id: int = Query(None)): async def tip(request: Request, tipjar_id: int = Query(None)):
"""Return the donation form for the Tipjar corresponding to id""" """Return the donation form for the Tipjar corresponding to id"""
tipjar = await get_tipjar(tipjar_id) tipjar = await get_tipjar(tipjar_id)
print(tipjar_id)
if not tipjar: if not tipjar:
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="TipJar does not exist." status_code=HTTPStatus.NOT_FOUND, detail="TipJar does not exist."

View file

@ -1,30 +1,28 @@
from http import HTTPStatus from http import HTTPStatus
import json
from fastapi import Request
from fastapi.param_functions import Query from fastapi.param_functions import Query
from fastapi.params import Depends from fastapi.params import Depends
from lnurl.exceptions import InvalidUrl as LnurlInvalidUrl # type: ignore
from starlette.exceptions import HTTPException from starlette.exceptions import HTTPException
from lnbits.decorators import WalletTypeInfo, get_key_type
from lnbits.core.crud import get_user from lnbits.core.crud import get_user
from lnbits.decorators import WalletTypeInfo, get_key_type
from ..satspay.crud import create_charge
from . import tipjar_ext from . import tipjar_ext
from .helpers import get_charge_details
from .crud import ( from .crud import (
create_tipjar,
get_tipjar,
create_tip, create_tip,
get_tipjars, create_tipjar,
delete_tip,
delete_tipjar,
get_tip, get_tip,
get_tipjar,
get_tipjars,
get_tips, get_tips,
update_tip, update_tip,
update_tipjar, update_tipjar,
delete_tip,
delete_tipjar,
) )
from ..satspay.crud import create_charge from .helpers import get_charge_details
from .models import createTipJar, createTips, createTip, CreateCharge from .models import CreateCharge, createTipJar, createTips
@tipjar_ext.post("/api/v1/tipjars") @tipjar_ext.post("/api/v1/tipjars")
@ -54,7 +52,6 @@ async def api_create_tip(data: createTips):
webhook = tipjar.webhook webhook = tipjar.webhook
charge_details = await get_charge_details(tipjar.id) charge_details = await get_charge_details(tipjar.id)
print(charge_details["time"])
name = data.name name = data.name
# Ensure that description string can be split reliably # Ensure that description string can be split reliably
name = name.replace('"', "''") name = name.replace('"', "''")

View file

@ -29,7 +29,6 @@ async def tpos(request: Request, tpos_id):
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="TPoS does not exist." status_code=HTTPStatus.NOT_FOUND, detail="TPoS does not exist."
) )
print(request.base_url)
return tpos_renderer().TemplateResponse( return tpos_renderer().TemplateResponse(
"tpos/tpos.html", {"request": request, "tpos": tpos} "tpos/tpos.html", {"request": request, "tpos": tpos}

View file

@ -4,11 +4,11 @@ from fastapi import Query
from fastapi.params import Depends from fastapi.params import Depends
from starlette.exceptions import HTTPException from starlette.exceptions import HTTPException
from lnbits.core.crud import get_user, get_wallet from lnbits.core.crud import get_user
from lnbits.core.services import check_invoice_status, create_invoice from lnbits.core.services import create_invoice
from lnbits.decorators import WalletTypeInfo, get_key_type, require_admin_key
from lnbits.core.views.api import api_payment from lnbits.core.views.api import api_payment
from lnbits.core.models import Wallet from lnbits.decorators import WalletTypeInfo, get_key_type, require_admin_key
from . import tpos_ext from . import tpos_ext
from .crud import create_tpos, delete_tpos, get_tpos, get_tposs from .crud import create_tpos, delete_tpos, get_tpos, get_tposs
from .models import CreateTposData from .models import CreateTposData
@ -43,15 +43,12 @@ async def api_tpos_delete(
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="TPoS does not exist." status_code=HTTPStatus.NOT_FOUND, detail="TPoS does not exist."
) )
# return {"message": "TPoS does not exist."}, HTTPStatus.NOT_FOUND
if tpos.wallet != wallet.wallet.id: if tpos.wallet != wallet.wallet.id:
raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="Not your TPoS.") raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="Not your TPoS.")
# return {"message": "Not your TPoS."}, HTTPStatus.FORBIDDEN
await delete_tpos(tpos_id) await delete_tpos(tpos_id)
raise HTTPException(status_code=HTTPStatus.NO_CONTENT) raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
# return "", HTTPStatus.NO_CONTENT
@tpos_ext.post("/api/v1/tposs/{tpos_id}/invoices", status_code=HTTPStatus.CREATED) @tpos_ext.post("/api/v1/tposs/{tpos_id}/invoices", status_code=HTTPStatus.CREATED)
@ -62,7 +59,6 @@ async def api_tpos_create_invoice(amount: int = Query(..., ge=1), tpos_id: str =
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="TPoS does not exist." status_code=HTTPStatus.NOT_FOUND, detail="TPoS does not exist."
) )
# return {"message": "TPoS does not exist."}, HTTPStatus.NOT_FOUND
try: try:
payment_hash, payment_request = await create_invoice( payment_hash, payment_request = await create_invoice(
@ -73,7 +69,6 @@ async def api_tpos_create_invoice(amount: int = Query(..., ge=1), tpos_id: str =
) )
except Exception as e: except Exception as e:
raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=str(e)) raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=str(e))
# return {"message": str(e)}, HTTPStatus.INTERNAL_SERVER_ERROR
return {"payment_hash": payment_hash, "payment_request": payment_request} return {"payment_hash": payment_hash, "payment_request": payment_request}

View file

@ -14,7 +14,6 @@ from .models import CreateUserData, Users, Wallets
### Users ### Users
async def create_usermanager_user(data: CreateUserData) -> Users: async def create_usermanager_user(data: CreateUserData) -> Users:
account = await create_account() account = await create_account()
user = await get_user(account.id) user = await get_user(account.id)

View file

@ -25,7 +25,6 @@ from .models import CreateUserData, CreateUserWallet
### Users ### Users
@usermanager_ext.get("/api/v1/users", status_code=HTTPStatus.OK) @usermanager_ext.get("/api/v1/users", status_code=HTTPStatus.OK)
async def api_usermanager_users(wallet: WalletTypeInfo = Depends(get_key_type)): async def api_usermanager_users(wallet: WalletTypeInfo = Depends(get_key_type)):
user_id = wallet.wallet.user user_id = wallet.wallet.user
@ -39,15 +38,6 @@ async def api_usermanager_user(user_id, wallet: WalletTypeInfo = Depends(get_key
@usermanager_ext.post("/api/v1/users", status_code=HTTPStatus.CREATED) @usermanager_ext.post("/api/v1/users", status_code=HTTPStatus.CREATED)
# @api_validate_post_request(
# schema={
# "user_name": {"type": "string", "empty": False, "required": True},
# "wallet_name": {"type": "string", "empty": False, "required": True},
# "admin_id": {"type": "string", "empty": False, "required": True},
# "email": {"type": "string", "required": False},
# "password": {"type": "string", "required": False},
# }
# )
async def api_usermanager_users_create( async def api_usermanager_users_create(
data: CreateUserData, wallet: WalletTypeInfo = Depends(get_key_type) data: CreateUserData, wallet: WalletTypeInfo = Depends(get_key_type)
): ):
@ -118,7 +108,6 @@ async def api_usermanager_wallet_transactions(
async def api_usermanager_users_wallets( async def api_usermanager_users_wallets(
user_id, wallet: WalletTypeInfo = Depends(get_key_type) user_id, wallet: WalletTypeInfo = Depends(get_key_type)
): ):
# wallet = await get_usermanager_users_wallets(user_id)
return [ return [
s_wallet.dict() for s_wallet in await get_usermanager_users_wallets(user_id) s_wallet.dict() for s_wallet in await get_usermanager_users_wallets(user_id)
] ]

View file

@ -75,7 +75,6 @@ def parse_key(masterpub: str):
async def create_watch_wallet(user: str, masterpub: str, title: str) -> Wallets: async def create_watch_wallet(user: str, masterpub: str, title: str) -> Wallets:
# check the masterpub is fine, it will raise an exception if not # check the masterpub is fine, it will raise an exception if not
print("PARSE", parse_key(masterpub))
parse_key(masterpub) parse_key(masterpub)
wallet_id = urlsafe_short_hash() wallet_id = urlsafe_short_hash()
await db.execute( await db.execute(

View file

@ -8,9 +8,6 @@ from lnbits.decorators import check_user_exists
from . import watchonly_ext, watchonly_renderer from . import watchonly_ext, watchonly_renderer
# from .crud import get_payment
templates = Jinja2Templates(directory="templates") templates = Jinja2Templates(directory="templates")
@ -19,15 +16,3 @@ async def index(request: Request, user: User = Depends(check_user_exists)):
return watchonly_renderer().TemplateResponse( return watchonly_renderer().TemplateResponse(
"watchonly/index.html", {"request": request, "user": user.dict()} "watchonly/index.html", {"request": request, "user": user.dict()}
) )
# @watchonly_ext.get("/{charge_id}", response_class=HTMLResponse)
# async def display(request: Request, charge_id):
# link = get_payment(charge_id)
# if not link:
# raise HTTPException(
# status_code=HTTPStatus.NOT_FOUND,
# detail="Charge link does not exist."
# )
#
# return watchonly_renderer().TemplateResponse("watchonly/display.html", {"request": request,"link": link.dict()})

View file

@ -18,7 +18,6 @@ withdraw_static_files = [
withdraw_ext: APIRouter = APIRouter( withdraw_ext: APIRouter = APIRouter(
prefix="/withdraw", prefix="/withdraw",
tags=["withdraw"], tags=["withdraw"],
# "withdraw", __name__, static_folder="static", template_folder="templates"
) )
@ -29,7 +28,3 @@ def withdraw_renderer():
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
# @withdraw_ext.on_event("startup")
# def _do_it():
# register_listeners()

View file

@ -22,20 +22,16 @@ from .crud import get_withdraw_link_by_hash, update_withdraw_link
name="withdraw.api_lnurl_response", name="withdraw.api_lnurl_response",
) )
async def api_lnurl_response(request: Request, unique_hash): async def api_lnurl_response(request: Request, unique_hash):
print("NOT UNIQUE")
link = await get_withdraw_link_by_hash(unique_hash) link = await get_withdraw_link_by_hash(unique_hash)
if not link: if not link:
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="Withdraw link does not exist." status_code=HTTPStatus.NOT_FOUND, detail="Withdraw link does not exist."
) )
# return ({"status": "ERROR", "reason": "LNURL-withdraw not found."},
# HTTPStatus.OK,
# )
if link.is_spent: if link.is_spent:
raise HTTPException( raise HTTPException(
# WHAT STATUS_CODE TO USE??
detail="Withdraw is spent." detail="Withdraw is spent."
) )
url = request.url_for("withdraw.api_lnurl_callback", unique_hash=link.unique_hash) url = request.url_for("withdraw.api_lnurl_callback", unique_hash=link.unique_hash)
@ -52,9 +48,6 @@ async def api_lnurl_response(request: Request, unique_hash):
# CALLBACK # CALLBACK
#https://5650-2001-8a0-fa12-2900-4c13-748a-fbb9-a47f.ngrok.io/withdraw/api/v1/lnurl/cb/eJHybS8hqcBWajZM63H3FP?k1=MUaYBGrUPuAs8SLpfizmCk&pr=lnbc100n1pse2tsypp5ju0yn3w9j0n8rr3squg0knddawu2ude2cgrm6zje5f34e9jzpmlsdq8w3jhxaqxqyjw5qcqpjsp5tyhu78pamqg5zfy96kup329zt40ramc8gs2ev6jxgp66zca2348qrzjqwac3nxyg3f5mfa4ke9577c4u8kvkx8pqtdsusqdfww0aymk823x6znwa5qqzyqqqyqqqqlgqqqqppgq9q9qy9qsq66zp6pctnlmk59xwtqjga5lvqrkyccmafmn43enhhc6ugew80sanxymepshpv44m9yyhfgh8r2upvxhgk00d36rpqzfy3fxemeu4jhqp96l8hx
@withdraw_ext.get( @withdraw_ext.get(
"/api/v1/lnurl/cb/{unique_hash}", "/api/v1/lnurl/cb/{unique_hash}",
name="withdraw.api_lnurl_callback", name="withdraw.api_lnurl_callback",
@ -126,7 +119,6 @@ async def api_lnurl_callback(
name="withdraw.api_lnurl_multi_response", name="withdraw.api_lnurl_multi_response",
) )
async def api_lnurl_multi_response(request: Request, unique_hash, id_unique_hash): async def api_lnurl_multi_response(request: Request, unique_hash, id_unique_hash):
print("UNIQUE")
link = await get_withdraw_link_by_hash(unique_hash) link = await get_withdraw_link_by_hash(unique_hash)
if not link: if not link:

View file

@ -18,8 +18,6 @@ templates = Jinja2Templates(directory="templates")
@withdraw_ext.get("/", response_class=HTMLResponse) @withdraw_ext.get("/", response_class=HTMLResponse)
# @validate_uuids(["usr"], required=True)
# @check_user_exists()
async def index(request: Request, user: User = Depends(check_user_exists)): async def index(request: Request, user: User = Depends(check_user_exists)):
return withdraw_renderer().TemplateResponse( return withdraw_renderer().TemplateResponse(
"withdraw/index.html", {"request": request, "user": user.dict()} "withdraw/index.html", {"request": request, "user": user.dict()}
@ -34,9 +32,6 @@ async def display(request: Request, link_id):
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="Withdraw link does not exist." status_code=HTTPStatus.NOT_FOUND, detail="Withdraw link does not exist."
) )
# response.status_code = HTTPStatus.NOT_FOUND
# return "Withdraw link does not exist." #probably here is where we should return the 404??
print("LINK", link)
return withdraw_renderer().TemplateResponse( return withdraw_renderer().TemplateResponse(
"withdraw/display.html", "withdraw/display.html",
{ {
@ -55,10 +50,7 @@ async def img(request: Request, link_id):
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="Withdraw link does not exist." status_code=HTTPStatus.NOT_FOUND, detail="Withdraw link does not exist."
) )
# response.status_code = HTTPStatus.NOT_FOUND
# return "Withdraw link does not exist."
qr = pyqrcode.create(link.lnurl(request)) qr = pyqrcode.create(link.lnurl(request))
print(qr)
stream = BytesIO() stream = BytesIO()
qr.svg(stream, scale=3) qr.svg(stream, scale=3)
stream.seek(0) stream.seek(0)
@ -102,13 +94,11 @@ async def print_qr(request: Request, link_id):
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="Withdraw link does not exist." status_code=HTTPStatus.NOT_FOUND, detail="Withdraw link does not exist."
) )
# response.status_code = HTTPStatus.NOT_FOUND
# return "Withdraw link does not exist."
links.append(str(linkk.lnurl(request))) links.append(str(linkk.lnurl(request)))
count = count + 1 count = count + 1
page_link = list(chunks(links, 2)) page_link = list(chunks(links, 2))
linked = list(chunks(page_link, 5)) linked = list(chunks(page_link, 5))
print("LINKED", linked)
return withdraw_renderer().TemplateResponse( return withdraw_renderer().TemplateResponse(
"withdraw/print_qr.html", {"request": request, "link": linked, "unique": True} "withdraw/print_qr.html", {"request": request, "link": linked, "unique": True}
) )