mirror of
https://github.com/lnbits/lnbits.git
synced 2025-11-25 13:28:45 +01:00
remove FIXME add couple of ignores
This commit is contained in:
@@ -270,9 +270,6 @@ async def perform_lnurlauth(
|
|||||||
|
|
||||||
k1 = unhexlify(parse_qs(cb.query)["k1"][0])
|
k1 = unhexlify(parse_qs(cb.query)["k1"][0])
|
||||||
|
|
||||||
# FIXME: wallet.wallet can be None here
|
|
||||||
assert wallet.wallet is not None
|
|
||||||
|
|
||||||
key = wallet.wallet.lnurlauth_key(cb.netloc)
|
key = wallet.wallet.lnurlauth_key(cb.netloc)
|
||||||
|
|
||||||
def int_to_bytes_suitable_der(x: int) -> bytes:
|
def int_to_bytes_suitable_der(x: int) -> bytes:
|
||||||
|
|||||||
@@ -56,16 +56,12 @@ from ..tasks import api_invoice_listeners
|
|||||||
@core_app.get("/api/v1/wallet")
|
@core_app.get("/api/v1/wallet")
|
||||||
async def api_wallet(wallet: WalletTypeInfo = Depends(get_key_type)):
|
async def api_wallet(wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||||
if wallet.wallet_type == 0:
|
if wallet.wallet_type == 0:
|
||||||
# FIXME: wallet.wallet can be None here
|
|
||||||
assert wallet.wallet is not None
|
|
||||||
return {
|
return {
|
||||||
"id": wallet.wallet.id,
|
"id": wallet.wallet.id,
|
||||||
"name": wallet.wallet.name,
|
"name": wallet.wallet.name,
|
||||||
"balance": wallet.wallet.balance_msat,
|
"balance": wallet.wallet.balance_msat,
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
# FIXME: wallet.wallet can be None here
|
|
||||||
assert wallet.wallet is not None
|
|
||||||
return {"name": wallet.wallet.name, "balance": wallet.wallet.balance_msat}
|
return {"name": wallet.wallet.name, "balance": wallet.wallet.balance_msat}
|
||||||
|
|
||||||
|
|
||||||
@@ -73,9 +69,6 @@ async def api_wallet(wallet: WalletTypeInfo = Depends(get_key_type)):
|
|||||||
async def api_update_balance(
|
async def api_update_balance(
|
||||||
amount: int, wallet: WalletTypeInfo = Depends(get_key_type)
|
amount: int, wallet: WalletTypeInfo = Depends(get_key_type)
|
||||||
):
|
):
|
||||||
# FIXME: wallet.wallet can be None here
|
|
||||||
assert wallet.wallet is not None
|
|
||||||
|
|
||||||
if wallet.wallet.user not in LNBITS_ADMIN_USERS:
|
if wallet.wallet.user not in LNBITS_ADMIN_USERS:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.FORBIDDEN, detail="Not an admin user"
|
status_code=HTTPStatus.FORBIDDEN, detail="Not an admin user"
|
||||||
@@ -105,9 +98,6 @@ async def api_update_balance(
|
|||||||
async def api_update_wallet(
|
async def api_update_wallet(
|
||||||
new_name: str, wallet: WalletTypeInfo = Depends(require_admin_key)
|
new_name: str, wallet: WalletTypeInfo = Depends(require_admin_key)
|
||||||
):
|
):
|
||||||
# FIXME: wallet.wallet can be None here
|
|
||||||
assert wallet.wallet is not None
|
|
||||||
|
|
||||||
await update_wallet(wallet.wallet.id, new_name)
|
await update_wallet(wallet.wallet.id, new_name)
|
||||||
return {
|
return {
|
||||||
"id": wallet.wallet.id,
|
"id": wallet.wallet.id,
|
||||||
@@ -122,9 +112,6 @@ async def api_payments(
|
|||||||
offset: Optional[int] = None,
|
offset: Optional[int] = None,
|
||||||
wallet: WalletTypeInfo = Depends(get_key_type),
|
wallet: WalletTypeInfo = Depends(get_key_type),
|
||||||
):
|
):
|
||||||
# FIXME: wallet.wallet can be None here
|
|
||||||
assert wallet.wallet is not None
|
|
||||||
|
|
||||||
pendingPayments = await get_payments(
|
pendingPayments = await get_payments(
|
||||||
wallet_id=wallet.wallet.id,
|
wallet_id=wallet.wallet.id,
|
||||||
pending=True,
|
pending=True,
|
||||||
@@ -269,15 +256,11 @@ async def api_payments_create(
|
|||||||
status_code=HTTPStatus.BAD_REQUEST,
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
detail="BOLT11 string is invalid or not given",
|
detail="BOLT11 string is invalid or not given",
|
||||||
)
|
)
|
||||||
# FIXME: wallet.wallet can be None here
|
|
||||||
assert wallet.wallet is not None
|
|
||||||
return await api_payments_pay_invoice(
|
return await api_payments_pay_invoice(
|
||||||
invoiceData.bolt11, wallet.wallet
|
invoiceData.bolt11, wallet.wallet
|
||||||
) # admin key
|
) # admin key
|
||||||
elif not invoiceData.out:
|
elif not invoiceData.out:
|
||||||
# invoice key
|
# invoice key
|
||||||
# FIXME: wallet.wallet can be None here
|
|
||||||
assert wallet.wallet is not None
|
|
||||||
return await api_payments_create_invoice(invoiceData, wallet.wallet)
|
return await api_payments_create_invoice(invoiceData, wallet.wallet)
|
||||||
else:
|
else:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
@@ -342,8 +325,6 @@ async def api_payments_pay_lnurl(
|
|||||||
if data.comment:
|
if data.comment:
|
||||||
extra["comment"] = data.comment
|
extra["comment"] = data.comment
|
||||||
assert data.description is not None, "description is required"
|
assert data.description is not None, "description is required"
|
||||||
# FIXME: wallet.wallet can be None here
|
|
||||||
assert wallet.wallet is not None
|
|
||||||
payment_hash = await pay_invoice(
|
payment_hash = await pay_invoice(
|
||||||
wallet_id=wallet.wallet.id,
|
wallet_id=wallet.wallet.id,
|
||||||
payment_request=params["pr"],
|
payment_request=params["pr"],
|
||||||
@@ -397,8 +378,6 @@ async def subscribe(request: Request, wallet: Wallet):
|
|||||||
async def api_payments_sse(
|
async def api_payments_sse(
|
||||||
request: Request, wallet: WalletTypeInfo = Depends(get_key_type)
|
request: Request, wallet: WalletTypeInfo = Depends(get_key_type)
|
||||||
):
|
):
|
||||||
# FIXME: wallet.wallet can be None here
|
|
||||||
assert wallet.wallet is not None
|
|
||||||
return EventSourceResponse(
|
return EventSourceResponse(
|
||||||
subscribe(request, wallet.wallet), ping=20, media_type="text/event-stream"
|
subscribe(request, wallet.wallet), ping=20, media_type="text/event-stream"
|
||||||
)
|
)
|
||||||
@@ -477,8 +456,6 @@ async def api_lnurlscan(code: str, wallet: WalletTypeInfo = Depends(get_key_type
|
|||||||
params.update(kind="auth")
|
params.update(kind="auth")
|
||||||
params.update(callback=url) # with k1 already in it
|
params.update(callback=url) # with k1 already in it
|
||||||
|
|
||||||
# FIXME: wallet.wallet can be None here
|
|
||||||
assert wallet.wallet is not None
|
|
||||||
lnurlauth_key = wallet.wallet.lnurlauth_key(domain)
|
lnurlauth_key = wallet.wallet.lnurlauth_key(domain)
|
||||||
params.update(pubkey=lnurlauth_key.verifying_key.to_string("compressed").hex())
|
params.update(pubkey=lnurlauth_key.verifying_key.to_string("compressed").hex())
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ class KeyChecker(SecurityBase):
|
|||||||
name="X-API-KEY",
|
name="X-API-KEY",
|
||||||
description="Wallet API Key - HEADER",
|
description="Wallet API Key - HEADER",
|
||||||
)
|
)
|
||||||
|
self.wallet = None # type: ignore
|
||||||
self.model: APIKey = key
|
self.model: APIKey = key
|
||||||
|
|
||||||
async def __call__(self, request: Request):
|
async def __call__(self, request: Request):
|
||||||
@@ -53,7 +54,7 @@ class KeyChecker(SecurityBase):
|
|||||||
# FIXME: Find another way to validate the key. A fetch from DB should be avoided here.
|
# FIXME: Find another way to validate the key. A fetch from DB should be avoided here.
|
||||||
# Also, we should not return the wallet here - thats silly.
|
# Also, we should not return the wallet here - thats silly.
|
||||||
# Possibly store it in a Redis DB
|
# Possibly store it in a Redis DB
|
||||||
self.wallet = await get_wallet_for_key(key_value, self._key_type)
|
self.wallet = await get_wallet_for_key(key_value, self._key_type) # type: ignore
|
||||||
if not self.wallet:
|
if not self.wallet:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.UNAUTHORIZED,
|
status_code=HTTPStatus.UNAUTHORIZED,
|
||||||
@@ -100,9 +101,9 @@ class WalletAdminKeyChecker(KeyChecker):
|
|||||||
|
|
||||||
class WalletTypeInfo:
|
class WalletTypeInfo:
|
||||||
wallet_type: int
|
wallet_type: int
|
||||||
wallet: Union[Wallet, None]
|
wallet: Wallet
|
||||||
|
|
||||||
def __init__(self, wallet_type: int, wallet: Union[Wallet, None]) -> None:
|
def __init__(self, wallet_type: int, wallet: Wallet) -> None:
|
||||||
self.wallet_type = wallet_type
|
self.wallet_type = wallet_type
|
||||||
self.wallet = wallet
|
self.wallet = wallet
|
||||||
|
|
||||||
@@ -137,8 +138,7 @@ async def get_key_type(
|
|||||||
try:
|
try:
|
||||||
admin_checker = WalletAdminKeyChecker(api_key=token)
|
admin_checker = WalletAdminKeyChecker(api_key=token)
|
||||||
await admin_checker.__call__(r)
|
await admin_checker.__call__(r)
|
||||||
wallet = WalletTypeInfo(0, admin_checker.wallet)
|
wallet = WalletTypeInfo(0, admin_checker.wallet) # type: ignore
|
||||||
assert wallet.wallet is not None
|
|
||||||
if (LNBITS_ADMIN_USERS and wallet.wallet.user not in LNBITS_ADMIN_USERS) and (
|
if (LNBITS_ADMIN_USERS and wallet.wallet.user not in LNBITS_ADMIN_USERS) and (
|
||||||
LNBITS_ADMIN_EXTENSIONS and pathname in LNBITS_ADMIN_EXTENSIONS
|
LNBITS_ADMIN_EXTENSIONS and pathname in LNBITS_ADMIN_EXTENSIONS
|
||||||
):
|
):
|
||||||
@@ -157,9 +157,7 @@ async def get_key_type(
|
|||||||
try:
|
try:
|
||||||
invoice_checker = WalletInvoiceKeyChecker(api_key=token)
|
invoice_checker = WalletInvoiceKeyChecker(api_key=token)
|
||||||
await invoice_checker.__call__(r)
|
await invoice_checker.__call__(r)
|
||||||
wallet = WalletTypeInfo(1, invoice_checker.wallet)
|
wallet = WalletTypeInfo(1, invoice_checker.wallet) # type: ignore
|
||||||
# FIXME: wallet.wallet can be None here
|
|
||||||
assert wallet.wallet is not None
|
|
||||||
if (LNBITS_ADMIN_USERS and wallet.wallet.user not in LNBITS_ADMIN_USERS) and (
|
if (LNBITS_ADMIN_USERS and wallet.wallet.user not in LNBITS_ADMIN_USERS) and (
|
||||||
LNBITS_ADMIN_EXTENSIONS and pathname in LNBITS_ADMIN_EXTENSIONS
|
LNBITS_ADMIN_EXTENSIONS and pathname in LNBITS_ADMIN_EXTENSIONS
|
||||||
):
|
):
|
||||||
@@ -171,7 +169,7 @@ async def get_key_type(
|
|||||||
if e.status_code == HTTPStatus.BAD_REQUEST:
|
if e.status_code == HTTPStatus.BAD_REQUEST:
|
||||||
raise
|
raise
|
||||||
if e.status_code == HTTPStatus.UNAUTHORIZED:
|
if e.status_code == HTTPStatus.UNAUTHORIZED:
|
||||||
return WalletTypeInfo(2, None)
|
return WalletTypeInfo(2, None) # type: ignore
|
||||||
except:
|
except:
|
||||||
raise
|
raise
|
||||||
return wallet
|
return wallet
|
||||||
|
|||||||
Reference in New Issue
Block a user