Skip to content

event_relay

event_relay

Junction model linking an Event to the Relay where it was observed.

Maps to the event_relay table in the database, recording which relay an event was received from and when it was first seen there. The database uses the event_relay_insert_cascade stored procedure to atomically insert the relay, event, and junction record in a single call.

See Also

bigbrotr.models.event: The Event model wrapped by this junction. bigbrotr.models.relay: The Relay model wrapped by this junction. bigbrotr.models.relay_metadata: Analogous junction model linking a Relay to a Metadata record.

Classes

EventRelayDbParams

Bases: NamedTuple

Positional parameters for the event-relay junction insert procedure.

Combines fields from the Event, Relay, and the junction timestamp into a single flat tuple for the event_relay_insert_cascade stored procedure.

Attributes:

  • event_id (bytes) –

    Event ID as 32-byte binary (from EventDbParams).

  • pubkey (bytes) –

    Author public key as 32-byte binary.

  • created_at (int) –

    Unix timestamp of event creation.

  • kind (int) –

    Integer event kind.

  • tags (str) –

    JSON-encoded array of tag arrays.

  • content (str) –

    Raw event content string.

  • sig (bytes) –

    Schnorr signature as 64-byte binary.

  • relay_url (str) –

    Fully normalized relay WebSocket URL (from RelayDbParams).

  • relay_network (str) –

    Network type string (e.g., "clearnet", "tor").

  • relay_discovered_at (int) –

    Unix timestamp of relay discovery.

  • seen_at (int) –

    Unix timestamp when the event was first observed on this relay.

See Also

EventRelay: The model that produces these parameters. EventDbParams: Source of the event fields. RelayDbParams: Source of the relay fields.

EventRelay dataclass

EventRelay(
    event: Event,
    relay: Relay,
    seen_at: int = (lambda: int(time()))(),
)

Immutable record of an Event observed on a specific Relay.

Attributes:

  • event (Event) –

    The Nostr Event that was observed.

  • relay (Relay) –

    The Relay where the event was seen.

  • seen_at (int) –

    Unix timestamp of when the event was first seen (defaults to now).

Examples:

event_relay = EventRelay(event=event, relay=relay)
event_relay.seen_at       # Auto-set to current time
params = event_relay.to_db_params()
params.relay_url          # 'wss://relay.damus.io'
params.event_id           # Binary event ID (bytes)
Note

The flat EventRelayDbParams tuple is designed for the event_relay_insert_cascade stored procedure, which atomically inserts the relay, event, and junction record. This avoids multiple round-trips and ensures referential integrity.

See Also

Event: The event half of this junction. Relay: The relay half of this junction. EventRelayDbParams: Database parameter container produced by to_db_params(). RelayMetadata: Analogous junction model for relay-to-metadata associations.

Functions
to_db_params
to_db_params() -> EventRelayDbParams

Return cached database parameters computed during initialization.

Returns:

Source code in src/bigbrotr/models/event_relay.py
def to_db_params(self) -> EventRelayDbParams:
    """Return cached database parameters computed during initialization.

    Returns:
        [EventRelayDbParams][bigbrotr.models.event_relay.EventRelayDbParams]
        combining event, relay, and junction fields.
    """
    return self._db_params

Functions