convert to using lnbits card id instead of card uid

This commit is contained in:
Lee Salminen 2022-08-21 10:00:16 -06:00
parent a8bc3ea870
commit 971d8f34e8
2 changed files with 4 additions and 17 deletions

View File

@ -85,18 +85,6 @@ async def get_card(card_id: str) -> Optional[Card]:
return Card.parse_obj(card)
async def get_card_by_uid(card_uid: str) -> Optional[Card]:
row = await db.fetchone(
"SELECT * FROM boltcards.cards WHERE uid = ?", (card_uid.upper(),)
)
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:

View File

@ -25,7 +25,6 @@ from .crud import (
get_all_cards,
get_card,
get_card_by_otp,
get_card_by_uid,
get_cards,
get_hits,
update_card,
@ -132,15 +131,15 @@ async def api_hits(
# /boltcards/api/v1/scan?p=00000000000000000000000000000000&c=0000000000000000
@boltcards_ext.get("/api/v1/scan")
@boltcards_ext.get("/api/v1/scan/{card_uid}")
async def api_scan(p, c, request: Request, card_uid: str = None):
@boltcards_ext.get("/api/v1/scan/{card_id}")
async def api_scan(p, c, request: Request, card_id: str = None):
# some wallets send everything as lower case, no bueno
p = p.upper()
c = c.upper()
card = None
counter = b""
if not card_uid:
if not card_id:
# since this route is common to all cards I don't know whitch 'meta key' to use
# so I try one by one until decrypted uid matches
for cand in await get_all_cards():
@ -157,7 +156,7 @@ async def api_scan(p, c, request: Request, card_uid: str = None):
continue
else:
try:
card = await get_card_by_uid(card_uid)
card = await get_card(card_id)
card_uid, counter = decryptSUN(bytes.fromhex(p), bytes.fromhex(card.k1))
except:
return {"status": "ERROR", "reason": "Error decrypting card."}