Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
needs: [lint]
strategy:
matrix:
python-version: ['3.9', '3.10']
python-version: ['3.10']
steps:
- uses: actions/checkout@v4
- uses: lnbits/lnbits/.github/actions/prepare@dev
Expand All @@ -30,5 +30,5 @@ jobs:
job-summary: true
emoji: false
click-to-expand: true
custom-pytest: poetry run pytest
custom-pytest: uv run pytest
report-title: 'test (${{ matrix.python-version }})'
24 changes: 12 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,42 @@ 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

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:
Expand Down
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ def satspay_start():
)


__all__ = ["db", "satspay_ext", "satspay_static_files", "satspay_start", "satspay_stop"]
__all__ = ["db", "satspay_ext", "satspay_start", "satspay_static_files", "satspay_stop"]
9 changes: 4 additions & 5 deletions crud.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from datetime import datetime
from typing import Optional

from lnbits.core.services import create_invoice
from lnbits.db import Database
Expand All @@ -19,7 +18,7 @@
async def create_charge(
user: str,
data: CreateCharge,
onchainaddress: Optional[str] = None,
onchainaddress: str | None = None,
) -> Charge:
if not data.amount or data.amount <= 0:
raise Exception("Amount must be greater than 0")
Expand Down Expand Up @@ -74,7 +73,7 @@ async def update_charge(charge: Charge) -> Charge:
return charge


async def get_charge(charge_id: str) -> Optional[Charge]:
async def get_charge(charge_id: str) -> Charge | None:
return await db.fetchone(
"SELECT * FROM satspay.charges WHERE id = :id",
{"id": charge_id},
Expand All @@ -89,7 +88,7 @@ async def get_pending_charges() -> list[Charge]:
)


async def get_charge_by_onchain_address(onchain_address: str) -> Optional[Charge]:
async def get_charge_by_onchain_address(onchain_address: str) -> Charge | None:
return await db.fetchone(
"SELECT * FROM satspay.charges WHERE onchainaddress = :address",
{"address": onchain_address},
Expand Down Expand Up @@ -127,7 +126,7 @@ async def update_theme(theme: SatsPayTheme) -> SatsPayTheme:
return theme


async def get_theme(css_id: str) -> Optional[SatsPayTheme]:
async def get_theme(css_id: str) -> SatsPayTheme | None:
return await db.fetchone(
"SELECT * FROM satspay.themes WHERE css_id = :css_id",
{"css_id": css_id},
Expand Down
48 changes: 16 additions & 32 deletions migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,26 @@ async def m002_add_charge_extra_data(db: Database):
"""
Add 'extra' column for storing various config about the charge (JSON format)
"""
await db.execute(
"""
await db.execute("""
ALTER TABLE satspay.charges
ADD COLUMN extra TEXT DEFAULT
'{"mempool_endpoint": "https://mempool.space", "network": "Mainnet"}'
"""
)
""")


async def m003_add_themes_table(db: Database):
"""
Themes table
"""

await db.execute(
"""
await db.execute("""
CREATE TABLE satspay.themes (
css_id TEXT NOT NULL PRIMARY KEY,
"user" TEXT,
title TEXT,
custom_css TEXT
);
"""
)
""")


async def m004_add_custom_css_to_charges(db: Database):
Expand All @@ -84,18 +80,14 @@ async def m006_add_zeroconf_column(db: Database):
Add 'zeroconf' column for allowing zero confirmation payments
"""
try:
await db.execute(
"""
await db.execute("""
ALTER TABLE satspay.charges ADD COLUMN zeroconf BOOLEAN NOT NULL DEFAULT FALSE
"""
)
""")

await db.execute(
"""
await db.execute("""
UPDATE satspay.charges
SET zeroconf = FALSE
"""
)
""")
except OperationalError:
pass

Expand All @@ -105,19 +97,15 @@ async def m007_add_pending_column(db: Database):
Add 'pending' column for storing the pending amount
"""
try:
await db.execute(
f"""
await db.execute(f"""
ALTER TABLE satspay.charges
ADD COLUMN pending {db.big_int} NOT NULL DEFAULT 0
"""
)
""")

await db.execute(
"""
await db.execute("""
UPDATE satspay.charges
SET pending = 0
"""
)
""")
except OperationalError:
pass

Expand All @@ -137,13 +125,11 @@ async def m009_settings(db: Database):
Add settings table
"""
try:
await db.execute(
"""
await db.execute("""
CREATE TABLE satspay.settings (
mempool_url TEXT NOT NULL
)
"""
)
""")
except OperationalError:
pass

Expand All @@ -167,13 +153,11 @@ async def m011_persist_paid(db: Database):
await db.execute(
"ALTER TABLE satspay.charges ADD COLUMN paid BOOLEAN DEFAULT FALSE"
)
await db.execute(
"""
await db.execute("""
UPDATE satspay.charges
SET paid = TRUE
WHERE balance >= amount
"""
)
""")
except OperationalError:
pass

Expand Down
39 changes: 19 additions & 20 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import json
from datetime import datetime
from typing import Optional

from fastapi.param_functions import Query
from pydantic import BaseModel
Expand All @@ -23,13 +22,13 @@ class CreateCharge(BaseModel):
completelink: str = Query(None)
completelinktext: str = Query("Back to Merchant")
time: int = Query(..., ge=1)
amount: Optional[int] = Query(None, ge=1)
amount: int | None = Query(None, ge=1)
zeroconf: bool = Query(False)
fasttrack: bool = Query(False)
custom_css: Optional[str] = Query(None)
custom_css: str | None = Query(None)
currency: str = Query(None)
currency_amount: Optional[float] = Query(None)
extra: Optional[str] = Query(None)
currency_amount: float | None = Query(None)
extra: str | None = Query(None)


class Charge(BaseModel):
Expand All @@ -43,20 +42,20 @@ class Charge(BaseModel):
zeroconf: bool = False
fasttrack: bool = False
paid: bool = False
completelinktext: Optional[str] = "Back to Merchant"
name: Optional[str] = None
description: Optional[str] = None
onchainwallet: Optional[str] = None
onchainaddress: Optional[str] = None
lnbitswallet: Optional[str] = None
payment_request: Optional[str] = None
payment_hash: Optional[str] = None
webhook: Optional[str] = None
completelink: Optional[str] = None
custom_css: Optional[str] = None
currency: Optional[str] = None
currency_amount: Optional[float] = None
extra: Optional[str] = None
completelinktext: str | None = "Back to Merchant"
name: str | None = None
description: str | None = None
onchainwallet: str | None = None
onchainaddress: str | None = None
lnbitswallet: str | None = None
payment_request: str | None = None
payment_hash: str | None = None
webhook: str | None = None
completelink: str | None = None
custom_css: str | None = None
currency: str | None = None
currency_amount: float | None = None
extra: str | None = None

def add_extra(self, extra: dict):
old_extra = json.loads(self.extra) if self.extra else {}
Expand All @@ -67,7 +66,7 @@ def paid_fasttrack(self):
"""
ignore the pending status if fasttrack is enabled tell the frontend its paid
"""
return (self.pending or 0) >= self.amount and self.fasttrack or self.paid
return ((self.pending or 0) >= self.amount and self.fasttrack) or self.paid

@property
def public(self):
Expand Down
Loading
Loading