allow inkey endpoints to be accessed with adminkeys.

This commit is contained in:
fiatjaf 2020-05-05 04:59:15 -03:00
parent 4730500ed7
commit c3ce18c8d9

View file

@ -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