chore: code format
This commit is contained in:
parent
5a984bddcd
commit
aed098499a
5 changed files with 31 additions and 15 deletions
|
|
@ -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}'"
|
||||
|
|
|
|||
5
crud.py
5
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 = ?",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
15
tasks.py
15
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
|
||||
|
||||
|
|
|
|||
16
views_api.py
16
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue