fix: use lnbits linting, change to uv (#9)
* fix: use lnbits linting, change to uv - formatting - prettier - pyright * dont ignore packagejson * readd poetry lock for integration tests * fix pyright * fix mypy * fix test? * fix lnbits version * fixup tests * fixup!
This commit is contained in:
parent
c1f9d6a754
commit
603b345073
28 changed files with 5059 additions and 2199 deletions
38
crud.py
38
crud.py
|
|
@ -1,5 +1,4 @@
|
|||
import time
|
||||
from typing import List, Optional
|
||||
|
||||
from lnbits.db import Database
|
||||
|
||||
|
|
@ -11,6 +10,7 @@ from .models import (
|
|||
GetNWC,
|
||||
GetWalletNWC,
|
||||
NWCBudget,
|
||||
NWCConfig,
|
||||
NWCKey,
|
||||
NWCNewBudget,
|
||||
TrackedSpendNWC,
|
||||
|
|
@ -71,7 +71,8 @@ async def delete_nwc(data: DeleteNWC) -> None:
|
|||
|
||||
# hardening #
|
||||
assert_valid_pubkey(data.pubkey)
|
||||
assert_valid_wallet_id(data.wallet)
|
||||
if data.wallet:
|
||||
assert_valid_wallet_id(data.wallet)
|
||||
# ## #
|
||||
|
||||
await db.execute(
|
||||
|
|
@ -80,9 +81,12 @@ async def delete_nwc(data: DeleteNWC) -> None:
|
|||
)
|
||||
|
||||
|
||||
async def get_wallet_nwcs(data: GetWalletNWC) -> List[NWCKey]:
|
||||
async def get_wallet_nwcs(data: GetWalletNWC) -> list[NWCKey]:
|
||||
expires = int(time.time()) if not data.include_expired else -1
|
||||
|
||||
if not data.wallet:
|
||||
return []
|
||||
|
||||
# hardening #
|
||||
assert_valid_wallet_id(data.wallet)
|
||||
assert_valid_expiration_seconds(expires)
|
||||
|
|
@ -101,7 +105,7 @@ async def get_wallet_nwcs(data: GetWalletNWC) -> List[NWCKey]:
|
|||
)
|
||||
|
||||
|
||||
async def get_nwc(data: GetNWC) -> Optional[NWCKey]:
|
||||
async def get_nwc(data: GetNWC) -> NWCKey | None:
|
||||
expires = int(time.time()) if not data.include_expired else -1
|
||||
|
||||
# hardening #
|
||||
|
|
@ -150,17 +154,17 @@ async def get_nwc(data: GetNWC) -> Optional[NWCKey]:
|
|||
return row
|
||||
|
||||
|
||||
async def get_budgets_nwc(data: GetBudgetsNWC) -> Optional[NWCBudget]:
|
||||
async def get_budgets_nwc(data: GetBudgetsNWC) -> list[NWCBudget]:
|
||||
|
||||
# hardening #
|
||||
assert_valid_pubkey(data.pubkey)
|
||||
# ## #
|
||||
|
||||
rows = await db.fetchall(
|
||||
budgets = await db.fetchall(
|
||||
"SELECT * FROM nwcprovider.budgets WHERE pubkey = :pubkey",
|
||||
{"pubkey": data.pubkey},
|
||||
model=NWCBudget,
|
||||
)
|
||||
budgets = [NWCBudget(**row) for row in rows]
|
||||
if data.calculate_spent:
|
||||
for budget in budgets:
|
||||
last_cycle, next_cycle = budget.get_timestamp_range()
|
||||
|
|
@ -170,7 +174,7 @@ async def get_budgets_nwc(data: GetBudgetsNWC) -> Optional[NWCBudget]:
|
|||
assert_valid_timestamp_seconds(next_cycle)
|
||||
# ## #
|
||||
|
||||
tot_spent_in_range_msats = await db.fetchone(
|
||||
result: dict = await db.fetchone(
|
||||
"""
|
||||
SELECT SUM(amount_msats) FROM nwcprovider.spent
|
||||
WHERE pubkey = :pubkey AND created_at >=
|
||||
|
|
@ -182,9 +186,7 @@ async def get_budgets_nwc(data: GetBudgetsNWC) -> Optional[NWCBudget]:
|
|||
"next_cycle": next_cycle,
|
||||
},
|
||||
)
|
||||
tot_spent_in_range_msats = (
|
||||
next(iter(tot_spent_in_range_msats.values())) or 0
|
||||
)
|
||||
tot_spent_in_range_msats = next(iter(result.values())) or 0
|
||||
|
||||
# hardening #
|
||||
assert_valid_msats(tot_spent_in_range_msats)
|
||||
|
|
@ -263,12 +265,14 @@ async def tracked_spend_nwc(data: TrackedSpendNWC, action):
|
|||
|
||||
|
||||
async def get_config_nwc(key: str):
|
||||
row = await db.fetchone(
|
||||
"SELECT * FROM nwcprovider.config WHERE key = :key", {"key": key}
|
||||
config = await db.fetchone(
|
||||
"SELECT * FROM nwcprovider.config WHERE key = :key",
|
||||
{"key": key},
|
||||
model=NWCConfig,
|
||||
)
|
||||
if not row:
|
||||
if not config:
|
||||
return None
|
||||
return row["value"]
|
||||
return config.value
|
||||
|
||||
|
||||
async def set_config_nwc(key: str, value: str):
|
||||
|
|
@ -289,5 +293,5 @@ async def set_config_nwc(key: str, value: str):
|
|||
|
||||
|
||||
async def get_all_config_nwc():
|
||||
rows = await db.fetchall("SELECT * FROM nwcprovider.config")
|
||||
return {row["key"]: row["value"] for row in rows}
|
||||
rows = await db.fetchall("SELECT * FROM nwcprovider.config", model=NWCConfig)
|
||||
return {row.key: row.value for row in rows}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue