[fix] Ws api tests (#31)
This commit is contained in:
parent
73054fd5ce
commit
3dc066fbd4
12 changed files with 108 additions and 44 deletions
|
|
@ -103,8 +103,16 @@ class NostrClientConnection:
|
|||
return []
|
||||
|
||||
message_type = data[0]
|
||||
|
||||
if message_type == NostrEventType.EVENT:
|
||||
await self._handle_event(NostrEvent.parse_obj(data[1]))
|
||||
event_dict = {
|
||||
"relay_id": self.relay_id,
|
||||
"publisher": data[1]["pubkey"],
|
||||
**data[1],
|
||||
}
|
||||
|
||||
event = NostrEvent(**event_dict)
|
||||
await self._handle_event(event)
|
||||
return []
|
||||
if message_type == NostrEventType.REQ:
|
||||
if len(data) != 3:
|
||||
|
|
@ -146,7 +154,6 @@ class NostrClientConnection:
|
|||
resp_nip20 += [valid, message]
|
||||
await self._send_msg(resp_nip20)
|
||||
return None
|
||||
|
||||
try:
|
||||
if e.is_replaceable_event:
|
||||
await delete_events(
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import hashlib
|
|||
import json
|
||||
from enum import Enum
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
from secp256k1 import PublicKey
|
||||
|
||||
|
||||
|
|
@ -15,13 +15,21 @@ class NostrEventType(str, Enum):
|
|||
|
||||
class NostrEvent(BaseModel):
|
||||
id: str
|
||||
relay_id: str
|
||||
publisher: str
|
||||
pubkey: str
|
||||
created_at: int
|
||||
kind: int
|
||||
tags: list[list[str]] = []
|
||||
tags: list[list[str]] = Field(default=[], no_database=True)
|
||||
content: str = ""
|
||||
sig: str
|
||||
|
||||
def nostr_dict(self) -> dict:
|
||||
_nostr_dict = dict(self)
|
||||
_nostr_dict.pop("relay_id")
|
||||
_nostr_dict.pop("publisher")
|
||||
return _nostr_dict
|
||||
|
||||
def serialize(self) -> list:
|
||||
return [0, self.pubkey, self.created_at, self.kind, self.tags, self.content]
|
||||
|
||||
|
|
@ -36,7 +44,7 @@ class NostrEvent(BaseModel):
|
|||
|
||||
@property
|
||||
def size_bytes(self) -> int:
|
||||
s = json.dumps(dict(self), separators=(",", ":"), ensure_ascii=False)
|
||||
s = json.dumps(self.nostr_dict(), separators=(",", ":"), ensure_ascii=False)
|
||||
return len(s.encode())
|
||||
|
||||
@property
|
||||
|
|
@ -83,7 +91,7 @@ class NostrEvent(BaseModel):
|
|||
raise ValueError(f"Invalid signature: '{self.sig}' for event '{self.id}'")
|
||||
|
||||
def serialize_response(self, subscription_id):
|
||||
return [NostrEventType.EVENT, subscription_id, dict(self)]
|
||||
return [NostrEventType.EVENT, subscription_id, self.nostr_dict()]
|
||||
|
||||
def tag_values(self, tag_name: str) -> list[str]:
|
||||
return [t[1] for t in self.tags if t[0] == tag_name]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue