Merge pull request #38 from fiatjaf/adminkey-to-inkey
allow inkey endpoints to be accessed with adminkeys.
This commit is contained in:
commit
42d307adf9
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user