chore: mypy fixes
This commit is contained in:
parent
d0f38346e3
commit
bc1af610db
7 changed files with 27 additions and 11 deletions
|
|
@ -94,8 +94,8 @@ class NostrClientConnection:
|
|||
self.relay_id = relay_id
|
||||
self.filters: List[NostrFilter] = []
|
||||
self.authenticated = False
|
||||
self.pubkey: str = None
|
||||
self._auth_challenge: str = None
|
||||
self.pubkey: Optional[str] = None
|
||||
self._auth_challenge: Optional[str] = None
|
||||
self._auth_challenge_created_at = 0
|
||||
|
||||
self._last_event_timestamp = 0 # in seconds
|
||||
|
|
@ -158,7 +158,7 @@ class NostrClientConnection:
|
|||
if message_type == NostrEventType.CLOSE:
|
||||
self._handle_close(data[1])
|
||||
if message_type == NostrEventType.AUTH:
|
||||
await self._handle_auth(data[1])
|
||||
await self._handle_auth()
|
||||
|
||||
return []
|
||||
|
||||
|
|
@ -269,7 +269,7 @@ class NostrClientConnection:
|
|||
def _validate_auth_event(self, e: NostrEvent) -> Tuple[bool, str]:
|
||||
valid, message = self._validate_event(e)
|
||||
if not valid:
|
||||
return [valid, message]
|
||||
return (valid, message)
|
||||
|
||||
relay_tag = e.tag_values("relay")
|
||||
challenge_tag = e.tag_values("challenge")
|
||||
|
|
|
|||
|
|
@ -216,7 +216,7 @@ class NostrEvent(BaseModel):
|
|||
def serialize_response(self, subscription_id):
|
||||
return [NostrEventType.EVENT, subscription_id, dict(self)]
|
||||
|
||||
def tag_values(self, tag_name: str) -> List[List[str]]:
|
||||
def tag_values(self, tag_name: str) -> List[str]:
|
||||
return [t[1] for t in self.tags if t[0] == tag_name]
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
9
tasks.py
9
tasks.py
|
|
@ -26,12 +26,19 @@ async def on_invoice_paid(payment: Payment):
|
|||
relay_id = payment.extra.get("relay_id")
|
||||
pubkey = payment.extra.get("pubkey")
|
||||
|
||||
if not relay_id or not pubkey:
|
||||
logger.warning(f"Invoice extra data missing for 'relay_id' and 'pubkey'. Payment hash: {payment.payment_hash}")
|
||||
return
|
||||
|
||||
if payment.extra.get("action") == "join":
|
||||
await invoice_paid_to_join(relay_id, pubkey, payment.amount)
|
||||
return
|
||||
|
||||
if payment.extra.get("action") == "storage":
|
||||
storage_to_buy = payment.extra.get("storage_to_buy")
|
||||
if not storage_to_buy:
|
||||
logger.warning(f"Invoice extra data missing for 'storage_to_buy'. Payment hash: {payment.payment_hash}")
|
||||
return
|
||||
await invoice_paid_for_storage(relay_id, pubkey, storage_to_buy, payment.amount)
|
||||
return
|
||||
|
||||
|
|
@ -56,7 +63,7 @@ async def invoice_paid_to_join(relay_id: str, pubkey: str, amount: int):
|
|||
logger.warning(ex)
|
||||
|
||||
|
||||
async def invoice_paid_for_storage(relay_id: str, pubkey: str, storage_to_buy: int, amount: str):
|
||||
async def invoice_paid_for_storage(relay_id: str, pubkey: str, storage_to_buy: int, amount: int):
|
||||
try:
|
||||
account = await get_account(relay_id, pubkey)
|
||||
if not account:
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@ import pytest
|
|||
from fastapi import WebSocket
|
||||
from loguru import logger
|
||||
|
||||
from lnbits.extensions.nostrrelay.client_manager import (
|
||||
from lnbits.extensions.nostrrelay.client_manager import ( # type: ignore
|
||||
NostrClientConnection,
|
||||
NostrClientManager,
|
||||
)
|
||||
from lnbits.extensions.nostrrelay.models import RelaySpec
|
||||
from lnbits.extensions.nostrrelay.models import RelaySpec # type: ignore
|
||||
|
||||
from .helpers import get_fixtures
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,12 @@ import pytest
|
|||
from loguru import logger
|
||||
from pydantic import BaseModel
|
||||
|
||||
from lnbits.extensions.nostrrelay.crud import create_event, get_event, get_events
|
||||
from lnbits.extensions.nostrrelay.models import NostrEvent, NostrFilter
|
||||
from lnbits.extensions.nostrrelay.crud import ( # type: ignore
|
||||
create_event,
|
||||
get_event,
|
||||
get_events,
|
||||
)
|
||||
from lnbits.extensions.nostrrelay.models import NostrEvent, NostrFilter # type: ignore
|
||||
|
||||
from .helpers import get_fixtures
|
||||
|
||||
|
|
|
|||
2
views.py
2
views.py
|
|
@ -7,9 +7,9 @@ from starlette.responses import HTMLResponse, JSONResponse
|
|||
|
||||
from lnbits.core.models import User
|
||||
from lnbits.decorators import check_user_exists
|
||||
from lnbits.extensions.nostrrelay.crud import get_public_relay
|
||||
|
||||
from . import nostrrelay_ext, nostrrelay_renderer
|
||||
from .crud import get_public_relay
|
||||
|
||||
templates = Jinja2Templates(directory="templates")
|
||||
|
||||
|
|
|
|||
|
|
@ -185,6 +185,11 @@ async def api_get_accounts(
|
|||
try:
|
||||
# make sure the user has access to the relay
|
||||
relay = await get_relay(wallet.wallet.user, relay_id)
|
||||
if not relay:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND,
|
||||
detail="Relay not found",
|
||||
)
|
||||
accounts = await get_accounts(relay.id, allowed, blocked)
|
||||
return accounts
|
||||
except ValueError as ex:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue