Merge pull request #3053 from poanetwork/ex_abi_update

Migrate to ex_abi 0.3.0
pull/3061/head
Victor Baranov 5 years ago committed by GitHub
commit 9a648e0086
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 2
      apps/block_scout_web/lib/block_scout_web/templates/smart_contract/_functions.html.eex
  3. 10
      apps/block_scout_web/lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex
  4. 2
      apps/block_scout_web/lib/block_scout_web/views/address_contract_view.ex
  5. 10
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/encoder.ex
  6. 2
      apps/ethereum_jsonrpc/mix.exs
  7. 11
      apps/explorer/lib/explorer/smart_contract/reader.ex
  8. 64
      apps/explorer/test/explorer/validator/metadata_retriever_test.exs
  9. 2
      mix.lock

@ -3,6 +3,7 @@
### Features ### Features
### Fixes ### Fixes
- [#3053](https://github.com/poanetwork/blockscout/pull/3053) - Fix ABI decoding in contracts methods, logs (migrate to ex_abi 0.3.0)
- [#3044](https://github.com/poanetwork/blockscout/pull/3044) - Prevent division by zero on /accounts page - [#3044](https://github.com/poanetwork/blockscout/pull/3044) - Prevent division by zero on /accounts page
- [#3043](https://github.com/poanetwork/blockscout/pull/3043) - Extract host name for split couple of indexer and web app - [#3043](https://github.com/poanetwork/blockscout/pull/3043) - Extract host name for split couple of indexer and web app
- [#3042](https://github.com/poanetwork/blockscout/pull/3042) - Speedup pending txs list query - [#3042](https://github.com/poanetwork/blockscout/pull/3042) - Speedup pending txs list query

@ -9,7 +9,7 @@
</div> </div>
<%= if queryable?(function["inputs"]) do %> <%= if queryable?(function["inputs"]) do %>
<div> <div style="width: 100%; overflow: hidden;">
<form class="form-inline" data-function-form data-url="<%= smart_contract_path(@conn, :show, @address.hash) %>"> <form class="form-inline" data-function-form data-url="<%= smart_contract_path(@conn, :show, @address.hash) %>">
<input type="hidden" name="function_name" value='<%= function["name"] %>' /> <input type="hidden" name="function_name" value='<%= function["name"] %>' />

@ -13,11 +13,11 @@
<%= unless Enum.empty?(@mapping) do %> <%= unless Enum.empty?(@mapping) do %>
<div class="table-responsive text-center"> <div class="table-responsive text-center">
<table style="color: black;" summary="<%= gettext "Transaction Inputs" %>" class="table thead-light table-bordered"> <table style="color: black; table-layout: fixed;" summary="<%= gettext "Transaction Inputs" %>" class="table thead-light table-bordered">
<tr> <tr>
<th scope="col"></th> <th scope="col" style="width: 60px;"></th>
<th scope="col"><%= gettext "Name" %></th> <th scope="col" style="width: 10%;"><%= gettext "Name" %></th>
<th scope="col"><%= gettext "Type" %></th> <th scope="col" style="width: 10%;"><%= gettext "Type" %></th>
<th scope="col"><%= gettext "Data" %></th> <th scope="col"><%= gettext "Data" %></th>
<tr> <tr>
<%= for {name, type, value} <- @mapping do %> <%= for {name, type, value} <- @mapping do %>
@ -49,7 +49,7 @@
<%= gettext "Error rendering value" %> <%= gettext "Error rendering value" %>
</div> </div>
<% value -> %> <% value -> %>
<pre class="transaction-input-text tile"><code><%= value %></code></pre> <pre class="transaction-input-text tile pre-wrap"><code><%= value %></code></pre>
<% end %> <% end %>
</td> </td>
</tr> </tr>

@ -33,7 +33,7 @@ defmodule BlockScoutWeb.AddressContractView do
|> Enum.zip(constructor_abi["inputs"]) |> Enum.zip(constructor_abi["inputs"])
|> Enum.reduce({0, "#{contract.constructor_arguments}\n\n"}, fn {val, %{"type" => type}}, {count, acc} -> |> Enum.reduce({0, "#{contract.constructor_arguments}\n\n"}, fn {val, %{"type" => type}}, {count, acc} ->
formatted_val = formatted_val =
if is_binary(val) do if type =~ "address" || type =~ "bytes" do
Base.encode16(val, case: :lower) Base.encode16(val, case: :lower)
else else
val val

@ -58,6 +58,16 @@ defmodule EthereumJSONRPC.Encoder do
end) end)
end end
def decode_result(result, %{returns: r} = fs) when r in [:string, [:string]] do
case decode_result(result, %{fs | returns: {:tuple, [:string]}}) do
{id, {:ok, [{string}]}} ->
{id, {:ok, [string]}}
error ->
error
end
end
def decode_result(%{id: id, result: result}, function_selector) do def decode_result(%{id: id, result: result}, function_selector) do
types_list = List.wrap(function_selector.returns) types_list = List.wrap(function_selector.returns)

@ -84,7 +84,7 @@ defmodule EthereumJsonrpc.MixProject do
# Convert unix timestamps in JSONRPC to DateTimes # Convert unix timestamps in JSONRPC to DateTimes
{:timex, "~> 3.6"}, {:timex, "~> 3.6"},
# Encode/decode function names and arguments # Encode/decode function names and arguments
{:ex_abi, "~> 0.1.18"}, {:ex_abi, [git: "https://github.com/poanetwork/ex_abi.git", branch: "master"]},
# `:verify_fun` for `Socket.Web.connect` # `:verify_fun` for `Socket.Web.connect`
{:ssl_verify_fun, "~> 1.1"}, {:ssl_verify_fun, "~> 1.1"},
# `EthereumJSONRPC.WebSocket` # `EthereumJSONRPC.WebSocket`

@ -262,7 +262,8 @@ defmodule Explorer.SmartContract.Reader do
end end
def link_outputs_and_values(blockchain_values, outputs, function_name) do def link_outputs_and_values(blockchain_values, outputs, function_name) do
{_, value} = Map.get(blockchain_values, function_name, {:ok, [""]}) default_value = Enum.map(outputs, fn _ -> "" end)
{_, value} = Map.get(blockchain_values, function_name, {:ok, default_value})
for {output, index} <- Enum.with_index(outputs) do for {output, index} <- Enum.with_index(outputs) do
new_value(output, List.wrap(value), index) new_value(output, List.wrap(value), index)
@ -273,8 +274,12 @@ defmodule Explorer.SmartContract.Reader do
Map.put_new(output, "value", bytes_to_string(value)) Map.put_new(output, "value", bytes_to_string(value))
end end
defp new_value(%{"type" => "bytes" <> _number} = output, [value], _index) do defp new_value(%{"type" => "bytes" <> _number} = output, values, index) do
Map.put_new(output, "value", bytes_to_string(value)) Map.put_new(output, "value", bytes_to_string(Enum.at(values, index)))
end
defp new_value(%{"type" => "bytes"} = output, values, index) do
Map.put_new(output, "value", bytes_to_string(Enum.at(values, index)))
end end
defp new_value(output, [value], _index) do defp new_value(output, [value], _index) do

@ -8,9 +8,33 @@ defmodule Explorer.Validator.MetadataRetrieverTest do
setup :set_mox_global setup :set_mox_global
describe "fetch_data/0" do describe "fetch_data/0" do
test "returns maps with the info on validator if they are alone in the list" do
single_validator_in_list_mox_ok()
validator_metadata_mox_ok()
expected = [
%{
address_hash: <<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1>>,
name: "Testname Unitarion",
primary: true,
metadata: %{
address: "",
created_date: 0,
expiration_date: 253_370_764_800,
license_id: "00000000",
state: "XX",
zipcode: "00000"
}
}
]
assert MetadataRetriever.fetch_data() == expected
end
test "returns maps with the info on each validator" do test "returns maps with the info on each validator" do
validators_list_mox_ok() validators_list_mox_ok()
validator_metadata_mox_ok() validator_metadata_mox_ok()
validator_metadata_mox_ok()
expected = [ expected = [
%{ %{
@ -25,6 +49,19 @@ defmodule Explorer.Validator.MetadataRetrieverTest do
state: "XX", state: "XX",
zipcode: "00000" zipcode: "00000"
} }
},
%{
address_hash: <<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2>>,
name: "Testname Unitarion",
primary: true,
metadata: %{
address: "",
created_date: 0,
expiration_date: 253_370_764_800,
license_id: "00000000",
state: "XX",
zipcode: "00000"
}
} }
] ]
@ -36,8 +73,8 @@ defmodule Explorer.Validator.MetadataRetrieverTest do
assert_raise(MatchError, fn -> MetadataRetriever.fetch_data() end) assert_raise(MatchError, fn -> MetadataRetriever.fetch_data() end)
end end
test "raise error when a call to the metadatc contract fails" do test "raise error when a call to the metadata contract fails" do
validators_list_mox_ok() single_validator_in_list_mox_ok()
contract_request_with_error() contract_request_with_error()
assert_raise(MatchError, fn -> MetadataRetriever.fetch_data() end) assert_raise(MatchError, fn -> MetadataRetriever.fetch_data() end)
end end
@ -60,7 +97,7 @@ defmodule Explorer.Validator.MetadataRetrieverTest do
) )
end end
defp validators_list_mox_ok() do defp single_validator_in_list_mox_ok() do
expect( expect(
EthereumJSONRPC.Mox, EthereumJSONRPC.Mox,
:json_rpc, :json_rpc,
@ -79,6 +116,25 @@ defmodule Explorer.Validator.MetadataRetrieverTest do
) )
end end
defp validators_list_mox_ok() do
expect(
EthereumJSONRPC.Mox,
:json_rpc,
1,
fn [%{id: id}], _opts ->
{:ok,
[
%{
id: id,
jsonrpc: "2.0",
result:
"0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"
}
]}
end
)
end
defp validator_metadata_mox_ok() do defp validator_metadata_mox_ok() do
expect( expect(
EthereumJSONRPC.Mox, EthereumJSONRPC.Mox,
@ -91,7 +147,7 @@ defmodule Explorer.Validator.MetadataRetrieverTest do
id: id, id: id,
jsonrpc: "2.0", jsonrpc: "2.0",
result: result:
"0x546573746e616d65000000000000000000000000000000000000000000000000556e69746172696f6e000000000000000000000000000000000000000000000030303030303030300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000140585800000000000000000000000000000000000000000000000000000000000030303030300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003afe130e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000058585858585858207374726565742058585858585800000000000000000000000000000000000000000000000000000000000000000000000000000000000000" "0x546573746e616d65000000000000000000000000000000000000000000000000556e69746172696f6e000000000000000000000000000000000000000000000030303030303030300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000140585800000000000000000000000000000000000000000000000000000000000030303030300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003afe130e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
} }
]} ]}
end end

@ -32,7 +32,7 @@
"ecto": {:hex, :ecto, "3.3.1", "82ab74298065bf0c64ca299f6c6785e68ea5d6b980883ee80b044499df35aba1", [:mix], [{:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"}, "ecto": {:hex, :ecto, "3.3.1", "82ab74298065bf0c64ca299f6c6785e68ea5d6b980883ee80b044499df35aba1", [:mix], [{:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
"ecto_sql": {:hex, :ecto_sql, "3.3.2", "92804e0de69bb63e621273c3492252cb08a29475c05d40eeb6f41ad2d483cfd3", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"}, "ecto_sql": {:hex, :ecto_sql, "3.3.2", "92804e0de69bb63e621273c3492252cb08a29475c05d40eeb6f41ad2d483cfd3", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"},
"elixir_make": {:hex, :elixir_make, "0.6.0", "38349f3e29aff4864352084fc736fa7fa0f2995a819a737554f7ebd28b85aaab", [:mix], [], "hexpm"}, "elixir_make": {:hex, :elixir_make, "0.6.0", "38349f3e29aff4864352084fc736fa7fa0f2995a819a737554f7ebd28b85aaab", [:mix], [], "hexpm"},
"ex_abi": {:hex, :ex_abi, "0.1.18", "19db9bffdd201edbdff97d7dd5849291218b17beda045c1b76bff5248964f37d", [:mix], [{:exth_crypto, "~> 0.1.4", [hex: :exth_crypto, repo: "hexpm", optional: false]}], "hexpm"}, "ex_abi": {:git, "https://github.com/poanetwork/ex_abi.git", "02539efc1a9f1c1e36f8df26e54617522482dc12", [branch: "master"]},
"ex_cldr": {:hex, :ex_cldr, "2.7.2", "d79a1af6ed12630a15175d2b88d4381b22db5d6f835c5da8de132f0cf712b233", [:mix], [{:cldr_utils, "~> 2.1", [hex: :cldr_utils, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:gettext, "~> 0.13", [hex: :gettext, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_parsec, "~> 0.5", [hex: :nimble_parsec, repo: "hexpm", optional: false]}, {:plug, "~> 1.4", [hex: :plug, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm"}, "ex_cldr": {:hex, :ex_cldr, "2.7.2", "d79a1af6ed12630a15175d2b88d4381b22db5d6f835c5da8de132f0cf712b233", [:mix], [{:cldr_utils, "~> 2.1", [hex: :cldr_utils, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:gettext, "~> 0.13", [hex: :gettext, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_parsec, "~> 0.5", [hex: :nimble_parsec, repo: "hexpm", optional: false]}, {:plug, "~> 1.4", [hex: :plug, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm"},
"ex_cldr_currencies": {:hex, :ex_cldr_currencies, "2.3.0", "bffae489416b8b05d4683403263f5d62aae17de70c24ff915a533541fea514de", [:mix], [{:ex_cldr, "~> 2.6", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"}, "ex_cldr_currencies": {:hex, :ex_cldr_currencies, "2.3.0", "bffae489416b8b05d4683403263f5d62aae17de70c24ff915a533541fea514de", [:mix], [{:ex_cldr, "~> 2.6", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
"ex_cldr_lists": {:hex, :ex_cldr_lists, "2.2.0", "b99f8752d098fc6ba5f083bbd0b25d0d01e36b0042155cf6abd5f205306ba849", [:mix], [{:ex_cldr, "~> 2.6", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:ex_cldr_numbers, "~> 2.6", [hex: :ex_cldr_numbers, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"}, "ex_cldr_lists": {:hex, :ex_cldr_lists, "2.2.0", "b99f8752d098fc6ba5f083bbd0b25d0d01e36b0042155cf6abd5f205306ba849", [:mix], [{:ex_cldr, "~> 2.6", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:ex_cldr_numbers, "~> 2.6", [hex: :ex_cldr_numbers, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},

Loading…
Cancel
Save