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 becauseYggdrasil
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
.
@spec send_connected(GenServer.server()) :: :ok
Informs the subscriber
process that the websocket is connected.
@spec send_disconnected(GenServer.server(), term()) :: :ok
Informs the subscriber
process that the websocket is disconnected.
@spec send_frame(GenServer.server(), term()) :: :ok
Informs the subscriber
of a new frame
.
@spec send_height(GenServer.server(), pos_integer()) :: :ok
Informs the subscriber
of a new height
.
@spec start_link(Yggdrasil.Channel.t(), GenServer.options()) :: GenServer.on_start()
Starts Elixir.Yggdrasil.Subscriber.Adapter.Icon with a channel
and optional options
.
@spec stop(GenServer.server(), term(), :infinity | non_neg_integer()) :: :ok
See GenServer.stop/3
.