chore: get rid of mypy notes and typecheck more functions (#3257)
This commit is contained in:
parent
1a02095758
commit
256a8098c6
8 changed files with 23 additions and 23 deletions
|
|
@ -448,7 +448,7 @@ def register_ext_routes(app: FastAPI, ext: Extension) -> None:
|
||||||
app.include_router(router=ext_route, prefix=prefix)
|
app.include_router(router=ext_route, prefix=prefix)
|
||||||
|
|
||||||
|
|
||||||
async def check_and_register_extensions(app: FastAPI):
|
async def check_and_register_extensions(app: FastAPI) -> None:
|
||||||
await check_installed_extensions(app)
|
await check_installed_extensions(app)
|
||||||
for ext in await get_valid_extensions(False):
|
for ext in await get_valid_extensions(False):
|
||||||
try:
|
try:
|
||||||
|
|
@ -458,7 +458,7 @@ async def check_and_register_extensions(app: FastAPI):
|
||||||
logger.error(f"Could not load extension `{ext.code}`: {exc!s}")
|
logger.error(f"Could not load extension `{ext.code}`: {exc!s}")
|
||||||
|
|
||||||
|
|
||||||
def register_async_tasks():
|
def register_async_tasks() -> None:
|
||||||
|
|
||||||
create_permanent_task(wait_for_audit_data)
|
create_permanent_task(wait_for_audit_data)
|
||||||
create_permanent_task(wait_notification_messages)
|
create_permanent_task(wait_notification_messages)
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ from lnbits.helpers import check_callback_url, is_valid_email_address
|
||||||
from lnbits.settings import settings
|
from lnbits.settings import settings
|
||||||
from lnbits.utils.nostr import normalize_private_key
|
from lnbits.utils.nostr import normalize_private_key
|
||||||
|
|
||||||
notifications_queue: asyncio.Queue = asyncio.Queue()
|
notifications_queue: asyncio.Queue[NotificationMessage] = asyncio.Queue()
|
||||||
|
|
||||||
|
|
||||||
def enqueue_notification(message_type: NotificationType, values: dict) -> None:
|
def enqueue_notification(message_type: NotificationType, values: dict) -> None:
|
||||||
|
|
@ -42,8 +42,8 @@ def enqueue_notification(message_type: NotificationType, values: dict) -> None:
|
||||||
logger.error(f"Error enqueuing notification: {e}")
|
logger.error(f"Error enqueuing notification: {e}")
|
||||||
|
|
||||||
|
|
||||||
async def process_next_notification():
|
async def process_next_notification() -> None:
|
||||||
notification_message: NotificationMessage = await notifications_queue.get()
|
notification_message = await notifications_queue.get()
|
||||||
message_type, text = _notification_message_to_text(notification_message)
|
message_type, text = _notification_message_to_text(notification_message)
|
||||||
await send_notification(text, message_type)
|
await send_notification(text, message_type)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ from lnbits.core.crud.audit import delete_expired_audit_entries
|
||||||
from lnbits.core.crud.payments import get_payments_status_count
|
from lnbits.core.crud.payments import get_payments_status_count
|
||||||
from lnbits.core.crud.users import get_accounts
|
from lnbits.core.crud.users import get_accounts
|
||||||
from lnbits.core.crud.wallets import get_wallets_count
|
from lnbits.core.crud.wallets import get_wallets_count
|
||||||
from lnbits.core.models import AuditEntry
|
from lnbits.core.models.audit import AuditEntry
|
||||||
from lnbits.core.models.extensions import InstallableExtension
|
from lnbits.core.models.extensions import InstallableExtension
|
||||||
from lnbits.core.models.notifications import NotificationType
|
from lnbits.core.models.notifications import NotificationType
|
||||||
from lnbits.core.services.funding_source import (
|
from lnbits.core.services.funding_source import (
|
||||||
|
|
@ -31,10 +31,10 @@ from lnbits.settings import settings
|
||||||
from lnbits.tasks import create_unique_task
|
from lnbits.tasks import create_unique_task
|
||||||
from lnbits.utils.exchange_rates import btc_rates
|
from lnbits.utils.exchange_rates import btc_rates
|
||||||
|
|
||||||
audit_queue: asyncio.Queue = asyncio.Queue()
|
audit_queue: asyncio.Queue[AuditEntry] = asyncio.Queue()
|
||||||
|
|
||||||
|
|
||||||
async def run_by_the_minute_tasks():
|
async def run_by_the_minute_tasks() -> None:
|
||||||
minute_counter = 0
|
minute_counter = 0
|
||||||
while settings.lnbits_running:
|
while settings.lnbits_running:
|
||||||
status_minutes = settings.lnbits_notification_server_status_hours * 60
|
status_minutes = settings.lnbits_notification_server_status_hours * 60
|
||||||
|
|
@ -69,7 +69,7 @@ async def run_by_the_minute_tasks():
|
||||||
await asyncio.sleep(60)
|
await asyncio.sleep(60)
|
||||||
|
|
||||||
|
|
||||||
async def _notify_server_status():
|
async def _notify_server_status() -> None:
|
||||||
accounts = await get_accounts(filters=Filters(limit=0))
|
accounts = await get_accounts(filters=Filters(limit=0))
|
||||||
wallets_count = await get_wallets_count()
|
wallets_count = await get_wallets_count()
|
||||||
payments = await get_payments_status_count()
|
payments = await get_payments_status_count()
|
||||||
|
|
@ -90,7 +90,7 @@ async def _notify_server_status():
|
||||||
enqueue_notification(NotificationType.server_status, values)
|
enqueue_notification(NotificationType.server_status, values)
|
||||||
|
|
||||||
|
|
||||||
async def wait_for_paid_invoices(invoice_paid_queue: asyncio.Queue):
|
async def wait_for_paid_invoices(invoice_paid_queue: asyncio.Queue) -> None:
|
||||||
"""
|
"""
|
||||||
This worker dispatches events to all extensions and dispatches webhooks.
|
This worker dispatches events to all extensions and dispatches webhooks.
|
||||||
"""
|
"""
|
||||||
|
|
@ -103,13 +103,13 @@ async def wait_for_paid_invoices(invoice_paid_queue: asyncio.Queue):
|
||||||
await send_payment_notification(wallet, payment)
|
await send_payment_notification(wallet, payment)
|
||||||
|
|
||||||
|
|
||||||
async def wait_for_audit_data():
|
async def wait_for_audit_data() -> None:
|
||||||
"""
|
"""
|
||||||
Waits for audit entries to be pushed to the queue.
|
Waits for audit entries to be pushed to the queue.
|
||||||
Then it inserts the entries into the DB.
|
Then it inserts the entries into the DB.
|
||||||
"""
|
"""
|
||||||
while settings.lnbits_running:
|
while settings.lnbits_running:
|
||||||
data: AuditEntry = await audit_queue.get()
|
data = await audit_queue.get()
|
||||||
try:
|
try:
|
||||||
await create_audit_entry(data)
|
await create_audit_entry(data)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
|
@ -117,7 +117,7 @@ async def wait_for_audit_data():
|
||||||
await asyncio.sleep(3)
|
await asyncio.sleep(3)
|
||||||
|
|
||||||
|
|
||||||
async def wait_notification_messages():
|
async def wait_notification_messages() -> None:
|
||||||
|
|
||||||
while settings.lnbits_running:
|
while settings.lnbits_running:
|
||||||
try:
|
try:
|
||||||
|
|
@ -127,7 +127,7 @@ async def wait_notification_messages():
|
||||||
await asyncio.sleep(3)
|
await asyncio.sleep(3)
|
||||||
|
|
||||||
|
|
||||||
async def purge_audit_data():
|
async def purge_audit_data() -> None:
|
||||||
"""
|
"""
|
||||||
Remove audit entries which have passed their retention period.
|
Remove audit entries which have passed their retention period.
|
||||||
"""
|
"""
|
||||||
|
|
@ -141,7 +141,7 @@ async def purge_audit_data():
|
||||||
await asyncio.sleep(60 * 60)
|
await asyncio.sleep(60 * 60)
|
||||||
|
|
||||||
|
|
||||||
async def collect_exchange_rates_data():
|
async def collect_exchange_rates_data() -> None:
|
||||||
"""
|
"""
|
||||||
Collect exchange rates data. Used for monitoring only.
|
Collect exchange rates data. Used for monitoring only.
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ from typing import Optional
|
||||||
import httpx
|
import httpx
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from websockets.legacy.client import WebSocketClientProtocol, connect
|
from websockets.legacy.client import connect
|
||||||
from websockets.typing import Subprotocol
|
from websockets.typing import Subprotocol
|
||||||
|
|
||||||
from lnbits import bolt11
|
from lnbits import bolt11
|
||||||
|
|
@ -48,7 +48,7 @@ class BlinkWallet(Wallet):
|
||||||
"payload": {"X-API-KEY": settings.blink_token},
|
"payload": {"X-API-KEY": settings.blink_token},
|
||||||
}
|
}
|
||||||
self.client = httpx.AsyncClient(base_url=self.endpoint, headers=self.auth)
|
self.client = httpx.AsyncClient(base_url=self.endpoint, headers=self.auth)
|
||||||
self.ws: Optional[WebSocketClientProtocol] = None
|
self.ws = None
|
||||||
self._wallet_id = None
|
self._wallet_id = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ class BoltzWallet(Wallet):
|
||||||
channel = grpc.aio.insecure_channel(settings.boltz_client_endpoint)
|
channel = grpc.aio.insecure_channel(settings.boltz_client_endpoint)
|
||||||
|
|
||||||
self.rpc = boltzrpc_pb2_grpc.BoltzStub(channel)
|
self.rpc = boltzrpc_pb2_grpc.BoltzStub(channel)
|
||||||
self.wallet_id: int = 0
|
self.wallet_id = 0
|
||||||
|
|
||||||
# Auto-create wallet if running in Docker mode
|
# Auto-create wallet if running in Docker mode
|
||||||
async def _init_boltz_wallet():
|
async def _init_boltz_wallet():
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ class NWCWallet(Wallet):
|
||||||
# interval in seconds between checks for pending payments
|
# interval in seconds between checks for pending payments
|
||||||
self.pending_payments_lookup_interval = 10
|
self.pending_payments_lookup_interval = 10
|
||||||
# track paid invoices for paid_invoices_stream
|
# track paid invoices for paid_invoices_stream
|
||||||
self.paid_invoices_queue: asyncio.Queue = asyncio.Queue(0)
|
self.paid_invoices_queue = asyncio.Queue(0)
|
||||||
# This task periodically checks if pending payments have been settled
|
# This task periodically checks if pending payments have been settled
|
||||||
self.pending_payments_lookup_task = asyncio.create_task(
|
self.pending_payments_lookup_task = asyncio.create_task(
|
||||||
self._handle_pending_payments()
|
self._handle_pending_payments()
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ class TokenBucket:
|
||||||
Token bucket rate limiter for Strike API endpoints.
|
Token bucket rate limiter for Strike API endpoints.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, rate: int, period_seconds: int):
|
def __init__(self, rate: int, period_seconds: int) -> None:
|
||||||
"""
|
"""
|
||||||
Initialize a token bucket.
|
Initialize a token bucket.
|
||||||
|
|
||||||
|
|
@ -77,7 +77,7 @@ class StrikeWallet(Wallet):
|
||||||
# construction / teardown #
|
# construction / teardown #
|
||||||
# --------------------------------------------------------------------- #
|
# --------------------------------------------------------------------- #
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self) -> None:
|
||||||
if not settings.strike_api_endpoint:
|
if not settings.strike_api_endpoint:
|
||||||
raise ValueError("Missing strike_api_endpoint")
|
raise ValueError("Missing strike_api_endpoint")
|
||||||
if not settings.strike_api_key:
|
if not settings.strike_api_key:
|
||||||
|
|
@ -120,7 +120,7 @@ class StrikeWallet(Wallet):
|
||||||
self._cached_balance_ts: float = 0.0
|
self._cached_balance_ts: float = 0.0
|
||||||
self._cache_ttl = 30 # seconds
|
self._cache_ttl = 30 # seconds
|
||||||
|
|
||||||
async def cleanup(self):
|
async def cleanup(self) -> None:
|
||||||
try:
|
try:
|
||||||
await self.client.aclose()
|
await self.client.aclose()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ async def test_crud_search_payments():
|
||||||
|
|
||||||
user = await create_user_account()
|
user = await create_user_account()
|
||||||
wallet = await create_wallet(user_id=user.id)
|
wallet = await create_wallet(user_id=user.id)
|
||||||
filters: Filters = Filters(
|
filters = Filters(
|
||||||
search="",
|
search="",
|
||||||
model=PaymentFilters,
|
model=PaymentFilters,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue