W3WS.Env (w3ws v0.2.0)
W3WS Envelope
Summary
Functions
Create an envelope from an eth_subscription response
Create an envelope from a log, like those returned by eth_getLogs
Adds a decoded event to the envelope and sets decoded?: true
if
the event is decoded.
Types
@type t() :: %W3WS.Env{ context: map(), decoded?: boolean(), event: W3WS.Event.t() | nil, jsonrpc: String.t() | nil, method: String.t() | nil, raw: W3WS.RawEvent.t(), subscription: String.t() | nil }
Functions
Link to this function
from_eth_subscription(map, context)
Create an envelope from an eth_subscription response
Examples
iex> from_eth_subscription(
...> %{
...> "jsonrpc" => "2.0",
...> "method" => "eth_subscription",
...> "params" => %{
...> "subscription" => "0x9",
...> "result" => %{
...> "address" => "0xAddress",
...> "blockHash" => "0xBlockHash",
...> "blockNumber" => "0x1",
...> "data" => "0xData",
...> "logIndex" => "0x0",
...> "removed" => false,
...> "topics" => ["0xTopic"],
...> "transactionHash" => "0xTransactionHash",
...> "transactionIndex" => "0x2"
...> }
...> }
...> },
...> %{chain_id: 1}
...> )
%W3WS.Env{
context: %{chain_id: 1},
decoded?: false,
event: nil,
jsonrpc: "2.0",
method: "eth_subscription",
raw: %W3WS.RawEvent{
address: "0xAddress",
block_hash: "0xBlockHash",
block_number: "0x1",
data: "0xData",
log_index: "0x0",
removed: false,
topics: ["0xTopic"],
transaction_hash: "0xTransactionHash",
transaction_index: "0x2"
},
subscription: "0x9"
}
Link to this function
from_log(log, context)
Create an envelope from a log, like those returned by eth_getLogs
Examples
iex> from_log(%{
...> "address" => "0xAddress",
...> "blockHash" => "0xBlockHash",
...> "blockNumber" => "0x1",
...> "data" => "0xData",
...> "logIndex" => "0x0",
...> "removed" => false,
...> "topics" => ["0xTopic"],
...> "transactionHash" => "0xTransactionHash",
...> "transactionIndex" => "0x2"
...> }, %{chain_id: 1})
%W3WS.Env{
context: %{chain_id: 1},
decoded?: false,
event: nil,
jsonrpc: nil,
method: nil,
raw: %W3WS.RawEvent{
address: "0xAddress",
block_hash: "0xBlockHash",
block_number: "0x1",
data: "0xData",
log_index: "0x0",
removed: false,
topics: ["0xTopic"],
transaction_hash: "0xTransactionHash",
transaction_index: "0x2"
},
subscription: nil
}
Link to this function
with_event(env, event)
@spec with_event(t(), W3WS.Event.t()) :: t()
Adds a decoded event to the envelope and sets decoded?: true
if
the event is decoded.
Examples
iex> with_event(%W3WS.Env{}, %W3WS.Event{data: nil})
%W3WS.Env{
decoded?: false,
event: %W3WS.Event{data: nil}
}
iex> with_event(%W3WS.Env{}, %W3WS.Event{data: %{}})
%W3WS.Env{
decoded?: true,
event: %W3WS.Event{data: %{}}
}