poanetwork / ex_abi

The Ethereum ABI Interface
GNU General Public License v3.0
61 stars 43 forks source link

Issue decoding Seaport Zone getSeaportMetadata #131

Closed Hajto closed 1 year ago

Hajto commented 1 year ago
data = "0x000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000008546573745a6f6e6500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000100794b048e2bcbab215c7b626b47c0b97d0c78b2a3ca9da47d2b3094ae99b0cb37000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000"

abi = %{
      "getSeaportMetadata" => %{
        "inputs" => [],
        "name" => "getSeaportMetadata",
        "outputs" => [
          %{"internalType" => "string", "name" => "name", "type" => "string"},
          %{
            "components" => [
              %{
                "internalType" => "uint256",
                "name" => "id",
                "type" => "uint256"
              },
              %{
                "internalType" => "bytes",
                "name" => "metadata",
                "type" => "bytes"
              }
            ],
            "internalType" => "struct Schema[]",
            "name" => "schemas",
            "type" => "tuple[]"
          }
        ],
        "stateMutability" => "view",
        "type" => "function"
      }
    }

method_name = "getSeaportMetadata"

ExW3.Abi.decode_output(abi, method_name, data)

Library version: 0.6.0

** (MatchError) no match of right hand side value: <<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...>>
    (ex_abi 0.6.0) lib/abi/type_decoder.ex:238: ABI.TypeDecoder.decode_bytes/4
    (ex_abi 0.6.0) lib/abi/type_decoder.ex:327: anonymous fn/3 in ABI.TypeDecoder.decode_type/3
    (elixir 1.14.4) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
    (ex_abi 0.6.0) lib/abi/type_decoder.ex:325: ABI.TypeDecoder.decode_type/3
    (ex_abi 0.6.0) lib/abi/type_decoder.ex:188: anonymous fn/3 in ABI.TypeDecoder.do_decode_raw/2
    (elixir 1.14.4) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
    (ex_abi 0.6.0) lib/abi/type_decoder.ex:185: ABI.TypeDecoder.do_decode_raw/2
    (ex_abi 0.6.0) lib/abi/type_decoder.ex:179: ABI.TypeDecoder.decode_raw/2
    (exw3 0.6.1) lib/exw3/abi.ex:52: ExW3.Abi.decode_output/3
    (hawku 0.1.0) lib/hawku/blockchain/ethereum/queries/blockchain_queries.ex:325: Hawku.Blockchain.Ethereum.Queries.ExW3Impl.call_eth_chain/5
    iex:5: (file)
Hajto commented 1 year ago
iex(9)> ABI.parse_specification([
...(9)> %{
...(9)>         "inputs" => [],
...(9)>         "name" => "getSeaportMetadata",
...(9)>         "outputs" => [
...(9)>           %{"internalType" => "string", "name" => "name", "type" => "string"},
...(9)>           %{
...(9)>             "components" => [
...(9)>               %{
...(9)>                 "internalType" => "uint256",
...(9)>                 "name" => "id",
...(9)>                 "type" => "uint256"
...(9)>               },
...(9)>               %{
...(9)>                 "internalType" => "bytes",
...(9)>                 "name" => "metadata",
...(9)>                 "type" => "bytes"
...(9)>               }
...(9)>             ],
...(9)>             "internalType" => "struct Schema[]",
...(9)>             "name" => "schemas",
...(9)>             "type" => "tuple[]"
...(9)>           }
...(9)>         ],
...(9)>         "stateMutability" => "view",
...(9)>         "type" => "function"
...(9)>       }
...(9)>       ]
...(9)> )
[
  %ABI.FunctionSelector{
    function: "getSeaportMetadata",
    method_id: <<46, 119, 142, 252>>,
    type: :function,
    inputs_indexed: nil,
    state_mutability: :view,
    input_names: [],
    types: [],
    returns: [:string, {:array, {:tuple, [{:uint, 256}, :bytes]}}]
  }
]
iex(16)> data                                                                                                                           
<<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,                                                         
  0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,                                                        
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 84, 101, 115, 116,
  90, 111, 110, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 1, 0, 121, 75, 4, 142, 43, 203, 171, 33, 92, 123, 98, 107,
  71, 192, 185, 125, 12, 120, 178, 163, 202, 157, 164, 125, 43, 48, 148, 174,
  153, 176, 203, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 160, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>>
iex(17)> sig
%ABI.FunctionSelector{
  function: "getSeaportMetadata",
  method_id: <<46, 119, 142, 252>>,
  type: :function,
  inputs_indexed: nil,
  state_mutability: :view,
  input_names: [],
  types: [],
  returns: [:string, {:array, {:tuple, [{:uint, 256}, :bytes]}}]
}
iex(18)> ABI.decode(sig, data)
** (MatchError) no match of right hand side value: {:ok, <<0, 0, 0, 0>>, <<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...>>}
    (ex_abi 0.6.0) lib/abi/type_decoder.ex:143: ABI.TypeDecoder.decode/3
    iex:18: (file)
atapin commented 1 year ago

@Hajto worked for me if I specify 3rd param as :output, e.g.

iex(13)> ABI.decode(abi |> Enum.at(0), data, :output)
[
  "TestZone",
  [
    {7,
     <<121, 75, 4, 142, 43, 203, 171, 33, 92, 123, 98, 107, 71, 192, 185, 125,
       12, 120, 178, 163, 202, 157, 164, 125, 43, 48, 148, 174, 153, 176, 203,
       55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...>>}
  ]
]
ayrat555 commented 1 year ago

@atapin. thank you