Rujira.Events (rujira_ex v0.0.1)

Copy Markdown View Source

Generic event parser for all Rujira events.

Takes a raw event, creates a default Event struct, then routes it to the correct protocol parser. Each protocol returns an envelope struct so consumers can match at protocol, type, or field level.

Usage

case Rujira.Events.parse(raw_event) do
  # Match all FIN events
  {:ok, %Rujira.Fin.Events.Event{} = e} -> handle_fin(e)

  # Match a specific FIN event by inner struct
  {:ok, %Rujira.Fin.Events.Event{data: %Rujira.Fin.Events.Trade{} = trade}} -> ...

  # Match all Thorchain events
  {:ok, %Rujira.Thorchain.Events.Event{} = e} -> handle_tc(e)

  # Unrecognized protocol
  {:ok, %Rujira.Events.Event{} = event} -> handle_unknown(event)
end

Summary

Functions

Casts a raw BlockEvent protobuf struct into the standard %{type: String.t(), attributes: map()} format.

Parses a raw event into a typed struct from the matching protocol.

Functions

cast(block_event)

@spec cast(Thorchain.Types.BlockEvent.t()) :: %{type: String.t(), attributes: map()}

Casts a raw BlockEvent protobuf struct into the standard %{type: String.t(), attributes: map()} format.

parse(event)

@spec parse(map() | Thorchain.Types.BlockEvent.t()) ::
  {:ok,
   Rujira.Fin.Events.Event.t()
   | Rujira.Thorchain.Events.Event.t()
   | Rujira.Events.Event.t()}
  | {:error, term()}

Parses a raw event into a typed struct from the matching protocol.

Accepts:

  • %{type: String.t(), attributes: map()} — already cast
  • %BlockEvent{} — raw protobuf, cast first

Returns {:ok, struct} for known events or {:ok, %Event{}} for unrecognized events so consumers never lose data.