diff --git a/crud.py b/crud.py
index 629bf91..28c986d 100644
--- a/crud.py
+++ b/crud.py
@@ -11,10 +11,10 @@ from .models import NostrEvent, NostrFilter, NostrRelay
async def create_relay(user_id: str, r: NostrRelay) -> NostrRelay:
await db.execute(
"""
- INSERT INTO nostrrelay.relays (user_id, id, name, description, pubkey, contact)
- VALUES (?, ?, ?, ?, ?, ?)
+ INSERT INTO nostrrelay.relays (user_id, id, name, description, pubkey, contact, meta)
+ VALUES (?, ?, ?, ?, ?, ?, ?)
""",
- (user_id, r.id, r.name, r.description, r.pubkey, r.contact,),
+ (user_id, r.id, r.name, r.description, r.pubkey, r.contact, json.dumps(dict(r.config))),
)
relay = await get_relay(user_id, r.id)
assert relay, "Created relay cannot be retrieved"
@@ -24,10 +24,10 @@ async def update_relay(user_id: str, r: NostrRelay) -> NostrRelay:
await db.execute(
"""
UPDATE nostrrelay.relays
- SET (name, description, pubkey, contact, active) = (?, ?, ?, ?, ?)
+ SET (name, description, pubkey, contact, active, meta) = (?, ?, ?, ?, ?, ?)
WHERE user_id = ? AND id = ?
""",
- (r.name, r.description, r.pubkey, r.contact, r.active, user_id, r.id),
+ (r.name, r.description, r.pubkey, r.contact, r.active, json.dumps(dict(r.config)), user_id, r.id),
)
return r
diff --git a/models.py b/models.py
index 6f703fd..bb69edc 100644
--- a/models.py
+++ b/models.py
@@ -8,6 +8,19 @@ from pydantic import BaseModel, Field
from secp256k1 import PublicKey
+class RelayConfig(BaseModel):
+ is_paid_relay = Field(False, alias="isPaidRelay")
+ wallet = Field("")
+ cost_to_join = Field(0, alias="costToJoin")
+ free_storage = Field(0, alias="freeStorage")
+ storage_cost_per_kb = Field(0, alias="storageCostPerKb")
+ max_client_filters = Field(0, alias="maxClientFilters")
+ allowed_public_keys = Field([], alias="allowedPublicKeys")
+ blocked_public_keys = Field([], alias="blockedPublicKeys")
+
+ class Config:
+ allow_population_by_field_name = True
+
class NostrRelay(BaseModel):
id: str
name: str
@@ -16,7 +29,14 @@ class NostrRelay(BaseModel):
contact: Optional[str]
active: bool = False
- # meta: Optional[str]
+ config: "RelayConfig" = RelayConfig()
+
+
+ @classmethod
+ def from_row(cls, row: Row) -> "NostrRelay":
+ relay = cls(**dict(row))
+ relay.config = RelayConfig(**json.loads(row["meta"]))
+ return relay
@classmethod
def info(cls,) -> dict:
@@ -28,9 +48,6 @@ class NostrRelay(BaseModel):
}
- @classmethod
- def from_row(cls, row: Row) -> "NostrRelay":
- return cls(**dict(row))
diff --git a/static/components/relay-details/relay-details.html b/static/components/relay-details/relay-details.html
index ed42511..ad36d51 100644
--- a/static/components/relay-details/relay-details.html
+++ b/static/components/relay-details/relay-details.html
@@ -162,14 +162,14 @@