adapt to bolt-nfc-android-app
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from optparse import Option
|
||||
import secrets
|
||||
from typing import List, Optional, Union
|
||||
|
||||
from lnbits.helpers import urlsafe_short_hash
|
||||
@@ -18,10 +18,12 @@ async def create_card(data: CreateCardData, wallet_id: str) -> Card:
|
||||
uid,
|
||||
counter,
|
||||
withdraw,
|
||||
file_key,
|
||||
meta_key
|
||||
k0,
|
||||
k1,
|
||||
k2,
|
||||
otp
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(
|
||||
card_id,
|
||||
@@ -30,11 +32,13 @@ async def create_card(data: CreateCardData, wallet_id: str) -> Card:
|
||||
data.uid,
|
||||
data.counter,
|
||||
data.withdraw,
|
||||
data.file_key,
|
||||
data.meta_key,
|
||||
data.k0,
|
||||
data.k1,
|
||||
data.k2,
|
||||
secrets.token_hex(16),
|
||||
),
|
||||
)
|
||||
card = await get_card(card_id, 0)
|
||||
card = await get_card(card_id)
|
||||
assert card, "Newly created card couldn't be retrieved"
|
||||
return card
|
||||
|
||||
@@ -69,14 +73,18 @@ async def get_all_cards() -> List[Card]:
|
||||
return [Card(**row) for row in rows]
|
||||
|
||||
|
||||
async def get_card(card_id: str, id_is_uid: bool = False) -> Optional[Card]:
|
||||
sql = "SELECT * FROM boltcards.cards WHERE {} = ?".format(
|
||||
"uid" if id_is_uid else "id"
|
||||
)
|
||||
row = await db.fetchone(
|
||||
sql,
|
||||
card_id,
|
||||
)
|
||||
async def get_card(card_id: str) -> Optional[Card]:
|
||||
row = await db.fetchone("SELECT * FROM boltcards.cards WHERE id = ?", (card_id,))
|
||||
if not row:
|
||||
return None
|
||||
|
||||
card = dict(**row)
|
||||
|
||||
return Card.parse_obj(card)
|
||||
|
||||
|
||||
async def get_card_by_otp(otp: str) -> Optional[Card]:
|
||||
row = await db.fetchone("SELECT * FROM boltcards.cards WHERE otp = ?", (otp,))
|
||||
if not row:
|
||||
return None
|
||||
|
||||
@@ -96,6 +104,13 @@ async def update_card_counter(counter: int, id: str):
|
||||
)
|
||||
|
||||
|
||||
async def update_card_otp(otp: str, id: str):
|
||||
await db.execute(
|
||||
"UPDATE boltcards.cards SET otp = ? WHERE id = ?",
|
||||
(otp, id),
|
||||
)
|
||||
|
||||
|
||||
async def get_hit(hit_id: str) -> Optional[Hit]:
|
||||
row = await db.fetchone(f"SELECT * FROM boltcards.hits WHERE id = ?", (hit_id))
|
||||
if not row:
|
||||
|
||||
Reference in New Issue
Block a user