parent
c060f10e65
commit
7bdf7db2c4
8 changed files with 2324 additions and 3665 deletions
24
Makefile
24
Makefile
|
|
@ -5,27 +5,27 @@ format: prettier black ruff
|
|||
check: mypy pyright checkblack checkruff checkprettier
|
||||
|
||||
prettier:
|
||||
poetry run ./node_modules/.bin/prettier --write .
|
||||
uv run ./node_modules/.bin/prettier --write .
|
||||
pyright:
|
||||
poetry run ./node_modules/.bin/pyright
|
||||
uv run ./node_modules/.bin/pyright
|
||||
|
||||
mypy:
|
||||
poetry run mypy .
|
||||
uv run mypy .
|
||||
|
||||
black:
|
||||
poetry run black .
|
||||
uv run black .
|
||||
|
||||
ruff:
|
||||
poetry run ruff check . --fix
|
||||
uv run ruff check . --fix
|
||||
|
||||
checkruff:
|
||||
poetry run ruff check .
|
||||
uv run ruff check .
|
||||
|
||||
checkprettier:
|
||||
poetry run ./node_modules/.bin/prettier --check .
|
||||
uv run ./node_modules/.bin/prettier --check .
|
||||
|
||||
checkblack:
|
||||
poetry run black --check .
|
||||
uv run black --check .
|
||||
|
||||
checkeditorconfig:
|
||||
editorconfig-checker
|
||||
|
|
@ -33,14 +33,14 @@ checkeditorconfig:
|
|||
test:
|
||||
PYTHONUNBUFFERED=1 \
|
||||
DEBUG=true \
|
||||
poetry run pytest
|
||||
uv run pytest
|
||||
install-pre-commit-hook:
|
||||
@echo "Installing pre-commit hook to git"
|
||||
@echo "Uninstall the hook with poetry run pre-commit uninstall"
|
||||
poetry run pre-commit install
|
||||
@echo "Uninstall the hook with uv run pre-commit uninstall"
|
||||
uv run pre-commit install
|
||||
|
||||
pre-commit:
|
||||
poetry run pre-commit run --all-files
|
||||
uv run pre-commit run --all-files
|
||||
|
||||
|
||||
checkbundle:
|
||||
|
|
|
|||
|
|
@ -40,9 +40,9 @@ def boltcards_start():
|
|||
|
||||
|
||||
__all__ = [
|
||||
"db",
|
||||
"boltcards_ext",
|
||||
"boltcards_static_files",
|
||||
"boltcards_start",
|
||||
"boltcards_static_files",
|
||||
"boltcards_stop",
|
||||
"db",
|
||||
]
|
||||
|
|
|
|||
15
crud.py
15
crud.py
|
|
@ -1,6 +1,5 @@
|
|||
import secrets
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from lnbits.db import Database
|
||||
from lnbits.helpers import urlsafe_short_hash
|
||||
|
|
@ -72,7 +71,7 @@ async def get_cards(wallet_ids: list[str]) -> list[Card]:
|
|||
)
|
||||
|
||||
|
||||
async def get_card(card_id: str) -> Optional[Card]:
|
||||
async def get_card(card_id: str) -> Card | None:
|
||||
return await db.fetchone(
|
||||
"SELECT * FROM boltcards.cards WHERE id = :id",
|
||||
{"id": card_id},
|
||||
|
|
@ -80,7 +79,7 @@ async def get_card(card_id: str) -> Optional[Card]:
|
|||
)
|
||||
|
||||
|
||||
async def get_card_by_uid(card_uid: str) -> Optional[Card]:
|
||||
async def get_card_by_uid(card_uid: str) -> Card | None:
|
||||
return await db.fetchone(
|
||||
"SELECT * FROM boltcards.cards WHERE uid = :uid",
|
||||
{"uid": card_uid.upper()},
|
||||
|
|
@ -88,7 +87,7 @@ async def get_card_by_uid(card_uid: str) -> Optional[Card]:
|
|||
)
|
||||
|
||||
|
||||
async def get_card_by_external_id(external_id: str) -> Optional[Card]:
|
||||
async def get_card_by_external_id(external_id: str) -> Card | None:
|
||||
return await db.fetchone(
|
||||
"SELECT * FROM boltcards.cards WHERE external_id = :ext_id",
|
||||
{"ext_id": external_id.lower()},
|
||||
|
|
@ -96,7 +95,7 @@ async def get_card_by_external_id(external_id: str) -> Optional[Card]:
|
|||
)
|
||||
|
||||
|
||||
async def get_card_by_otp(otp: str) -> Optional[Card]:
|
||||
async def get_card_by_otp(otp: str) -> Card | None:
|
||||
return await db.fetchone(
|
||||
"SELECT * FROM boltcards.cards WHERE otp = :otp",
|
||||
{"otp": otp},
|
||||
|
|
@ -126,7 +125,7 @@ async def update_card_counter(counter: int, card_id: str):
|
|||
)
|
||||
|
||||
|
||||
async def enable_disable_card(enable: bool, card_id: str) -> Optional[Card]:
|
||||
async def enable_disable_card(enable: bool, card_id: str) -> Card | None:
|
||||
await db.execute(
|
||||
"UPDATE boltcards.cards SET enable = :enable WHERE id = :id",
|
||||
{"enable": enable, "id": card_id},
|
||||
|
|
@ -141,7 +140,7 @@ async def update_card_otp(otp: str, card_id: str):
|
|||
)
|
||||
|
||||
|
||||
async def get_hit(hit_id: str) -> Optional[Hit]:
|
||||
async def get_hit(hit_id: str) -> Hit | None:
|
||||
return await db.fetchone(
|
||||
"SELECT * FROM boltcards.hits WHERE id = :id",
|
||||
{"id": hit_id},
|
||||
|
|
@ -236,7 +235,7 @@ async def create_refund(hit_id, refund_amount) -> Refund:
|
|||
return refund
|
||||
|
||||
|
||||
async def get_refund(refund_id: str) -> Optional[Refund]:
|
||||
async def get_refund(refund_id: str) -> Refund | None:
|
||||
return await db.fetchone(
|
||||
"SELECT * FROM boltcards.refunds WHERE id = :id",
|
||||
{"id": refund_id},
|
||||
|
|
|
|||
|
|
@ -74,5 +74,5 @@ class Refund(BaseModel):
|
|||
|
||||
|
||||
class UIDPost(BaseModel):
|
||||
UID: str = Field(None, description="The UID of the card.")
|
||||
LNURLW: str = Field(None, description="The LNURLW of the card.")
|
||||
UID: str = Field(description="The UID of the card.")
|
||||
LNURLW: str = Field(description="The LNURLW of the card.")
|
||||
|
|
|
|||
3609
poetry.lock
generated
3609
poetry.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1,40 +1,34 @@
|
|||
[tool.poetry]
|
||||
[project]
|
||||
name = "lnbits-boltcards"
|
||||
version = "0.0.0"
|
||||
requires-python = ">=3.10,<3.13"
|
||||
description = "LNbits, free and open-source Lightning wallet and accounts system."
|
||||
authors = ["Alan Bits <alan@lnbits.com>"]
|
||||
authors = [{ name = "Alan Bits", email = "alan@lnbits.com" }]
|
||||
urls = { Homepage = "https://lnbits.com", Repository = "https://github.com/lnbits/bitcoinswitch_extension" }
|
||||
dependencies = [ "lnbits>1" ]
|
||||
|
||||
[tool.poetry]
|
||||
package-mode = false
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "~3.12 | ~3.11 | ~3.10"
|
||||
lnbits = {version = "*", allow-prereleases = true}
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
black = "^24.3.0"
|
||||
pytest-asyncio = "^0.21.0"
|
||||
pytest = "^7.3.2"
|
||||
mypy = "^1.5.1"
|
||||
pre-commit = "^3.2.2"
|
||||
ruff = "^0.6.3"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=1.0.0"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
[tool.uv]
|
||||
dev-dependencies = [
|
||||
"black",
|
||||
"pytest-asyncio",
|
||||
"pytest",
|
||||
"mypy",
|
||||
"pre-commit",
|
||||
"ruff",
|
||||
"pytest-md",
|
||||
]
|
||||
|
||||
[tool.mypy]
|
||||
exclude = "(nostr/*)"
|
||||
[[tool.mypy.overrides]]
|
||||
module = [
|
||||
"lnbits.*",
|
||||
"lnurl.*",
|
||||
"loguru.*",
|
||||
"fastapi.*",
|
||||
"pydantic.*",
|
||||
"pyqrcode.*",
|
||||
"shortuuid.*",
|
||||
"httpx.*",
|
||||
]
|
||||
ignore_missing_imports = "True"
|
||||
plugins = ["pydantic.mypy"]
|
||||
|
||||
[tool.pydantic-mypy]
|
||||
init_forbid_extra = true
|
||||
init_typed = true
|
||||
warn_required_dynamic_aliases = true
|
||||
warn_untyped_fields = true
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
log_cli = false
|
||||
|
|
|
|||
3
views.py
3
views.py
|
|
@ -1,5 +1,4 @@
|
|||
from http import HTTPStatus
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request
|
||||
from fastapi.responses import HTMLResponse
|
||||
|
|
@ -26,7 +25,7 @@ async def index(request: Request, user: User = Depends(check_user_exists)):
|
|||
|
||||
@boltcards_generic_router.get("/{card_id}", response_class=HTMLResponse)
|
||||
async def display(
|
||||
request: Request, card_id: str, user_id: Optional[str] = Depends(optional_user_id)
|
||||
request: Request, card_id: str, user_id: str | None = Depends(optional_user_id)
|
||||
):
|
||||
if not user_id:
|
||||
raise HTTPException(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue