some more mypy fixes
This commit is contained in:
parent
45a13fd807
commit
8901ff8084
9 changed files with 25 additions and 16 deletions
|
|
@ -113,7 +113,7 @@ async def create_wallet(
|
||||||
async def update_wallet(
|
async def update_wallet(
|
||||||
wallet_id: str, new_name: str, conn: Optional[Connection] = None
|
wallet_id: str, new_name: str, conn: Optional[Connection] = None
|
||||||
) -> Optional[Wallet]:
|
) -> Optional[Wallet]:
|
||||||
await (conn or db).execute(
|
return await (conn or db).execute(
|
||||||
"""
|
"""
|
||||||
UPDATE wallets SET
|
UPDATE wallets SET
|
||||||
name = ?
|
name = ?
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,8 @@ class Payment(BaseModel):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def tag(self) -> Optional[str]:
|
def tag(self) -> Optional[str]:
|
||||||
|
if self.extra is None:
|
||||||
|
return ""
|
||||||
return self.extra.get("tag")
|
return self.extra.get("tag")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import hashlib
|
||||||
import json
|
import json
|
||||||
from binascii import unhexlify
|
from binascii import unhexlify
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from typing import Dict, List, Optional, Union
|
from typing import Dict, List, Optional, Union, Tuple
|
||||||
from urllib.parse import ParseResult, parse_qs, urlencode, urlparse, urlunparse
|
from urllib.parse import ParseResult, parse_qs, urlencode, urlparse, urlunparse
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
|
@ -185,7 +185,7 @@ async def api_payments_create_invoice(data: CreateInvoiceData, wallet: Wallet):
|
||||||
assert (
|
assert (
|
||||||
data.lnurl_balance_check is not None
|
data.lnurl_balance_check is not None
|
||||||
), "lnurl_balance_check is required"
|
), "lnurl_balance_check is required"
|
||||||
save_balance_check(wallet.id, data.lnurl_balance_check)
|
await save_balance_check(wallet.id, data.lnurl_balance_check)
|
||||||
|
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
try:
|
try:
|
||||||
|
|
@ -291,7 +291,7 @@ async def api_payments_pay_lnurl(
|
||||||
timeout=40,
|
timeout=40,
|
||||||
)
|
)
|
||||||
if r.is_error:
|
if r.is_error:
|
||||||
raise httpx.ConnectError
|
raise httpx.ConnectError("LNURL Callback Connection Error")
|
||||||
except (httpx.ConnectError, httpx.RequestError):
|
except (httpx.ConnectError, httpx.RequestError):
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.BAD_REQUEST,
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
|
|
@ -348,7 +348,7 @@ async def subscribe(request: Request, wallet: Wallet):
|
||||||
logger.debug("adding sse listener", payment_queue)
|
logger.debug("adding sse listener", payment_queue)
|
||||||
api_invoice_listeners.append(payment_queue)
|
api_invoice_listeners.append(payment_queue)
|
||||||
|
|
||||||
send_queue: asyncio.Queue[tuple[str, Payment]] = asyncio.Queue(0)
|
send_queue: asyncio.Queue[Tuple[str, Payment]] = asyncio.Queue(0)
|
||||||
|
|
||||||
async def payment_received() -> None:
|
async def payment_received() -> None:
|
||||||
while True:
|
while True:
|
||||||
|
|
@ -389,9 +389,12 @@ async def api_payment(payment_hash, X_Api_Key: Optional[str] = Header(None)):
|
||||||
# If a valid key is given, we also return the field "details", otherwise not
|
# If a valid key is given, we also return the field "details", otherwise not
|
||||||
wallet = None
|
wallet = None
|
||||||
try:
|
try:
|
||||||
|
assert X_Api_Key is not None
|
||||||
|
# TODO: type above is Optional[str] how can that have .extra?
|
||||||
if X_Api_Key.extra:
|
if X_Api_Key.extra:
|
||||||
logger.warning("No key")
|
logger.warning("No key")
|
||||||
except:
|
except:
|
||||||
|
if X_Api_Key is not None:
|
||||||
wallet = await get_wallet_for_key(X_Api_Key)
|
wallet = await get_wallet_for_key(X_Api_Key)
|
||||||
payment = await get_standalone_payment(
|
payment = await get_standalone_payment(
|
||||||
payment_hash, wallet_id=wallet.id if wallet else None
|
payment_hash, wallet_id=wallet.id if wallet else None
|
||||||
|
|
@ -606,7 +609,7 @@ class ConversionData(BaseModel):
|
||||||
async def api_fiat_as_sats(data: ConversionData):
|
async def api_fiat_as_sats(data: ConversionData):
|
||||||
output = {}
|
output = {}
|
||||||
if data.from_ == "sat":
|
if data.from_ == "sat":
|
||||||
output["sats"] = int(data.amount)
|
output["sats"] = data.amount
|
||||||
output["BTC"] = data.amount / 100000000
|
output["BTC"] = data.amount / 100000000
|
||||||
for currency in data.to.split(","):
|
for currency in data.to.split(","):
|
||||||
output[currency.strip().upper()] = await satoshis_amount_as_fiat(
|
output[currency.strip().upper()] = await satoshis_amount_as_fiat(
|
||||||
|
|
|
||||||
|
|
@ -112,9 +112,11 @@ async def wallet(
|
||||||
|
|
||||||
if not user_id:
|
if not user_id:
|
||||||
user = await get_user((await create_account()).id)
|
user = await get_user((await create_account()).id)
|
||||||
|
assert user is not None
|
||||||
logger.info(f"Created new account for user {user.id}")
|
logger.info(f"Created new account for user {user.id}")
|
||||||
else:
|
else:
|
||||||
user = await get_user(user_id)
|
user = await get_user(user_id)
|
||||||
|
assert user is not None
|
||||||
if not user:
|
if not user:
|
||||||
return template_renderer().TemplateResponse(
|
return template_renderer().TemplateResponse(
|
||||||
"error.html", {"request": request, "err": "User does not exist."}
|
"error.html", {"request": request, "err": "User does not exist."}
|
||||||
|
|
@ -209,6 +211,7 @@ async def lnurl_full_withdraw_callback(request: Request):
|
||||||
@core_html_routes.get("/deletewallet", response_class=RedirectResponse)
|
@core_html_routes.get("/deletewallet", response_class=RedirectResponse)
|
||||||
async def deletewallet(request: Request, wal: str = Query(...), usr: str = Query(...)):
|
async def deletewallet(request: Request, wal: str = Query(...), usr: str = Query(...)):
|
||||||
user = await get_user(usr)
|
user = await get_user(usr)
|
||||||
|
assert user is not None
|
||||||
user_wallet_ids = [u.id for u in user.wallets]
|
user_wallet_ids = [u.id for u in user.wallets]
|
||||||
|
|
||||||
if wal not in user_wallet_ids:
|
if wal not in user_wallet_ids:
|
||||||
|
|
@ -233,7 +236,7 @@ async def deletewallet(request: Request, wal: str = Query(...), usr: str = Query
|
||||||
async def lnurl_balance_notify(request: Request, service: str):
|
async def lnurl_balance_notify(request: Request, service: str):
|
||||||
bc = await get_balance_check(request.query_params.get("wal"), service)
|
bc = await get_balance_check(request.query_params.get("wal"), service)
|
||||||
if bc:
|
if bc:
|
||||||
redeem_lnurl_withdraw(bc.wallet, bc.url)
|
await redeem_lnurl_withdraw(bc.wallet, bc.url)
|
||||||
|
|
||||||
|
|
||||||
@core_html_routes.get(
|
@core_html_routes.get(
|
||||||
|
|
@ -243,6 +246,7 @@ async def lnurlwallet(request: Request):
|
||||||
async with db.connect() as conn:
|
async with db.connect() as conn:
|
||||||
account = await create_account(conn=conn)
|
account = await create_account(conn=conn)
|
||||||
user = await get_user(account.id, conn=conn)
|
user = await get_user(account.id, conn=conn)
|
||||||
|
assert user is not None
|
||||||
wallet = await create_wallet(user_id=user.id, conn=conn)
|
wallet = await create_wallet(user_id=user.id, conn=conn)
|
||||||
|
|
||||||
asyncio.create_task(
|
asyncio.create_task(
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ class ExtensionManager:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extensions(self) -> List[Extension]:
|
def extensions(self) -> List[Extension]:
|
||||||
output = []
|
output: List[Extension] = []
|
||||||
|
|
||||||
if "all" in self._disabled:
|
if "all" in self._disabled:
|
||||||
return output
|
return output
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ async def webhook_handler():
|
||||||
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
internal_invoice_queue = asyncio.Queue(0)
|
internal_invoice_queue: asyncio.Queue = asyncio.Queue(0)
|
||||||
|
|
||||||
|
|
||||||
async def internal_invoice_listener():
|
async def internal_invoice_listener():
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
from typing import Callable, NamedTuple
|
from typing import Callable, NamedTuple, List
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
@ -227,10 +227,10 @@ async def btc_price(currency: str) -> float:
|
||||||
"TO": currency.upper(),
|
"TO": currency.upper(),
|
||||||
"to": currency.lower(),
|
"to": currency.lower(),
|
||||||
}
|
}
|
||||||
rates = []
|
rates: List[float] = []
|
||||||
tasks = []
|
tasks: List[asyncio.Task] = []
|
||||||
|
|
||||||
send_channel = asyncio.Queue()
|
send_channel: asyncio.Queue = asyncio.Queue()
|
||||||
|
|
||||||
async def controller():
|
async def controller():
|
||||||
failures = 0
|
failures = 0
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,7 @@ class LNPayWallet(Wallet):
|
||||||
return PaymentStatus(statuses[r.json()["settled"]])
|
return PaymentStatus(statuses[r.json()["settled"]])
|
||||||
|
|
||||||
async def paid_invoices_stream(self) -> AsyncGenerator[str, None]:
|
async def paid_invoices_stream(self) -> AsyncGenerator[str, None]:
|
||||||
self.queue = asyncio.Queue(0)
|
self.queue: asyncio.Queue = asyncio.Queue(0)
|
||||||
while True:
|
while True:
|
||||||
value = await self.queue.get()
|
value = await self.queue.get()
|
||||||
yield value
|
yield value
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ class OpenNodeWallet(Wallet):
|
||||||
return PaymentStatus(statuses[r.json()["data"]["status"]])
|
return PaymentStatus(statuses[r.json()["data"]["status"]])
|
||||||
|
|
||||||
async def paid_invoices_stream(self) -> AsyncGenerator[str, None]:
|
async def paid_invoices_stream(self) -> AsyncGenerator[str, None]:
|
||||||
self.queue = asyncio.Queue(0)
|
self.queue: asyncio.Queue = asyncio.Queue(0)
|
||||||
while True:
|
while True:
|
||||||
value = await self.queue.get()
|
value = await self.queue.get()
|
||||||
yield value
|
yield value
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue