Make a link to address page on decoded constructor argumennt of address type

pull/3069/head
Victor Baranov 5 years ago
parent 2824fefc47
commit 8cc05a3202
  1. 1
      CHANGELOG.md
  2. 2
      apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex
  3. 28
      apps/block_scout_web/lib/block_scout_web/views/address_contract_view.ex
  4. 4
      apps/block_scout_web/priv/gettext/default.pot
  5. 4
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po

@ -2,6 +2,7 @@
### Features
- [#3069](https://github.com/poanetwork/blockscout/pull/3069) - Make a link to address page on decoded constructor argument of address type
- [#3066](https://github.com/poanetwork/blockscout/pull/3066) - ERC-721 token instance page: link to token added
### Fixes

@ -53,7 +53,7 @@
<h3><%= gettext "Constructor Arguments" %></h3>
</div>
<div class="tile tile-muted mb-4">
<pre class="pre-wrap pre-scrollable"><code class="nohighlight"><%= raw(format_constructor_arguments(@address.smart_contract)) %></code>
<pre class="pre-wrap pre-scrollable"><code class="nohighlight"><%= raw(format_constructor_arguments(@address.smart_contract, @conn)) %></code>
</pre>
</div>
</section>

@ -2,6 +2,7 @@ defmodule BlockScoutWeb.AddressContractView do
use BlockScoutWeb, :view
alias ABI.{FunctionSelector, TypeDecoder}
alias Explorer.Chain
alias Explorer.Chain.{Address, Data, InternalTransaction, SmartContract}
def render("scripts.html", %{conn: conn}) do
@ -22,7 +23,7 @@ defmodule BlockScoutWeb.AddressContractView do
def format_optimization_text(true), do: gettext("true")
def format_optimization_text(false), do: gettext("false")
def format_constructor_arguments(contract) do
def format_constructor_arguments(contract, conn) do
constructor_abi = Enum.find(contract.abi, fn el -> el["type"] == "constructor" && el["inputs"] != [] end)
input_types = Enum.map(constructor_abi["inputs"], &FunctionSelector.parse_specification_type/1)
@ -32,10 +33,23 @@ defmodule BlockScoutWeb.AddressContractView do
|> decode_data(input_types)
|> Enum.zip(constructor_abi["inputs"])
|> Enum.reduce({0, "#{contract.constructor_arguments}\n\n"}, fn {val, %{"type" => type}}, {count, acc} ->
address_hash = "0x" <> Base.encode16(val, case: :lower)
address =
case Chain.string_to_address_hash(address_hash) do
{:ok, address} -> address
_ -> nil
end
formatted_val =
if type =~ "address" || type =~ "bytes" do
cond do
type =~ "address" ->
get_formatted_address_data(address, address_hash, conn)
type =~ "bytes" ->
Base.encode16(val, case: :lower)
else
true ->
val
end
@ -47,6 +61,14 @@ defmodule BlockScoutWeb.AddressContractView do
_ -> contract.constructor_arguments
end
defp get_formatted_address_data(address, address_hash, conn) do
if address != nil do
"<a href=" <> address_path(conn, :show, address) <> ">" <> address_hash <> "</a>"
else
address_hash
end
end
defp decode_data("0x" <> encoded_data, types) do
decode_data(encoded_data, types)
end

@ -1672,7 +1672,7 @@ msgid "custom RPC"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/address_contract_view.ex:23
#: lib/block_scout_web/views/address_contract_view.ex:24
msgid "false"
msgstr ""
@ -1714,7 +1714,7 @@ msgid "string"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/address_contract_view.ex:22
#: lib/block_scout_web/views/address_contract_view.ex:23
msgid "true"
msgstr ""

@ -1672,7 +1672,7 @@ msgid "custom RPC"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/address_contract_view.ex:23
#: lib/block_scout_web/views/address_contract_view.ex:24
msgid "false"
msgstr ""
@ -1714,7 +1714,7 @@ msgid "string"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/address_contract_view.ex:22
#: lib/block_scout_web/views/address_contract_view.ex:23
msgid "true"
msgstr ""

Loading…
Cancel
Save