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