ABI.TypeDecoder.decode
You're seeing just the function
decode
, go back to ABI.TypeDecoder module for more information.
Link to this function
decode(encoded_data, selector_or_types, data_type \\ :input)
Decodes the given data based on the function selector.
Note, we don't currently try to guess the function name?
Examples
iex> "00000000000000000000000000000000000000000000000000000000000000450000000000000000000000000000000000000000000000000000000000000001"
...> |> Base.decode16!(case: :lower)
...> |> ABI.TypeDecoder.decode(
...> %ABI.FunctionSelector{
...> function: "baz",
...> types: [
...> {:uint, 32},
...> :bool
...> ],
...> returns: [:bool]
...> }
...> )
[69, true]
iex> "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd6"
...> |> Base.decode16!(case: :lower)
...> |> ABI.TypeDecoder.decode(
...> %ABI.FunctionSelector{
...> function: "baz",
...> types: [
...> {:int, 8}
...> ],
...> returns: [:int]
...> }
...> )
[-42]
iex> ABI.TypeEncoder.encode(["hello world"],[:string])
...> |> ABI.TypeDecoder.decode(
...> %ABI.FunctionSelector{
...> function: nil,
...> types: [
...> :string
...> ]
...> }
...> )
["hello world"]
iex> "00000000000000000000000000000000000000000000000000000000000000110000000000000000000000000000000000000000000000000000000000000001"
...> |> Base.decode16!(case: :lower)
...> |> ABI.TypeDecoder.decode(
...> %ABI.FunctionSelector{
...> function: nil,
...> types: [
...> {:tuple, [{:uint, 32}, :bool]}
...> ]
...> }
...> )
[{17, true}]
iex> ABI.TypeEncoder.encode([[17,1]],[{:array,{:uint,32}}])
...> |> ABI.TypeDecoder.decode(
...> %ABI.FunctionSelector{
...> function: nil,
...> types: [
...> {:array, {:uint, 32}}
...> ]
...> }
...> )
[[17, 1]]
iex> ABI.TypeEncoder.encode([[17, 1], true, <<16, 32>>], [{:array, {:uint, 32}},:bool,{:bytes, 2}])
...> |> ABI.TypeDecoder.decode(
...> %ABI.FunctionSelector{
...> function: nil,
...> types: [
...> {:array, {:uint, 32}},
...> :bool,
...> {:bytes, 2}
...> ]
...> }
...> )
[[17, 1], true, <<16, 32>>]
iex> ABI.TypeEncoder.encode([{"awesome", true}], [{:tuple, [:string, :bool]}])
...> |> ABI.TypeDecoder.decode(
...> %ABI.FunctionSelector{
...> function: nil,
...> types: [
...> {:tuple, [:string, :bool]}
...> ]
...> }
...> )
[{"awesome", true}]
iex> ABI.TypeEncoder.encode([{[]}],[{:tuple, [{:array, :address}]}])
...> |> ABI.TypeDecoder.decode(
...> %ABI.FunctionSelector{
...> function: nil,
...> types: [
...> {:tuple, [{:array, :address}]}
...> ]
...> }
...> )
[{[]}]
iex> ABI.TypeEncoder.encode( [{
...> "Unauthorized",
...> [
...> 184341788326688649239867304918349890235378717380,
...> 765664983403968947098136133435535343021479462042,
...> ]
...> }], [{:tuple,[:string, {:array, {:uint, 256}}]}])
...> |> ABI.TypeDecoder.decode(
...> %ABI.FunctionSelector{
...> function: nil,
...> types: [{:tuple,[
...> :string,
...> {:array, {:uint, 256}}
...> ]}]
...> }
...> )
[{
"Unauthorized",
[
184341788326688649239867304918349890235378717380,
765664983403968947098136133435535343021479462042,
]
}]