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:
|
if account.blocked:
|
||||||
return (
|
return (
|
||||||
False,
|
False,
|
||||||
f"Public key '{pubkey}' is not allowed in relay '{self.relay_id}'!",
|
f"Public key '{pubkey}' is not allowed in relay '{self.relay_id}'!",
|
||||||
)
|
)
|
||||||
|
|
||||||
if not account.can_join and self.client_config.is_paid_relay:
|
if not account.can_join and self.client_config.is_paid_relay:
|
||||||
return False, f"This is a paid relay: '{self.relay_id}'"
|
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
|
return NostrAccount.from_row(row) if row else None
|
||||||
|
|
||||||
|
|
||||||
async def get_accounts(
|
async def get_accounts(
|
||||||
relay_id: str,
|
relay_id: str,
|
||||||
allowed = True,
|
allowed=True,
|
||||||
blocked = False,
|
blocked=False,
|
||||||
) -> List[NostrAccount]:
|
) -> List[NostrAccount]:
|
||||||
rows = await db.fetchall(
|
rows = await db.fetchall(
|
||||||
"SELECT * FROM nostrrelay.accounts WHERE relay_id = ? AND allowed = ? AND blocked = ?",
|
"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")
|
storage_cost_unit = Field("MB", alias="storageCostUnit")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class WalletSpec(Spec):
|
class WalletSpec(Spec):
|
||||||
wallet = Field("")
|
wallet = Field("")
|
||||||
|
|
||||||
|
|
@ -332,11 +331,14 @@ class BuyOrder(BaseModel):
|
||||||
def is_valid_action(self):
|
def is_valid_action(self):
|
||||||
return self.action in ["join", "storage"]
|
return self.action in ["join", "storage"]
|
||||||
|
|
||||||
|
|
||||||
class NostrPartialAccount(BaseModel):
|
class NostrPartialAccount(BaseModel):
|
||||||
relay_id: str
|
relay_id: str
|
||||||
pubkey: str
|
pubkey: str
|
||||||
allowed: Optional[bool]
|
allowed: Optional[bool]
|
||||||
blocked: Optional[bool]
|
blocked: Optional[bool]
|
||||||
|
|
||||||
|
|
||||||
class NostrAccount(BaseModel):
|
class NostrAccount(BaseModel):
|
||||||
pubkey: str
|
pubkey: str
|
||||||
allowed = False
|
allowed = False
|
||||||
|
|
|
||||||
15
tasks.py
15
tasks.py
|
|
@ -27,7 +27,9 @@ async def on_invoice_paid(payment: Payment):
|
||||||
pubkey = payment.extra.get("pubkey")
|
pubkey = payment.extra.get("pubkey")
|
||||||
|
|
||||||
if not relay_id or not 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
|
return
|
||||||
|
|
||||||
if payment.extra.get("action") == "join":
|
if payment.extra.get("action") == "join":
|
||||||
|
|
@ -37,7 +39,9 @@ async def on_invoice_paid(payment: Payment):
|
||||||
if payment.extra.get("action") == "storage":
|
if payment.extra.get("action") == "storage":
|
||||||
storage_to_buy = payment.extra.get("storage_to_buy")
|
storage_to_buy = payment.extra.get("storage_to_buy")
|
||||||
if not 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
|
return
|
||||||
await invoice_paid_for_storage(relay_id, pubkey, storage_to_buy, payment.amount)
|
await invoice_paid_for_storage(relay_id, pubkey, storage_to_buy, payment.amount)
|
||||||
return
|
return
|
||||||
|
|
@ -63,12 +67,15 @@ async def invoice_paid_to_join(relay_id: str, pubkey: str, amount: int):
|
||||||
logger.warning(ex)
|
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:
|
try:
|
||||||
account = await get_account(relay_id, pubkey)
|
account = await get_account(relay_id, pubkey)
|
||||||
if not account:
|
if not account:
|
||||||
await create_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
|
return
|
||||||
|
|
||||||
|
|
|
||||||
12
views_api.py
12
views_api.py
|
|
@ -155,7 +155,11 @@ async def api_create_or_update_account(
|
||||||
data.pubkey = normalize_public_key(data.pubkey)
|
data.pubkey = normalize_public_key(data.pubkey)
|
||||||
account = await get_account(data.relay_id, data.pubkey)
|
account = await get_account(data.relay_id, data.pubkey)
|
||||||
if not account:
|
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)
|
return await create_account(data.relay_id, account)
|
||||||
|
|
||||||
if data.blocked is not None:
|
if data.blocked is not None:
|
||||||
|
|
@ -182,7 +186,10 @@ async def api_create_or_update_account(
|
||||||
|
|
||||||
@nostrrelay_ext.get("/api/v1/account")
|
@nostrrelay_ext.get("/api/v1/account")
|
||||||
async def api_get_accounts(
|
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]:
|
) -> List[NostrAccount]:
|
||||||
try:
|
try:
|
||||||
# make sure the user has access to the relay
|
# 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}")
|
@nostrrelay_ext.delete("/api/v1/relay/{relay_id}")
|
||||||
async def api_delete_relay(
|
async def api_delete_relay(
|
||||||
relay_id: str, wallet: WalletTypeInfo = Depends(require_admin_key)
|
relay_id: str, wallet: WalletTypeInfo = Depends(require_admin_key)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue