View Source Yggdrasil.Subscriber.Adapter.Icon (ICON 2.0 SDK v0.2.3)

Yggdrasil publisher adapter for Icon. The name of the channel should be a map with:

  • :source - Either :block or :event (required).
  • :identity - Icon.RPC.Identity instance pointed to the right network.
  • :data - Data for the subscription.
  • :from_height - Height to start receiving messages. Defaults to :latest.

Important: We need to be careful when using from_height in the channel because Yggdrasil will restart the synchronization process from the chosen height if the process crashes.

e.g. given a proper channel name, then we can subscribe to ICON 2.0 :block websocket:

iex(1)> Yggdrasil.subscribe(name: %{source: :block}, adapter: :icon)
:ok
iex(4)> flush()
{:Y_CONNECTED, %Yggdrasil.Channel{name: %{source: :block}, (...)}}

after that, we'll start receiving messages like the following:

iex(6)> flush()
{:Y_EVENT, %Yggdrasil.Channel{name: %{source: :block}, (...)}, %Yggdrasil.Icon.Block{hash: "0x...", (...)}}

Finally, when we're done, we can unsubscribe from the channel:

iex(7)> Yggdrasil.unsubscribe(name: %{source: :block}, adapter: :icon)
:ok
iex(8)> flush()
{:Y_DISCONNECTED, %Yggdrasil.Channel{name: %{source: :block}, (...)}}

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Informs the subscriber process that the websocket is connected.

Informs the subscriber process that the websocket is disconnected.

Informs the subscriber of a new frame.

Informs the subscriber of a new height.

Starts Elixir.Yggdrasil.Subscriber.Adapter.Icon with a channel and optional options.

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

send_connected(subscriber)

View Source
@spec send_connected(GenServer.server()) :: :ok

Informs the subscriber process that the websocket is connected.

Link to this function

send_disconnected(subscriber, reason)

View Source
@spec send_disconnected(GenServer.server(), term()) :: :ok

Informs the subscriber process that the websocket is disconnected.

Link to this function

send_frame(subscriber, frame)

View Source
@spec send_frame(GenServer.server(), term()) :: :ok

Informs the subscriber of a new frame.

Link to this function

send_height(subscriber, height)

View Source
@spec send_height(GenServer.server(), pos_integer()) :: :ok

Informs the subscriber of a new height.

Link to this function

start_link(channel, options \\ [])

View Source

Starts Elixir.Yggdrasil.Subscriber.Adapter.Icon with a channel and optional options.

Link to this function

stop(subscriber, reason \\ :normal, timeout \\ :infinity)

View Source
@spec stop(GenServer.server(), term(), :infinity | non_neg_integer()) :: :ok

See GenServer.stop/3.