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. 7
      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
### Chore
- [#4439](https://github.com/blockscout/blockscout/pull/4439) - Fix revert response in contract's output
## 3.7.2-beta

@ -1,10 +1,14 @@
<div class="tile tile-muted tile-function-response monospace">
<pre>
[ <strong><%= @function_name %></strong> method Response ]
[<%= 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 %>]
<%= case @outputs do %>
<% {:error, message} -> %>
<span class="text-muted"><%=raw(values_with_type(message, :error))%></span>
<% _ -> %>
[<%= 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>
</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, :error, _components), do: render_type_value("error", value)
def values_with_type(value, type, _components) do
render_type_value(type, binary_to_utf_string(value))
end

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

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

Loading…
Cancel
Save