chore: code format

This commit is contained in:
Vlad Stan 2023-02-10 17:25:02 +02:00
parent 8678090e7b
commit ebada934b0
6 changed files with 32 additions and 29 deletions

View file

@ -61,13 +61,12 @@ async def get_relay(user_id: str, relay_id: str) -> Optional[NostrRelay]:
return NostrRelay.from_row(row) if row else None
async def get_relay_by_id(relay_id: str) -> Optional[NostrRelay]:
"""Note: it does not require `user_id`. Can read any relay. Use it with care."""
row = await db.fetchone(
"""SELECT * FROM nostrrelay.relays WHERE id = ?""",
(
relay_id,
),
(relay_id,),
)
return NostrRelay.from_row(row) if row else None
@ -111,7 +110,7 @@ async def get_public_relay(relay_id: str) -> Optional[dict]:
"description": relay.description,
"pubkey": relay.pubkey,
"contact": relay.contact,
"config": RelayPublicSpec(**dict(relay.config)).dict(by_alias=True)
"config": RelayPublicSpec(**dict(relay.config)).dict(by_alias=True),
}

View file

@ -2,7 +2,7 @@ from bech32 import bech32_decode, convertbits
def normalize_public_key(pubkey: str) -> str:
if pubkey.startswith('npub1'):
if pubkey.startswith("npub1"):
_, decoded_data = bech32_decode(pubkey)
if not decoded_data:
raise ValueError("Public Key is not valid npub")
@ -12,7 +12,7 @@ def normalize_public_key(pubkey: str) -> str:
raise ValueError("Public Key is not valid npub")
return bytes(decoded_data_bits).hex()
#check if valid hex
# check if valid hex
if len(pubkey) != 64:
raise ValueError("Public Key is not valid hex")
int(pubkey, 16)

View file

@ -11,10 +11,13 @@ from secp256k1 import PublicKey
class Spec(BaseModel):
class Config:
allow_population_by_field_name = True
class FilterSpec(Spec):
max_client_filters = Field(0, alias="maxClientFilters")
limit_per_filter = Field(1000, alias="limitPerFilter")
class EventSpec(Spec):
max_events_per_second = Field(0, alias="maxEventsPerSecond")
@ -28,7 +31,6 @@ class EventSpec(Spec):
created_at_minutes_future = Field(0, alias="createdAtMinutesFuture")
created_at_seconds_future = Field(0, alias="createdAtSecondsFuture")
@property
def created_at_in_past(self) -> int:
return (
@ -47,6 +49,7 @@ class EventSpec(Spec):
+ self.created_at_seconds_future
)
class StorageSpec(Spec):
free_storage_value = Field(1, alias="freeStorageValue")
free_storage_unit = Field("MB", alias="freeStorageUnit")
@ -59,6 +62,7 @@ class StorageSpec(Spec):
value *= 1024
return value
class AuthorSpec(Spec):
allowed_public_keys = Field([], alias="allowedPublicKeys")
blocked_public_keys = Field([], alias="blockedPublicKeys")
@ -78,15 +82,22 @@ class PaymentSpec(BaseModel):
storage_cost_value = Field(0, alias="storageCostValue")
storage_cost_unit = Field("MB", alias="storageCostUnit")
class WalletSpec(Spec):
wallet = Field("")
class RelaySpec(FilterSpec, EventSpec, StorageSpec, AuthorSpec, PaymentSpec, WalletSpec):
class RelaySpec(
FilterSpec, EventSpec, StorageSpec, AuthorSpec, PaymentSpec, WalletSpec
):
pass
class RelayPublicSpec(FilterSpec, EventSpec, StorageSpec, PaymentSpec):
pass
class NostrRelay(BaseModel):
id: str
name: str

View file

@ -42,7 +42,7 @@
<q-card-section v-if="joinInvoice">
<q-expansion-item
group="join-invoice"
label="Join Invoice"
label="Pay invoice to join relay"
:content-inset-level="0.5"
default-opened
>

View file

@ -155,9 +155,7 @@ async def api_delete_relay(
@nostrrelay_ext.put("/api/v1/join")
async def api_pay_to_join(
data: RelayJoin
):
async def api_pay_to_join(data: RelayJoin):
try:
pubkey = normalize_public_key(data.pubkey)
@ -179,13 +177,11 @@ async def api_pay_to_join(
"tag": "nostrrely",
"action": "join",
"relay": relay.id,
"pubkey": pubkey
"pubkey": pubkey,
},
)
print("### payment_request", payment_request)
return {
"invoice": payment_request
}
return {"invoice": payment_request}
except ValueError as ex:
raise HTTPException(
status_code=HTTPStatus.BAD_REQUEST,
@ -199,6 +195,3 @@ async def api_pay_to_join(
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
detail="Cannot create invoice for client to join",
)