feat: update to lnbits 1.0.0 (#27)

* feat: update to lnbits 1.0.0
* fix select wallet
* fix splits
* fix: types, postgres errors with cache
---------

Co-authored-by: Tiago Vasconcelos <talvasconcelos@gmail.com>
This commit is contained in:
dni ⚡ 2024-11-28 12:28:00 +01:00 committed by GitHub
commit 5042d40af6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 1300 additions and 1218 deletions

32
crud.py
View file

@ -1,37 +1,23 @@
from typing import List
from lnbits.db import Database
from lnbits.helpers import urlsafe_short_hash
from .models import Target
db = Database("ext_splitpayments")
async def get_targets(source_wallet: str) -> List[Target]:
rows = await db.fetchall(
"SELECT * FROM splitpayments.targets WHERE source = ?", (source_wallet,)
async def get_targets(source_wallet: str) -> list[Target]:
return await db.fetchall(
"SELECT * FROM splitpayments.targets WHERE source = :source_wallet",
{"source_wallet": source_wallet},
Target,
)
return [Target(**row) for row in rows]
async def set_targets(source_wallet: str, targets: List[Target]):
async def set_targets(source_wallet: str, targets: list[Target]):
async with db.connect() as conn:
await conn.execute(
"DELETE FROM splitpayments.targets WHERE source = ?", (source_wallet,)
"DELETE FROM splitpayments.targets WHERE source = :source_wallet",
{"source_wallet": source_wallet},
)
for target in targets:
await conn.execute(
"""
INSERT INTO splitpayments.targets
(id, source, wallet, percent, alias)
VALUES (?, ?, ?, ?, ?)
""",
(
urlsafe_short_hash(),
source_wallet,
target.wallet,
target.percent,
target.alias,
),
)
await conn.insert("splitpayments.targets", target)