From adfb068241c8d86d17adc2b60425add35262f3e5 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Wed, 8 Apr 2020 12:04:06 +0300 Subject: [PATCH 1/5] NFT token page: link to token --- CHANGELOG.md | 2 ++ .../templates/tokens/instance/overview/_details.html.eex | 2 +- .../templates/tokens/transfer/_token_transfer.html.eex | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d902dc4ab5..9e3756ddd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### Features +- [#3066](https://github.com/poanetwork/blockscout/pull/3066) - ERC-721 token instance page: link to token added + ### Fixes - [#3064](https://github.com/poanetwork/blockscout/pull/3064) - Automatically define Block reward contract address in TokenBridge supply module diff --git a/apps/block_scout_web/lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex index 417f9e976e..9785453dd6 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex @@ -5,7 +5,7 @@

<%= if token_name?(@token) do %> - <%= @token.name %> + <%= link(@token.name, to: token_path(BlockScoutWeb.Endpoint, :show, @token.contract_address_hash)) %> <% else %> <%= gettext("Token Details") %> <% end %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex index 5e9afe04df..91dc2c2775 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex @@ -37,7 +37,7 @@ <%= value %> <% end %> <%= " "%> - <%= @token_transfer.token.symbol %> + <%= link(@token_transfer.token.symbol, to: token_path(BlockScoutWeb.Endpoint, :show, @token_transfer.token.contract_address_hash)) %>

From 1944c05baab866f330cf6788b1496c041da7db22 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Wed, 8 Apr 2020 16:31:31 +0300 Subject: [PATCH 2/5] Distinguish token burnings, mintings --- .../channels/address_channel.ex | 6 +- .../channels/transaction_channel.ex | 6 + .../address_token_transfer_controller.ex | 5 + .../address_transaction_controller.ex | 6 +- .../block_transaction_controller.ex | 4 + .../pending_transaction_controller.ex | 4 + .../tokens/instance/transfer_controller.ex | 6 +- .../controllers/tokens/transfer_controller.ex | 6 +- .../controllers/transaction_controller.ex | 4 + .../transaction_token_transfer_controller.ex | 4 + .../tokens/transfer/_token_transfer.html.eex | 11 +- .../templates/transaction/_tile.html.eex | 2 +- .../templates/transaction/overview.html.eex | 67 ++++++++--- .../_token_transfer.html.eex | 11 +- .../block_scout_web/views/transaction_view.ex | 111 ++++++++++++++++-- apps/block_scout_web/priv/gettext/default.pot | 80 ++++++++----- .../priv/gettext/en/LC_MESSAGES/default.po | 80 ++++++++----- 17 files changed, 328 insertions(+), 85 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/channels/address_channel.ex b/apps/block_scout_web/lib/block_scout_web/channels/address_channel.ex index 3af20a4fd3..376015dbac 100644 --- a/apps/block_scout_web/lib/block_scout_web/channels/address_channel.ex +++ b/apps/block_scout_web/lib/block_scout_web/channels/address_channel.ex @@ -13,6 +13,9 @@ defmodule BlockScoutWeb.AddressChannel do intercept(["balance_update", "coin_balance", "count", "internal_transaction", "transaction", "verification_result"]) + {:ok, burn_address_hash} = Chain.string_to_address_hash("0x0000000000000000000000000000000000000000") + @burn_address_hash burn_address_hash + def join("addresses:" <> address_hash, _params, socket) do {:ok, %{}, assign(socket, :address_hash, address_hash)} end @@ -129,7 +132,8 @@ defmodule BlockScoutWeb.AddressChannel do "_tile.html", conn: socket, current_address: address, - transaction: transaction + transaction: transaction, + burn_address_hash: @burn_address_hash ) push(socket, event, %{ diff --git a/apps/block_scout_web/lib/block_scout_web/channels/transaction_channel.ex b/apps/block_scout_web/lib/block_scout_web/channels/transaction_channel.ex index e9ec0ec928..4679873131 100644 --- a/apps/block_scout_web/lib/block_scout_web/channels/transaction_channel.ex +++ b/apps/block_scout_web/lib/block_scout_web/channels/transaction_channel.ex @@ -5,11 +5,15 @@ defmodule BlockScoutWeb.TransactionChannel do use BlockScoutWeb, :channel alias BlockScoutWeb.TransactionView + alias Explorer.Chain alias Explorer.Chain.Hash alias Phoenix.View intercept(["pending_transaction", "transaction"]) + {:ok, burn_address_hash} = Chain.string_to_address_hash("0x0000000000000000000000000000000000000000") + @burn_address_hash burn_address_hash + def join("transactions:new_transaction", _params, socket) do {:ok, %{}, socket} end @@ -30,6 +34,7 @@ defmodule BlockScoutWeb.TransactionChannel do TransactionView, "_tile.html", transaction: transaction, + burn_address_hash: @burn_address_hash, conn: socket ) @@ -49,6 +54,7 @@ defmodule BlockScoutWeb.TransactionChannel do TransactionView, "_tile.html", transaction: transaction, + burn_address_hash: @burn_address_hash, conn: socket ) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_token_transfer_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_token_transfer_controller.ex index 23b393f5a3..4af79088b0 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_token_transfer_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_token_transfer_controller.ex @@ -24,6 +24,9 @@ defmodule BlockScoutWeb.AddressTokenTransferController do } ] + {:ok, burn_address_hash} = Chain.string_to_address_hash("0x0000000000000000000000000000000000000000") + @burn_address_hash burn_address_hash + def index( conn, %{ @@ -67,6 +70,7 @@ defmodule BlockScoutWeb.AddressTokenTransferController do "_tile.html", conn: conn, transaction: transaction, + burn_address_hash: @burn_address_hash, current_address: address ) end) @@ -151,6 +155,7 @@ defmodule BlockScoutWeb.AddressTokenTransferController do "_tile.html", conn: conn, transaction: transaction, + burn_address_hash: @burn_address_hash, current_address: address ) end) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_transaction_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_transaction_controller.ex index 2bac5acdb2..66203f425b 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_transaction_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_transaction_controller.ex @@ -23,6 +23,9 @@ defmodule BlockScoutWeb.AddressTransactionController do } ] + {:ok, burn_address_hash} = Chain.string_to_address_hash("0x0000000000000000000000000000000000000000") + @burn_address_hash burn_address_hash + def index(conn, %{"address_id" => address_hash_string, "type" => "JSON"} = params) do address_options = [necessity_by_association: %{:names => :optional}] @@ -69,7 +72,8 @@ defmodule BlockScoutWeb.AddressTransactionController do "_tile.html", conn: conn, current_address: address, - transaction: transaction + transaction: transaction, + burn_address_hash: @burn_address_hash ) end end) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/block_transaction_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/block_transaction_controller.ex index 9351f9f886..a07f4113c1 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/block_transaction_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/block_transaction_controller.ex @@ -10,6 +10,9 @@ defmodule BlockScoutWeb.BlockTransactionController do alias Explorer.Chain alias Phoenix.View + {:ok, burn_address_hash} = Chain.string_to_address_hash("0x0000000000000000000000000000000000000000") + @burn_address_hash burn_address_hash + def index(conn, %{"block_hash_or_number" => formatted_block_hash_or_number, "type" => "JSON"} = params) do case param_block_hash_or_number_to_block(formatted_block_hash_or_number, []) do {:ok, block} -> @@ -51,6 +54,7 @@ defmodule BlockScoutWeb.BlockTransactionController do TransactionView, "_tile.html", transaction: transaction, + burn_address_hash: @burn_address_hash, conn: conn ) end) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/pending_transaction_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/pending_transaction_controller.ex index 9385ee5616..03b9d87885 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/pending_transaction_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/pending_transaction_controller.ex @@ -7,6 +7,9 @@ defmodule BlockScoutWeb.PendingTransactionController do alias Explorer.Chain alias Phoenix.View + {:ok, burn_address_hash} = Chain.string_to_address_hash("0x0000000000000000000000000000000000000000") + @burn_address_hash burn_address_hash + def index(conn, %{"type" => "JSON"} = params) do full_options = Keyword.merge( @@ -44,6 +47,7 @@ defmodule BlockScoutWeb.PendingTransactionController do TransactionView, "_tile.html", transaction: transaction, + burn_address_hash: @burn_address_hash, conn: conn ) end), diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/tokens/instance/transfer_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/tokens/instance/transfer_controller.ex index e05b49cd47..d687147cd9 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/tokens/instance/transfer_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/tokens/instance/transfer_controller.ex @@ -8,6 +8,9 @@ defmodule BlockScoutWeb.Tokens.Instance.TransferController do import BlockScoutWeb.Chain, only: [split_list_by_page: 1, paging_options: 1, next_page_params: 3] + {:ok, burn_address_hash} = Chain.string_to_address_hash("0x0000000000000000000000000000000000000000") + @burn_address_hash burn_address_hash + def index(conn, %{"token_id" => token_address_hash, "instance_id" => token_id, "type" => "JSON"} = params) do with {:ok, hash} <- Chain.string_to_address_hash(token_address_hash), {:ok, token} <- Chain.token_from_address_hash(hash), @@ -37,7 +40,8 @@ defmodule BlockScoutWeb.Tokens.Instance.TransferController do "_token_transfer.html", conn: conn, token: token, - token_transfer: transfer + token_transfer: transfer, + burn_address_hash: @burn_address_hash ) end) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/tokens/transfer_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/tokens/transfer_controller.ex index b3b523926f..6f8d7958e9 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/tokens/transfer_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/tokens/transfer_controller.ex @@ -8,6 +8,9 @@ defmodule BlockScoutWeb.Tokens.TransferController do import BlockScoutWeb.Chain, only: [split_list_by_page: 1, paging_options: 1, next_page_params: 3] + {:ok, burn_address_hash} = Chain.string_to_address_hash("0x0000000000000000000000000000000000000000") + @burn_address_hash burn_address_hash + def index(conn, %{"token_id" => address_hash_string, "type" => "JSON"} = params) do with {:ok, address_hash} <- Chain.string_to_address_hash(address_hash_string), {:ok, token} <- Chain.token_from_address_hash(address_hash), @@ -35,7 +38,8 @@ defmodule BlockScoutWeb.Tokens.TransferController do "_token_transfer.html", conn: conn, token: token, - token_transfer: transfer + token_transfer: transfer, + burn_address_hash: @burn_address_hash ) end) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_controller.ex index db0cae65d8..9643a356bd 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_controller.ex @@ -7,6 +7,9 @@ defmodule BlockScoutWeb.TransactionController do alias Explorer.Chain alias Phoenix.View + {:ok, burn_address_hash} = Chain.string_to_address_hash("0x0000000000000000000000000000000000000000") + @burn_address_hash burn_address_hash + def index(conn, %{"type" => "JSON"} = params) do full_options = Keyword.merge( @@ -42,6 +45,7 @@ defmodule BlockScoutWeb.TransactionController do TransactionView, "_tile.html", transaction: transaction, + burn_address_hash: @burn_address_hash, conn: conn ) end), diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_token_transfer_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_token_transfer_controller.ex index 585a01301f..afb2fa373e 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_token_transfer_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_token_transfer_controller.ex @@ -8,6 +8,9 @@ defmodule BlockScoutWeb.TransactionTokenTransferController do alias Explorer.ExchangeRates.Token alias Phoenix.View + {:ok, burn_address_hash} = Chain.string_to_address_hash("0x0000000000000000000000000000000000000000") + @burn_address_hash burn_address_hash + def index(conn, %{"transaction_id" => hash_string, "type" => "JSON"} = params) do with {:ok, hash} <- Chain.string_to_transaction_hash(hash_string), :ok <- Chain.check_transaction_exists(hash) do @@ -43,6 +46,7 @@ defmodule BlockScoutWeb.TransactionTokenTransferController do TransactionTokenTransferView, "_token_transfer.html", token_transfer: transfer, + burn_address_hash: @burn_address_hash, conn: conn ) end) diff --git a/apps/block_scout_web/lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex index 5e9afe04df..1372082f65 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex @@ -2,7 +2,16 @@
- <%= gettext "Token Transfer" %> + + <%= cond do %> + <% @token_transfer.to_address.hash == @burn_address_hash -> %> + <%= gettext("Token Burning") %> + <% @token_transfer.from_address.hash == @burn_address_hash -> %> + <%= gettext("Token Minting") %> + <% true -> %> + <%= gettext("Token Transfer") %> + <% end %> +
diff --git a/apps/block_scout_web/lib/block_scout_web/templates/transaction/_tile.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/transaction/_tile.html.eex index c8a966c9f2..f21d474ccf 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/transaction/_tile.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/transaction/_tile.html.eex @@ -42,7 +42,7 @@
<%= for token_transfer <- remaining_token_transfers do %> - <%= render "_token_transfer.html", address: assigns[:current_address], token_transfer: token_transfer %> + <%= render "_token_transfer.html", address: assigns[:current_address], token_transfer: token_transfer, burn_address_hash: @burn_address_hash %> <% end %>
diff --git a/apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex index 7b2d942ade..cca53f0865 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex @@ -191,21 +191,60 @@ <% end %>
<% end %> -

<%= token_type_name(type)%><%= gettext " Token Transfer" %>

-
- <%= for transfer <- aggregate_token_transfers(transaction_with_transfers.token_transfers) do %> -

- <%= case token_transfer_amount(transfer) do %> - <% {:ok, :erc721_instance} -> %> - <%= "TokenID ["%><%= link(transfer.token_id, to: token_instance_path(@conn, :show, transfer.token.contract_address_hash, to_string(transfer.token_id))) %><%= "]" %> - <% {:ok, value} -> %> - <%= value %> - <% end %> - <%= " "%> - <%= link(token_symbol(transfer.token), to: token_path(BlockScoutWeb.Endpoint, :show, transfer.token.contract_address_hash)) %> -

+ <% token_transfers = aggregate_token_transfers(transaction_with_transfers.token_transfers) %> + <%= if Enum.count(token_transfers) > 0 do %> +

<%= token_type_name(type)%><%= gettext " Token Transfer" %>

+
+ <%= for transfer <- token_transfers do %> +

+ <%= case token_transfer_amount(transfer) do %> + <% {:ok, :erc721_instance} -> %> + <%= "TokenID ["%><%= link(transfer.token_id, to: token_instance_path(@conn, :show, transfer.token.contract_address_hash, to_string(transfer.token_id))) %><%= "]" %> + <% {:ok, value} -> %> + <%= value %> + <% end %> + <%= " "%> + <%= link(token_symbol(transfer.token), to: token_path(BlockScoutWeb.Endpoint, :show, transfer.token.contract_address_hash)) %> +

+ <% end %> +
+ <% end %> + <% mintings = aggregate_token_mintings(transaction_with_transfers.token_transfers) %> + <%= if Enum.count(mintings) > 0 do %> +

<%= token_type_name(type)%><%= gettext " Token Minting" %>

+
+ <%= for transfer <- mintings do %> +

+ <%= case token_transfer_amount(transfer) do %> + <% {:ok, :erc721_instance} -> %> + <%= "TokenID ["%><%= link(transfer.token_id, to: token_instance_path(@conn, :show, transfer.token.contract_address_hash, to_string(transfer.token_id))) %><%= "]" %> + <% {:ok, value} -> %> + <%= value %> + <% end %> + <%= " "%> + <%= link(token_symbol(transfer.token), to: token_path(BlockScoutWeb.Endpoint, :show, transfer.token.contract_address_hash)) %> +

+ <% end %> +
+ <% end %> + <% burnings = aggregate_token_burnings(transaction_with_transfers.token_transfers) %> + <%= if Enum.count(burnings) > 0 do %> +

<%= token_type_name(type)%><%= gettext " Token Burning" %>

+
+ <%= for transfer <- burnings do %> +

+ <%= case token_transfer_amount(transfer) do %> + <% {:ok, :erc721_instance} -> %> + <%= "TokenID ["%><%= link(transfer.token_id, to: token_instance_path(@conn, :show, transfer.token.contract_address_hash, to_string(transfer.token_id))) %><%= "]" %> + <% {:ok, value} -> %> + <%= value %> + <% end %> + <%= " "%> + <%= link(token_symbol(transfer.token), to: token_path(BlockScoutWeb.Endpoint, :show, transfer.token.contract_address_hash)) %> +

