Merge pull request #4439 from blockscout/np-fix-error-print

Fix error response in contract's output
pull/4444/head
Victor Baranov 3 years ago committed by GitHub
commit 54e28d4d25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 14
      apps/block_scout_web/lib/block_scout_web/templates/smart_contract/_function_response.html.eex
  3. 2
      apps/block_scout_web/lib/block_scout_web/views/smart_contract_view.ex
  4. 11
      apps/explorer/lib/explorer/smart_contract/reader.ex
  5. 6
      apps/explorer/test/explorer/smart_contract/reader_test.exs

@ -6,6 +6,7 @@
- [#4401](https://github.com/blockscout/blockscout/pull/4401) - Fix displaying of token holders with the same amount - [#4401](https://github.com/blockscout/blockscout/pull/4401) - Fix displaying of token holders with the same amount
### Chore ### Chore
- [#4439](https://github.com/blockscout/blockscout/pull/4439) - Fix revert response in contract's output
## 3.7.2-beta ## 3.7.2-beta

@ -1,10 +1,14 @@
<div class="tile tile-muted tile-function-response monospace"> <div class="tile tile-muted tile-function-response monospace">
<pre> <pre>
[ <strong><%= @function_name %></strong> method Response ] [ <strong><%= @function_name %></strong> method Response ]
<%= case @outputs do %>
[<%= for item <- @outputs do %> <% {:error, message} -> %>
<%= if named_argument?(item) do %><span class="function-response-item"><%= item["name"] %></span><% end %> <span class="text-muted"><%=raw(values_with_type(message, :error))%></span>
<span class="text-muted"><%= raw(values_with_type(item["value"], item["type"])) %></span> <% _ -> %>
<% end %>] [<%= for item <- @outputs do %>
<%= if named_argument?(item) do %><span class="function-response-item"><%= item["name"] %></span><% end %>
<span class="text-muted"><%= raw(values_with_type(item["value"], item["type"])) %></span>
<% end %>]
<% end %>
</pre> </pre>
</div> </div>

@ -100,6 +100,8 @@ defmodule BlockScoutWeb.SmartContractView do
def values_with_type(value, :bool, _components), do: render_type_value("bool", to_string(value)) def values_with_type(value, :bool, _components), do: render_type_value("bool", to_string(value))
def values_with_type(value, :error, _components), do: render_type_value("error", value)
def values_with_type(value, type, _components) do def values_with_type(value, type, _components) do
render_type_value(type, binary_to_utf_string(value)) render_type_value(type, binary_to_utf_string(value))
end end

@ -450,10 +450,15 @@ defmodule Explorer.SmartContract.Reader do
def link_outputs_and_values(blockchain_values, outputs, method_id) do def link_outputs_and_values(blockchain_values, outputs, method_id) do
default_value = Enum.map(outputs, fn _ -> "" end) default_value = Enum.map(outputs, fn _ -> "" end)
{_, value} = Map.get(blockchain_values, method_id, {:ok, default_value})
for {output, index} <- Enum.with_index(outputs) do case Map.get(blockchain_values, method_id, {:ok, default_value}) do
new_value(output, List.wrap(value), index) {:ok, value} ->
for {output, index} <- Enum.with_index(outputs) do
new_value(output, List.wrap(value), index)
end
{:error, message} ->
{:error, message}
end end
end end

@ -357,6 +357,12 @@ defmodule Explorer.SmartContract.ReaderTest do
} }
] = Reader.link_outputs_and_values(blockchain_values, outputs, function_name) ] = Reader.link_outputs_and_values(blockchain_values, outputs, function_name)
end end
test "save error message" do
blockchain_values = %{"check" => {:error, "Reverted"}}
assert {:error, "Reverted"} == Reader.link_outputs_and_values(blockchain_values, [], "check")
end
end end
defp blockchain_get_function_mock do defp blockchain_get_function_mock do

Loading…
Cancel
Save