Merge pull request #38 from fiatjaf/adminkey-to-inkey

allow inkey endpoints to be accessed with adminkeys.
This commit is contained in:
Eneko Illarramendi 2020-05-05 11:09:02 +02:00 committed by GitHub
commit 42d307adf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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