|
|
@ -12,10 +12,12 @@ defmodule BlockScoutWeb.ABIEncodedValueView do |
|
|
|
|
|
|
|
|
|
|
|
require Logger |
|
|
|
require Logger |
|
|
|
|
|
|
|
|
|
|
|
def value_html(type, value) do |
|
|
|
def value_html(type, value, no_links \\ false) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def value_html(type, value, no_links) do |
|
|
|
decoded_type = FunctionSelector.decode_type(type) |
|
|
|
decoded_type = FunctionSelector.decode_type(type) |
|
|
|
|
|
|
|
|
|
|
|
do_value_html(decoded_type, value) |
|
|
|
do_value_html(decoded_type, value, no_links) |
|
|
|
rescue |
|
|
|
rescue |
|
|
|
exception -> |
|
|
|
exception -> |
|
|
|
Logger.warn(fn -> |
|
|
|
Logger.warn(fn -> |
|
|
@ -78,20 +80,20 @@ defmodule BlockScoutWeb.ABIEncodedValueView do |
|
|
|
to_string(value) |
|
|
|
to_string(value) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp do_value_html(type, value, depth \\ 0) |
|
|
|
defp do_value_html(type, value, no_links, depth \\ 0) |
|
|
|
|
|
|
|
|
|
|
|
defp do_value_html({:bytes, _}, value, depth) do |
|
|
|
defp do_value_html({:bytes, _}, value, no_links, depth) do |
|
|
|
do_value_html(:bytes, value, depth) |
|
|
|
do_value_html(:bytes, value, no_links, depth) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp do_value_html({:array, type, _}, value, depth) do |
|
|
|
defp do_value_html({:array, type, _}, value, no_links, depth) do |
|
|
|
do_value_html({:array, type}, value, depth) |
|
|
|
do_value_html({:array, type}, value, no_links, depth) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp do_value_html({:array, type}, value, depth) do |
|
|
|
defp do_value_html({:array, type}, value, no_links, depth) do |
|
|
|
values = |
|
|
|
values = |
|
|
|
Enum.map(value, fn inner_value -> |
|
|
|
Enum.map(value, fn inner_value -> |
|
|
|
do_value_html(type, inner_value, depth + 1) |
|
|
|
do_value_html(type, inner_value, no_links, depth + 1) |
|
|
|
end) |
|
|
|
end) |
|
|
|
|
|
|
|
|
|
|
|
spacing = String.duplicate(" ", depth * 2) |
|
|
|
spacing = String.duplicate(" ", depth * 2) |
|
|
@ -100,44 +102,48 @@ defmodule BlockScoutWeb.ABIEncodedValueView do |
|
|
|
~E|<%= spacing %>[<%= "\n" %><%= delimited %><%= "\n" %><%= spacing %>]| |
|
|
|
~E|<%= spacing %>[<%= "\n" %><%= delimited %><%= "\n" %><%= spacing %>]| |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp do_value_html({:tuple, types}, values, _) do |
|
|
|
defp do_value_html({:tuple, types}, values, no_links, _) do |
|
|
|
values_list = |
|
|
|
values_list = |
|
|
|
values |
|
|
|
values |
|
|
|
|> Tuple.to_list() |
|
|
|
|> Tuple.to_list() |
|
|
|
|> Enum.with_index() |
|
|
|
|> Enum.with_index() |
|
|
|
|> Enum.map(fn {value, i} -> |
|
|
|
|> Enum.map(fn {value, i} -> |
|
|
|
do_value_html(Enum.at(types, i), value) |
|
|
|
do_value_html(Enum.at(types, i), value, no_links) |
|
|
|
end) |
|
|
|
end) |
|
|
|
|
|
|
|
|
|
|
|
delimited = Enum.intersperse(values_list, ",") |
|
|
|
delimited = Enum.intersperse(values_list, ",") |
|
|
|
~E|(<%= delimited %>)| |
|
|
|
~E|(<%= delimited %>)| |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp do_value_html(type, value, depth) do |
|
|
|
defp do_value_html(type, value, no_links, depth) do |
|
|
|
spacing = String.duplicate(" ", depth * 2) |
|
|
|
spacing = String.duplicate(" ", depth * 2) |
|
|
|
~E|<%= spacing %><%=base_value_html(type, value)%>| |
|
|
|
~E|<%= spacing %><%=base_value_html(type, value, no_links)%>| |
|
|
|
[spacing, base_value_html(type, value)] |
|
|
|
[spacing, base_value_html(type, value, no_links)] |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp base_value_html(_, {:dynamic, value}) do |
|
|
|
defp base_value_html(_, {:dynamic, value}, _no_links) do |
|
|
|
~E|<%= hex(value) %>| |
|
|
|
~E|<%= hex(value) %>| |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp base_value_html(:address, value) do |
|
|
|
defp base_value_html(:address, value, no_links) do |
|
|
|
|
|
|
|
if no_links do |
|
|
|
|
|
|
|
base_value_html(:address_text, value, no_links) |
|
|
|
|
|
|
|
else |
|
|
|
address = hex(value) |
|
|
|
address = hex(value) |
|
|
|
|
|
|
|
|
|
|
|
~E|<a href="<%= address_path(BlockScoutWeb.Endpoint, :show, address) %>" target="_blank"><%= address %></a>| |
|
|
|
~E|<a href="<%= address_path(BlockScoutWeb.Endpoint, :show, address) %>" target="_blank"><%= address %></a>| |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp base_value_html(:address_text, value) do |
|
|
|
defp base_value_html(:address_text, value, _no_links) do |
|
|
|
~E|<%= hex(value) %>| |
|
|
|
~E|<%= hex(value) %>| |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp base_value_html(:bytes, value) do |
|
|
|
defp base_value_html(:bytes, value, _no_links) do |
|
|
|
~E|<%= hex(value) %>| |
|
|
|
~E|<%= hex(value) %>| |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp base_value_html(_, value), do: HTML.html_escape(value) |
|
|
|
defp base_value_html(_, value, _no_links), do: HTML.html_escape(value) |
|
|
|
|
|
|
|
|
|
|
|
defp hex(value), do: "0x" <> Base.encode16(value, case: :lower) |
|
|
|
defp hex(value), do: "0x" <> Base.encode16(value, case: :lower) |
|
|
|
end |
|
|
|
end |
|
|
|