feat: update to v1.0.0 (#30)
This commit is contained in:
parent
2bdbbb274d
commit
73054fd5ce
20 changed files with 2029 additions and 2132 deletions
|
|
@ -154,7 +154,7 @@ class NostrClientConnection:
|
|||
NostrFilter(kinds=[e.kind], authors=[e.pubkey], until=e.created_at),
|
||||
)
|
||||
if not e.is_ephemeral_event:
|
||||
await create_event(self.relay_id, e, self.auth_pubkey)
|
||||
await create_event(e)
|
||||
await self._broadcast_event(e)
|
||||
|
||||
if e.is_delete_event:
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
import hashlib
|
||||
import json
|
||||
from enum import Enum
|
||||
from sqlite3 import Row
|
||||
from typing import List
|
||||
|
||||
from pydantic import BaseModel
|
||||
from secp256k1 import PublicKey
|
||||
|
|
@ -20,11 +18,11 @@ class NostrEvent(BaseModel):
|
|||
pubkey: str
|
||||
created_at: int
|
||||
kind: int
|
||||
tags: List[List[str]] = []
|
||||
tags: list[list[str]] = []
|
||||
content: str = ""
|
||||
sig: str
|
||||
|
||||
def serialize(self) -> List:
|
||||
def serialize(self) -> list:
|
||||
return [0, self.pubkey, self.created_at, self.kind, self.tags, self.content]
|
||||
|
||||
def serialize_json(self) -> str:
|
||||
|
|
@ -87,7 +85,7 @@ class NostrEvent(BaseModel):
|
|||
def serialize_response(self, subscription_id):
|
||||
return [NostrEventType.EVENT, subscription_id, dict(self)]
|
||||
|
||||
def tag_values(self, tag_name: str) -> List[str]:
|
||||
def tag_values(self, tag_name: str) -> list[str]:
|
||||
return [t[1] for t in self.tags if t[0] == tag_name]
|
||||
|
||||
def has_tag_value(self, tag_name: str, tag_value: str) -> bool:
|
||||
|
|
@ -95,7 +93,3 @@ class NostrEvent(BaseModel):
|
|||
|
||||
def is_direct_message_for_pubkey(self, pubkey: str) -> bool:
|
||||
return self.is_direct_message and self.has_tag_value("p", pubkey)
|
||||
|
||||
@classmethod
|
||||
def from_row(cls, row: Row) -> "NostrEvent":
|
||||
return cls(**dict(row))
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Any, List, Optional, Tuple
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
|
@ -6,11 +6,11 @@ from .event import NostrEvent
|
|||
|
||||
|
||||
class NostrFilter(BaseModel):
|
||||
e: List[str] = Field(default=[], alias="#e")
|
||||
p: List[str] = Field(default=[], alias="#p")
|
||||
ids: List[str] = []
|
||||
authors: List[str] = []
|
||||
kinds: List[int] = []
|
||||
e: list[str] = Field(default=[], alias="#e")
|
||||
p: list[str] = Field(default=[], alias="#p")
|
||||
ids: list[str] = []
|
||||
authors: list[str] = []
|
||||
kinds: list[int] = []
|
||||
subscription_id: Optional[str] = None
|
||||
since: Optional[int] = None
|
||||
until: Optional[int] = None
|
||||
|
|
@ -66,16 +66,13 @@ class NostrFilter(BaseModel):
|
|||
if not self.limit or self.limit > limit:
|
||||
self.limit = limit
|
||||
|
||||
def to_sql_components(
|
||||
self, relay_id: str
|
||||
) -> Tuple[List[str], List[str], List[Any]]:
|
||||
inner_joins: List[str] = []
|
||||
where = ["deleted=false", "nostrrelay.events.relay_id = ?"]
|
||||
values: List[Any] = [relay_id]
|
||||
def to_sql_components(self, relay_id: str) -> tuple[list[str], list[str], dict]:
|
||||
inner_joins: list[str] = []
|
||||
where = ["deleted=false", "nostrrelay.events.relay_id = :relay_id"]
|
||||
values: dict = {"relay_id": relay_id}
|
||||
|
||||
if len(self.e):
|
||||
values += self.e
|
||||
e_s = ",".join(["?"] * len(self.e))
|
||||
e_s = ",".join([f"'{e}'" for e in self.e])
|
||||
inner_joins.append(
|
||||
"INNER JOIN nostrrelay.event_tags e_tags "
|
||||
"ON nostrrelay.events.id = e_tags.event_id"
|
||||
|
|
@ -83,8 +80,7 @@ class NostrFilter(BaseModel):
|
|||
where.append(f" (e_tags.value in ({e_s}) AND e_tags.name = 'e')")
|
||||
|
||||
if len(self.p):
|
||||
values += self.p
|
||||
p_s = ",".join(["?"] * len(self.p))
|
||||
p_s = ",".join([f"'{p}'" for p in self.p])
|
||||
inner_joins.append(
|
||||
"INNER JOIN nostrrelay.event_tags p_tags "
|
||||
"ON nostrrelay.events.id = p_tags.event_id"
|
||||
|
|
@ -92,26 +88,23 @@ class NostrFilter(BaseModel):
|
|||
where.append(f" p_tags.value in ({p_s}) AND p_tags.name = 'p'")
|
||||
|
||||
if len(self.ids) != 0:
|
||||
ids = ",".join(["?"] * len(self.ids))
|
||||
ids = ",".join([f"'{_id}'" for _id in self.ids])
|
||||
where.append(f"id IN ({ids})")
|
||||
values += self.ids
|
||||
|
||||
if len(self.authors) != 0:
|
||||
authors = ",".join(["?"] * len(self.authors))
|
||||
authors = ",".join([f"'{author}'" for author in self.authors])
|
||||
where.append(f"pubkey IN ({authors})")
|
||||
values += self.authors
|
||||
|
||||
if len(self.kinds) != 0:
|
||||
kinds = ",".join(["?"] * len(self.kinds))
|
||||
kinds = ",".join([f"'{kind}'" for kind in self.kinds])
|
||||
where.append(f"kind IN ({kinds})")
|
||||
values += self.kinds
|
||||
|
||||
if self.since:
|
||||
where.append("created_at >= ?")
|
||||
values += [self.since]
|
||||
where.append("created_at >= :since")
|
||||
values["since"] = self.since
|
||||
|
||||
if self.until:
|
||||
where.append("created_at < ?")
|
||||
values += [self.until]
|
||||
where.append("created_at < :until")
|
||||
values["until"] = self.until
|
||||
|
||||
return inner_joins, where, values
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import json
|
||||
from sqlite3 import Row
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
|
@ -102,23 +100,17 @@ class RelaySpec(RelayPublicSpec, WalletSpec, AuthSpec):
|
|||
|
||||
class NostrRelay(BaseModel):
|
||||
id: str
|
||||
user_id: Optional[str] = None
|
||||
name: str
|
||||
description: Optional[str]
|
||||
pubkey: Optional[str]
|
||||
contact: Optional[str]
|
||||
description: Optional[str] = None
|
||||
pubkey: Optional[str] = None
|
||||
contact: Optional[str] = None
|
||||
active: bool = False
|
||||
|
||||
config = RelaySpec()
|
||||
meta: RelaySpec = RelaySpec()
|
||||
|
||||
@property
|
||||
def is_free_to_join(self):
|
||||
return not self.config.is_paid_relay or self.config.cost_to_join == 0
|
||||
|
||||
@classmethod
|
||||
def from_row(cls, row: Row) -> "NostrRelay":
|
||||
relay = cls(**dict(row))
|
||||
relay.config = RelaySpec(**json.loads(row["meta"]))
|
||||
return relay
|
||||
return not self.meta.is_paid_relay or self.meta.cost_to_join == 0
|
||||
|
||||
@classmethod
|
||||
def info(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue