diff --git a/client_manager.py b/client_manager.py index b8f61ab..dcc2c3e 100644 --- a/client_manager.py +++ b/client_manager.py @@ -322,9 +322,9 @@ class NostrClientConnection: if account.blocked: return ( - False, - f"Public key '{pubkey}' is not allowed in relay '{self.relay_id}'!", - ) + False, + f"Public key '{pubkey}' is not allowed in relay '{self.relay_id}'!", + ) if not account.can_join and self.client_config.is_paid_relay: return False, f"This is a paid relay: '{self.relay_id}'" diff --git a/crud.py b/crud.py index 82c1cca..d6aad4c 100644 --- a/crud.py +++ b/crud.py @@ -375,10 +375,11 @@ async def get_account( return NostrAccount.from_row(row) if row else None + async def get_accounts( relay_id: str, - allowed = True, - blocked = False, + allowed=True, + blocked=False, ) -> List[NostrAccount]: rows = await db.fetchall( "SELECT * FROM nostrrelay.accounts WHERE relay_id = ? AND allowed = ? AND blocked = ?", diff --git a/models.py b/models.py index d482f19..7eb5dd2 100644 --- a/models.py +++ b/models.py @@ -83,7 +83,6 @@ class PaymentSpec(BaseModel): storage_cost_unit = Field("MB", alias="storageCostUnit") - class WalletSpec(Spec): wallet = Field("") @@ -332,11 +331,14 @@ class BuyOrder(BaseModel): def is_valid_action(self): return self.action in ["join", "storage"] + class NostrPartialAccount(BaseModel): relay_id: str pubkey: str allowed: Optional[bool] blocked: Optional[bool] + + class NostrAccount(BaseModel): pubkey: str allowed = False diff --git a/tasks.py b/tasks.py index 521fca4..87b8eed 100644 --- a/tasks.py +++ b/tasks.py @@ -27,7 +27,9 @@ async def on_invoice_paid(payment: Payment): 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}") + logger.warning( + f"Invoice extra data missing for 'relay_id' and 'pubkey'. Payment hash: {payment.payment_hash}" + ) return if payment.extra.get("action") == "join": @@ -37,7 +39,9 @@ async def on_invoice_paid(payment: Payment): 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}") + 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 @@ -63,12 +67,15 @@ 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: int): +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: await create_account( - relay_id, NostrAccount(pubkey=pubkey, storage=storage_to_buy, sats=amount) + relay_id, + NostrAccount(pubkey=pubkey, storage=storage_to_buy, sats=amount), ) return diff --git a/views_api.py b/views_api.py index 94bb1df..1d1c843 100644 --- a/views_api.py +++ b/views_api.py @@ -155,15 +155,19 @@ async def api_create_or_update_account( data.pubkey = normalize_public_key(data.pubkey) account = await get_account(data.relay_id, data.pubkey) if not account: - account = NostrAccount(pubkey=data.pubkey, blocked = data.blocked or False, allowed = data.allowed or False) + account = NostrAccount( + pubkey=data.pubkey, + blocked=data.blocked or False, + allowed=data.allowed or False, + ) return await create_account(data.relay_id, account) if data.blocked is not None: account.blocked = data.blocked if data.allowed is not None: account.allowed = data.allowed - - return await update_account(data.relay_id, account) + + return await update_account(data.relay_id, account) except ValueError as ex: raise HTTPException( @@ -182,7 +186,10 @@ async def api_create_or_update_account( @nostrrelay_ext.get("/api/v1/account") async def api_get_accounts( - relay_id: str, allowed = False, blocked = True, wallet: WalletTypeInfo = Depends(require_invoice_key) + relay_id: str, + allowed=False, + blocked=True, + wallet: WalletTypeInfo = Depends(require_invoice_key), ) -> List[NostrAccount]: try: # make sure the user has access to the relay @@ -209,7 +216,6 @@ async def api_get_accounts( ) - @nostrrelay_ext.delete("/api/v1/relay/{relay_id}") async def api_delete_relay( relay_id: str, wallet: WalletTypeInfo = Depends(require_admin_key)