+ <% end %> +
<% end %> -
<% _ -> %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex index 1bc1b34dc7..353d3067bf 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex @@ -1,7 +1,14 @@
- <%= gettext("Token Transfer") %> + <%= cond do %> + <% @token_transfer.to_address.hash == @burn_address_hash -> %> + <%= gettext("Token Burning") %> + <% @token_transfer.from_address.hash == @burn_address_hash -> %> + <%= gettext("Token Minting") %> + <% true -> %> + <%= gettext("Token Transfer") %> + <% end %>
@@ -15,7 +22,7 @@ <%= case token_transfer_amount(@token_transfer) do%> <% {:ok, :erc721_instance} -> %> - <%= "TokenID ["%><%= link(@token_transfer.token_id, to: token_instance_path(@conn, :show, @token_transfer.token.contract_address_hash, to_string(@token_transfer.token_id))) %><%= "]" %> + <%= "TokenID2 ["%><%= link(@token_transfer.token_id, to: token_instance_path(@conn, :show, @token_transfer.token.contract_address_hash, to_string(@token_transfer.token_id))) %><%= "]" %> <% {:ok, value} -> %> <%= value %> <% end %> diff --git a/apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex b/apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex index ede96a048d..252df60bf5 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex @@ -14,6 +14,17 @@ defmodule BlockScoutWeb.TransactionView do @tabs ["token_transfers", "internal_transactions", "logs", "raw_trace"] + {:ok, burn_address_hash} = Chain.string_to_address_hash("0x0000000000000000000000000000000000000000") + @burn_address_hash burn_address_hash + + @token_burning_title "Token Burning" + @token_minting_title "Token Minting" + @token_transfer_title "Token Transfer" + + @token_burning_type "token-burning" + @token_minting_type "token-minting" + @token_transfer_type "token-transfer" + defguardp is_transaction_type(mod) when mod in [InternalTransaction, Transaction] defdelegate formatted_timestamp(block), to: BlockView @@ -43,7 +54,44 @@ defmodule BlockScoutWeb.TransactionView do {transfers, nft_transfers} = token_transfers |> Enum.reduce({%{}, []}, fn token_transfer, acc -> - aggregate_reducer(token_transfer, acc) + if token_transfer.to_address_hash != @burn_address_hash && + token_transfer.from_address_hash != @burn_address_hash do + aggregate_reducer(token_transfer, acc) + else + acc + end + end) + + final_transfers = Map.values(transfers) + + final_transfers ++ nft_transfers + end + + def aggregate_token_mintings(token_transfers) do + {transfers, nft_transfers} = + token_transfers + |> Enum.reduce({%{}, []}, fn token_transfer, acc -> + if token_transfer.from_address_hash == @burn_address_hash do + aggregate_reducer(token_transfer, acc) + else + acc + end + end) + + final_transfers = Map.values(transfers) + + final_transfers ++ nft_transfers + end + + def aggregate_token_burnings(token_transfers) do + {transfers, nft_transfers} = + token_transfers + |> Enum.reduce({%{}, []}, fn token_transfer, acc -> + if token_transfer.to_address_hash == @burn_address_hash do + aggregate_reducer(token_transfer, acc) + else + acc + end end) final_transfers = Map.values(transfers) @@ -55,7 +103,9 @@ defmodule BlockScoutWeb.TransactionView do new_entry = %{ token: token_transfer.token, amount: nil, - token_id: token_transfer.token_id + token_id: token_transfer.token_id, + to_address_hash: token_transfer.to_address_hash, + from_address_hash: token_transfer.from_address_hash } {acc1, [new_entry | acc2]} @@ -65,7 +115,9 @@ defmodule BlockScoutWeb.TransactionView do new_entry = %{ token: token_transfer.token, amount: token_transfer.amount, - token_id: token_transfer.token_id + token_id: token_transfer.token_id, + to_address_hash: token_transfer.to_address_hash, + from_address_hash: token_transfer.from_address_hash } existing_entry = Map.get(acc1, token_transfer.token_contract_address, %{new_entry | amount: Decimal.new(0)}) @@ -257,10 +309,23 @@ defmodule BlockScoutWeb.TransactionView do def transaction_display_type(%Transaction{} = transaction) do cond do - involves_token_transfers?(transaction) -> gettext("Token Transfer") - contract_creation?(transaction) -> gettext("Contract Creation") - involves_contract?(transaction) -> gettext("Contract Call") - true -> gettext("Transaction") + involves_token_transfers?(transaction) -> + token_transfer_type = get_token_transfer_type(transaction.token_transfers) + + case token_transfer_type do + @token_minting_type -> gettext(@token_minting_title) + @token_burning_type -> gettext(@token_burning_title) + @token_transfer_type -> gettext(@token_transfer_title) + end + + contract_creation?(transaction) -> + gettext("Contract Creation") + + involves_contract?(transaction) -> + gettext("Contract Call") + + true -> + gettext("Transaction") end end @@ -315,4 +380,36 @@ defmodule BlockScoutWeb.TransactionView do defp tab_name(["internal_transactions"]), do: gettext("Internal Transactions") defp tab_name(["logs"]), do: gettext("Logs") defp tab_name(["raw_trace"]), do: gettext("Raw Trace") + + defp get_token_transfer_type(token_transfers) do + token_transfers + |> Enum.reduce("", fn token_transfer, type -> + cond do + token_transfer.to_address_hash == @burn_address_hash -> + update_transfer_type_if_burning(type) + + token_transfer.from_address_hash == @burn_address_hash -> + update_transfer_type_if_minting(type) + + true -> + @token_transfer_type + end + end) + end + + defp update_transfer_type_if_minting(type) do + case type do + "" -> @token_minting_type + @token_burning_type -> @token_transfer_type + _ -> type + end + end + + defp update_transfer_type_if_burning(type) do + case type do + "" -> @token_burning_type + @token_minting_type -> @token_transfer_type + _ -> type + end + end end diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index 9e0a122b09..91a34cf880 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -13,7 +13,7 @@ msgstr[0] "" msgstr[1] "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:194 +#: lib/block_scout_web/templates/transaction/overview.html.eex:196 msgid " Token Transfer" msgstr "" @@ -59,7 +59,7 @@ msgid "%{subnetwork} Explorer - BlockScout" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:184 +#: lib/block_scout_web/views/transaction_view.ex:236 msgid "(Awaiting internal transactions for status)" msgstr "" @@ -183,7 +183,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/block/_link.html.eex:2 #: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:28 -#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:48 +#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:57 msgid "Block #%{number}" msgstr "" @@ -218,7 +218,7 @@ msgid "Block Number" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:21 +#: lib/block_scout_web/views/transaction_view.ex:32 msgid "Block Pending" msgstr "" @@ -355,12 +355,12 @@ msgid "Contract Byte Code" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:262 +#: lib/block_scout_web/views/transaction_view.ex:325 msgid "Contract Call" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:261 +#: lib/block_scout_web/views/transaction_view.ex:322 msgid "Contract Creation" msgstr "" @@ -558,12 +558,12 @@ msgid "During times when the network is busy (i.e during ICOs) it can take a whi msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:84 +#: lib/block_scout_web/views/transaction_view.ex:136 msgid "ERC-20 " msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:85 +#: lib/block_scout_web/views/transaction_view.ex:137 msgid "ERC-721 " msgstr "" @@ -621,12 +621,12 @@ msgid "Error trying to fetch balances." msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:188 +#: lib/block_scout_web/views/transaction_view.ex:240 msgid "Error: %{reason}" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:186 +#: lib/block_scout_web/views/transaction_view.ex:238 msgid "Error: (Awaiting internal transactions for reason)" msgstr "" @@ -647,7 +647,7 @@ msgstr "" #: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:20 #: lib/block_scout_web/templates/transaction/_tile.html.eex:29 #: lib/block_scout_web/templates/transaction/overview.html.eex:181 -#: lib/block_scout_web/templates/transaction/overview.html.eex:216 +#: lib/block_scout_web/templates/transaction/overview.html.eex:255 #: lib/block_scout_web/views/wei_helpers.ex:78 msgid "Ether" msgstr "" @@ -776,7 +776,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/transaction/_emission_reward_tile.html.eex:8 -#: lib/block_scout_web/views/transaction_view.ex:185 +#: lib/block_scout_web/views/transaction_view.ex:237 msgid "Success" msgstr "" @@ -883,9 +883,9 @@ msgid "Token ID" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:5 -#: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:4 -#: lib/block_scout_web/views/transaction_view.ex:260 +#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:12 +#: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:10 +#: lib/block_scout_web/views/transaction_view.ex:318 msgid "Token Transfer" msgstr "" @@ -900,7 +900,7 @@ msgstr "" #: lib/block_scout_web/views/address_view.ex:314 #: lib/block_scout_web/views/tokens/instance/overview_view.ex:90 #: lib/block_scout_web/views/tokens/overview_view.ex:35 -#: lib/block_scout_web/views/transaction_view.ex:314 +#: lib/block_scout_web/views/transaction_view.ex:379 msgid "Token Transfers" msgstr "" @@ -916,7 +916,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address_logs/_logs.html.eex:18 -#: lib/block_scout_web/views/transaction_view.ex:263 +#: lib/block_scout_web/views/transaction_view.ex:328 msgid "Transaction" msgstr "" @@ -999,7 +999,7 @@ msgid "License ID" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:244 +#: lib/block_scout_web/templates/transaction/overview.html.eex:283 msgid "Limit" msgstr "" @@ -1041,8 +1041,8 @@ msgid "Market Cap" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:169 -#: lib/block_scout_web/views/transaction_view.ex:169 +#: lib/block_scout_web/views/transaction_view.ex:221 +#: lib/block_scout_web/views/transaction_view.ex:221 msgid "Max of" msgstr "" @@ -1154,8 +1154,8 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/layout/_topnav.html.eex:59 -#: lib/block_scout_web/views/transaction_view.ex:183 -#: lib/block_scout_web/views/transaction_view.ex:217 +#: lib/block_scout_web/views/transaction_view.ex:235 +#: lib/block_scout_web/views/transaction_view.ex:269 msgid "Pending" msgstr "" @@ -1203,7 +1203,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/transaction/_tabs.html.eex:24 #: lib/block_scout_web/templates/transaction_raw_trace/index.html.eex:7 -#: lib/block_scout_web/views/transaction_view.ex:317 +#: lib/block_scout_web/views/transaction_view.ex:382 msgid "Raw Trace" msgstr "" @@ -1539,7 +1539,7 @@ msgid "Use the search box to find a hosted network, or select from the list of a msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:238 +#: lib/block_scout_web/templates/transaction/overview.html.eex:277 msgid "Used" msgstr "" @@ -1570,7 +1570,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/transaction/overview.html.eex:181 -#: lib/block_scout_web/templates/transaction/overview.html.eex:216 +#: lib/block_scout_web/templates/transaction/overview.html.eex:255 msgid "Value" msgstr "" @@ -1747,7 +1747,7 @@ msgid "Decimals" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:234 +#: lib/block_scout_web/templates/transaction/overview.html.eex:273 msgid "Gas" msgstr "" @@ -1833,7 +1833,7 @@ msgstr "" #: lib/block_scout_web/templates/transaction/_tabs.html.eex:11 #: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:6 #: lib/block_scout_web/views/address_view.ex:313 -#: lib/block_scout_web/views/transaction_view.ex:315 +#: lib/block_scout_web/views/transaction_view.ex:380 msgid "Internal Transactions" msgstr "" @@ -1843,7 +1843,7 @@ msgstr "" #: lib/block_scout_web/templates/transaction/_tabs.html.eex:17 #: lib/block_scout_web/templates/transaction_log/index.html.eex:8 #: lib/block_scout_web/views/address_view.ex:320 -#: lib/block_scout_web/views/transaction_view.ex:316 +#: lib/block_scout_web/views/transaction_view.ex:381 msgid "Logs" msgstr "" @@ -1874,3 +1874,27 @@ msgstr "" #: lib/block_scout_web/views/address_view.ex:312 msgid "Transactions" msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/transaction/overview.html.eex:232 +msgid " Token Burning" +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:8 +#: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:6 +#: lib/block_scout_web/views/transaction_view.ex:317 +msgid "Token Burning" +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/transaction/overview.html.eex:214 +msgid " Token Minting" +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:10 +#: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:8 +#: lib/block_scout_web/views/transaction_view.ex:316 +msgid "Token Minting" +msgstr "" diff --git a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po index 9e0a122b09..91a34cf880 100644 --- a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po +++ b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po @@ -13,7 +13,7 @@ msgstr[0] "" msgstr[1] "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:194 +#: lib/block_scout_web/templates/transaction/overview.html.eex:196 msgid " Token Transfer" msgstr "" @@ -59,7 +59,7 @@ msgid "%{subnetwork} Explorer - BlockScout" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:184 +#: lib/block_scout_web/views/transaction_view.ex:236 msgid "(Awaiting internal transactions for status)" msgstr "" @@ -183,7 +183,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/block/_link.html.eex:2 #: lib/block_scout_web/templates/internal_transaction/_tile.html.eex:28 -#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:48 +#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:57 msgid "Block #%{number}" msgstr "" @@ -218,7 +218,7 @@ msgid "Block Number" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:21 +#: lib/block_scout_web/views/transaction_view.ex:32 msgid "Block Pending" msgstr "" @@ -355,12 +355,12 @@ msgid "Contract Byte Code" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:262 +#: lib/block_scout_web/views/transaction_view.ex:325 msgid "Contract Call" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:261 +#: lib/block_scout_web/views/transaction_view.ex:322 msgid "Contract Creation" msgstr "" @@ -558,12 +558,12 @@ msgid "During times when the network is busy (i.e during ICOs) it can take a whi msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:84 +#: lib/block_scout_web/views/transaction_view.ex:136 msgid "ERC-20 " msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:85 +#: lib/block_scout_web/views/transaction_view.ex:137 msgid "ERC-721 " msgstr "" @@ -621,12 +621,12 @@ msgid "Error trying to fetch balances." msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:188 +#: lib/block_scout_web/views/transaction_view.ex:240 msgid "Error: %{reason}" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:186 +#: lib/block_scout_web/views/transaction_view.ex:238 msgid "Error: (Awaiting internal transactions for reason)" msgstr "" @@ -647,7 +647,7 @@ msgstr "" #: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:20 #: lib/block_scout_web/templates/transaction/_tile.html.eex:29 #: lib/block_scout_web/templates/transaction/overview.html.eex:181 -#: lib/block_scout_web/templates/transaction/overview.html.eex:216 +#: lib/block_scout_web/templates/transaction/overview.html.eex:255 #: lib/block_scout_web/views/wei_helpers.ex:78 msgid "Ether" msgstr "" @@ -776,7 +776,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/transaction/_emission_reward_tile.html.eex:8 -#: lib/block_scout_web/views/transaction_view.ex:185 +#: lib/block_scout_web/views/transaction_view.ex:237 msgid "Success" msgstr "" @@ -883,9 +883,9 @@ msgid "Token ID" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:5 -#: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:4 -#: lib/block_scout_web/views/transaction_view.ex:260 +#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:12 +#: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:10 +#: lib/block_scout_web/views/transaction_view.ex:318 msgid "Token Transfer" msgstr "" @@ -900,7 +900,7 @@ msgstr "" #: lib/block_scout_web/views/address_view.ex:314 #: lib/block_scout_web/views/tokens/instance/overview_view.ex:90 #: lib/block_scout_web/views/tokens/overview_view.ex:35 -#: lib/block_scout_web/views/transaction_view.ex:314 +#: lib/block_scout_web/views/transaction_view.ex:379 msgid "Token Transfers" msgstr "" @@ -916,7 +916,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address_logs/_logs.html.eex:18 -#: lib/block_scout_web/views/transaction_view.ex:263 +#: lib/block_scout_web/views/transaction_view.ex:328 msgid "Transaction" msgstr "" @@ -999,7 +999,7 @@ msgid "License ID" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:244 +#: lib/block_scout_web/templates/transaction/overview.html.eex:283 msgid "Limit" msgstr "" @@ -1041,8 +1041,8 @@ msgid "Market Cap" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:169 -#: lib/block_scout_web/views/transaction_view.ex:169 +#: lib/block_scout_web/views/transaction_view.ex:221 +#: lib/block_scout_web/views/transaction_view.ex:221 msgid "Max of" msgstr "" @@ -1154,8 +1154,8 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/layout/_topnav.html.eex:59 -#: lib/block_scout_web/views/transaction_view.ex:183 -#: lib/block_scout_web/views/transaction_view.ex:217 +#: lib/block_scout_web/views/transaction_view.ex:235 +#: lib/block_scout_web/views/transaction_view.ex:269 msgid "Pending" msgstr "" @@ -1203,7 +1203,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/transaction/_tabs.html.eex:24 #: lib/block_scout_web/templates/transaction_raw_trace/index.html.eex:7 -#: lib/block_scout_web/views/transaction_view.ex:317 +#: lib/block_scout_web/views/transaction_view.ex:382 msgid "Raw Trace" msgstr "" @@ -1539,7 +1539,7 @@ msgid "Use the search box to find a hosted network, or select from the list of a msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:238 +#: lib/block_scout_web/templates/transaction/overview.html.eex:277 msgid "Used" msgstr "" @@ -1570,7 +1570,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/transaction/overview.html.eex:181 -#: lib/block_scout_web/templates/transaction/overview.html.eex:216 +#: lib/block_scout_web/templates/transaction/overview.html.eex:255 msgid "Value" msgstr "" @@ -1747,7 +1747,7 @@ msgid "Decimals" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:234 +#: lib/block_scout_web/templates/transaction/overview.html.eex:273 msgid "Gas" msgstr "" @@ -1833,7 +1833,7 @@ msgstr "" #: lib/block_scout_web/templates/transaction/_tabs.html.eex:11 #: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:6 #: lib/block_scout_web/views/address_view.ex:313 -#: lib/block_scout_web/views/transaction_view.ex:315 +#: lib/block_scout_web/views/transaction_view.ex:380 msgid "Internal Transactions" msgstr "" @@ -1843,7 +1843,7 @@ msgstr "" #: lib/block_scout_web/templates/transaction/_tabs.html.eex:17 #: lib/block_scout_web/templates/transaction_log/index.html.eex:8 #: lib/block_scout_web/views/address_view.ex:320 -#: lib/block_scout_web/views/transaction_view.ex:316 +#: lib/block_scout_web/views/transaction_view.ex:381 msgid "Logs" msgstr "" @@ -1874,3 +1874,27 @@ msgstr "" #: lib/block_scout_web/views/address_view.ex:312 msgid "Transactions" msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/transaction/overview.html.eex:232 +msgid " Token Burning" +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:8 +#: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:6 +#: lib/block_scout_web/views/transaction_view.ex:317 +msgid "Token Burning" +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/transaction/overview.html.eex:214 +msgid " Token Minting" +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:10 +#: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:8 +#: lib/block_scout_web/views/transaction_view.ex:316 +msgid "Token Minting" +msgstr "" From ad9accef094e172066b8047db68e6b2a8f7db4d5 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Wed, 8 Apr 2020 16:38:03 +0300 Subject: [PATCH 3/5] Add CHANGELOG entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d902dc4ab5..ed57ac778d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### Features +- [#3067](https://github.com/poanetwork/blockscout/pull/3067) - Show proper title of the tile or container for token burnings/mintings instead of "Token Transfer" + ### Fixes - [#3064](https://github.com/poanetwork/blockscout/pull/3064) - Automatically define Block reward contract address in TokenBridge supply module From 4ceafdd99d3f86a81fb8c0a79cf68736668df37f Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Wed, 8 Apr 2020 16:54:27 +0300 Subject: [PATCH 4/5] Fix test --- .../controllers/recent_transactions_controller.ex | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/recent_transactions_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/recent_transactions_controller.ex index 3b9830476c..5057ac4f5d 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/recent_transactions_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/recent_transactions_controller.ex @@ -5,6 +5,9 @@ defmodule BlockScoutWeb.RecentTransactionsController do alias Explorer.Chain.Hash alias Phoenix.View + {:ok, burn_address_hash} = Chain.string_to_address_hash("0x0000000000000000000000000000000000000000") + @burn_address_hash burn_address_hash + def index(conn, _params) do if ajax?(conn) do recent_transactions = @@ -23,7 +26,11 @@ defmodule BlockScoutWeb.RecentTransactionsController do %{ transaction_hash: Hash.to_string(transaction.hash), transaction_html: - View.render_to_string(BlockScoutWeb.TransactionView, "_tile.html", transaction: transaction, conn: conn) + View.render_to_string(BlockScoutWeb.TransactionView, "_tile.html", + transaction: transaction, + burn_address_hash: @burn_address_hash, + conn: conn + ) } end) From 8cc05a3202294ee9a4bbc7b7d1893c20f7e8237a Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Wed, 8 Apr 2020 18:32:08 +0300 Subject: [PATCH 5/5] Make a link to address page on decoded constructor argumennt of address type --- CHANGELOG.md | 1 + .../templates/address_contract/index.html.eex | 2 +- .../views/address_contract_view.ex | 32 ++++++++++++++++--- apps/block_scout_web/priv/gettext/default.pot | 4 +-- .../priv/gettext/en/LC_MESSAGES/default.po | 4 +-- 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e3756ddd3..a4508c5523 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex index c84879dc9b..4d0cf6d063 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex @@ -53,7 +53,7 @@

<%= gettext "Constructor Arguments" %>

-
<%= raw(format_constructor_arguments(@address.smart_contract)) %>
+              
<%= raw(format_constructor_arguments(@address.smart_contract, @conn)) %>
               
diff --git a/apps/block_scout_web/lib/block_scout_web/views/address_contract_view.ex b/apps/block_scout_web/lib/block_scout_web/views/address_contract_view.ex index 5bb8b7cebb..527bb6eb97 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/address_contract_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/address_contract_view.ex @@ -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,11 +33,24 @@ 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 - Base.encode16(val, case: :lower) - else - val + cond do + type =~ "address" -> + get_formatted_address_data(address, address_hash, conn) + + type =~ "bytes" -> + Base.encode16(val, case: :lower) + + true -> + val end {count + 1, "#{acc}Arg [#{count}] (#{type}) : #{formatted_val}\n"} @@ -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 + "" <> address_hash <> "" + else + address_hash + end + end + defp decode_data("0x" <> encoded_data, types) do decode_data(encoded_data, types) end diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index 9e0a122b09..5bd6545e50 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -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 "" diff --git a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po index 9e0a122b09..5bd6545e50 100644 --- a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po +++ b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po @@ -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 ""