From c3ce18c8d993c8e5374cc88a15e773ac2110721a Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Tue, 5 May 2020 04:59:15 -0300 Subject: [PATCH] allow inkey endpoints to be accessed with adminkeys. --- lnbits/core/crud.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lnbits/core/crud.py b/lnbits/core/crud.py index 195748a4..a06e045b 100644 --- a/lnbits/core/crud.py +++ b/lnbits/core/crud.py @@ -114,17 +114,22 @@ def get_wallet(wallet_id: str) -> Optional[Wallet]: def get_wallet_for_key(key: str, key_type: str = "invoice") -> Optional[Wallet]: with open_db() as db: - check_field = "adminkey" if key_type == "admin" else "inkey" row = db.fetchone( f""" SELECT *, COALESCE((SELECT balance FROM balances WHERE wallet = wallets.id), 0) AS balance_msat FROM wallets - WHERE {check_field} = ? + WHERE adminkey = ? OR inkey = ? """, - (key,), + (key, key), ) - return Wallet(**row) if row else None + if not row: + return None + + if key_type == "admin" and row["adminkey"] != key: + return None + + return Wallet(**row) # wallet payments