diff --git a/nostr/relay.py b/nostr/relay.py index ac6c9f6..bc75e25 100644 --- a/nostr/relay.py +++ b/nostr/relay.py @@ -12,6 +12,12 @@ class RelayPolicy: self.should_read = should_read self.should_write = should_write + def to_json_object(self) -> dict[str, bool]: + return { + "read": self.should_read, + "write": self.should_write + } + class Relay: def __init__( self, @@ -61,6 +67,13 @@ class Relay: return None + def to_json_object(self) -> dict: + return { + "url": self.url, + "policy": self.policy.to_json_object(), + "subscriptions": [subscription.to_json_object() for subscription in self.subscriptions.values()] + } + def _is_valid_message(self, message: str) -> bool: if not message or message[0] != '[' or message[-1] != ']': return False diff --git a/nostr/subscription.py b/nostr/subscription.py index 4d3814e..7afba20 100644 --- a/nostr/subscription.py +++ b/nostr/subscription.py @@ -4,3 +4,9 @@ class Subscription: def __init__(self, id: str, filters: Filters=None) -> None: self.id = id self.filters = filters + + def to_json_object(self): + return { + "id": self.id, + "filters": self.filters.to_json_array() + }