W3WS.Util (w3ws v0.3.0)
Utility functions
Summary
Functions
Try to decode the event with the given ABI and apply the handler. The handler is always called, even if the event could not be decoded.
Convert a hex string to a binary
Convert a hex string to an integer
Calculate the keccak256 hash of a binary, optionally encoding as hex
Try to decode an event if an ABI is present
Resolve the ABI from the given options
Convert a binary to hex
Functions
decode_apply(env, abi, handler, handler_state)
@spec decode_apply(W3WS.Env.t(), W3WS.ABI.t() | nil, W3WS.Handler.t(), any()) :: pid() | {pid(), reference()}
Try to decode the event with the given ABI and apply the handler. The handler is always called, even if the event could not be decoded.
from_hex(hex)
Convert a hex string to a binary
Examples
iex> from_hex("0x010203")
<<1, 2, 3>>
iex> from_hex("0x")
""
iex> from_hex("")
""
integer_from_hex(arg)
Convert a hex string to an integer
Examples
iex> integer_from_hex("0x7")
7
keccak(binary, opts \\ [])
Calculate the keccak256 hash of a binary, optionally encoding as hex
Examples
iex> keccak("foo", hex?: true)
"0x41b1a0649752af1b28b3dc29a1556eee781e4a4c3a1f7f53f90fa834de098c4d"
maybe_decode_event(env, abi)
@spec maybe_decode_event(W3WS.Env.t(), W3WS.ABI.t() | nil) :: W3WS.Env.t()
Try to decode an event if an ABI is present
resolve_abi(opts)
Resolve the ABI from the given options
Examples
iex> resolve_abi(abi: [])
[]
iex> resolve_abi(abi: nil)
nil
iex> resolve_abi(abi: [], abi_files: ["./test/support/files/test_abi.json"])
[
%ABI.FunctionSelector{
function: "Transfer",
method_id: <<221, 242, 82, 173>>,
type: :event,
inputs_indexed: [false, false, false],
state_mutability: nil,
input_names: ["from", "to", "value"],
types: [:address, :address, {:uint, 256}],
returns: [],
return_names: []
}
]
to_hex(int)
Convert a binary to hex
Examples
iex> to_hex(<<1, 2, 3>>)
"0x010203"
iex> to_hex(1)
"0x1"