From 7148d5f9904b4d06b98935af6b3e8693412a891a Mon Sep 17 00:00:00 2001 From: Viktor Baranov Date: Fri, 23 Apr 2021 16:54:34 +0300 Subject: [PATCH] ERC-1155 finalization --- .../address_token_balance/_tokens.html.eex | 8 +- .../_link_to_token_instance.html.eex | 1 + .../_link_to_token_symbol.html.eex | 1 + .../transaction/_total_transfers.html.eex | 20 +++-- .../_transfer_token_with_id.html.eex | 2 + .../lib/block_scout_web/views/address_view.ex | 2 + .../block_scout_web/views/tokens/helpers.ex | 24 +++-- .../block_scout_web/views/transaction_view.ex | 22 ++++- apps/block_scout_web/priv/gettext/default.pot | 87 +++++++++++-------- .../priv/gettext/en/LC_MESSAGES/default.po | 87 +++++++++++-------- .../chain/address/current_token_balance.ex | 4 +- .../explorer/chain/address/token_balance.ex | 4 +- .../runner/address/current_token_balances.ex | 2 +- .../import/runner/address/token_balances.ex | 2 +- .../lib/explorer/chain/token_transfer.ex | 12 ++- ..._balances_add_token_id_to_unique_index.exs | 8 ++ ..._balances_add_token_id_to_unique_index.exs | 8 ++ ..._unfetched_token_balances_unique_index.exs | 23 +++++ ...108_extend_token_transfers_for_erc1155.exs | 10 +++ apps/indexer/lib/indexer/token_balances.ex | 10 ++- .../lib/indexer/transform/token_transfers.ex | 2 +- 21 files changed, 242 insertions(+), 97 deletions(-) create mode 100644 apps/block_scout_web/lib/block_scout_web/templates/transaction/_link_to_token_instance.html.eex create mode 100644 apps/block_scout_web/lib/block_scout_web/templates/transaction/_link_to_token_symbol.html.eex create mode 100644 apps/block_scout_web/lib/block_scout_web/templates/transaction/_transfer_token_with_id.html.eex create mode 100644 apps/explorer/priv/repo/migrations/20210423084253_address_current_token_balances_add_token_id_to_unique_index.exs create mode 100644 apps/explorer/priv/repo/migrations/20210423091652_address_token_balances_add_token_id_to_unique_index.exs create mode 100644 apps/explorer/priv/repo/migrations/20210423094801_address_token_balances_change_unfetched_token_balances_unique_index.exs create mode 100644 apps/explorer/priv/repo/migrations/20210423115108_extend_token_transfers_for_erc1155.exs diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_token_balance/_tokens.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_token_balance/_tokens.html.eex index 383be888bd..65c9caca56 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_token_balance/_tokens.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_token_balance/_tokens.html.eex @@ -10,8 +10,14 @@ data-token-name="<%= token_name(token_balance.token) %>" data-token-symbol="<%= token_balance.token.symbol %>" > + <% path = case token_balance.token_type do + "ERC-721" -> token_instance_path(@conn, :show, token_balance.token.contract_address_hash, to_string(token_balance.token_id)) + "ERC-1155" -> token_instance_path(@conn, :show, token_balance.token.contract_address_hash, to_string(token_balance.token_id)) + _ -> token_path(@conn, :show, to_string(token_balance.token.contract_address_hash)) + end + %> <%= link( - to: token_path(@conn, :show, to_string(token_balance.token.contract_address_hash)), + to: path, class: "dropdown-item" ) do %>
diff --git a/apps/block_scout_web/lib/block_scout_web/templates/transaction/_link_to_token_instance.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/transaction/_link_to_token_instance.html.eex new file mode 100644 index 0000000000..88273f4bc0 --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/templates/transaction/_link_to_token_instance.html.eex @@ -0,0 +1 @@ +<%= "[" %><%= link(short_token_id(@token_id, 30), to: token_instance_path(BlockScoutWeb.Endpoint, :show, @transfer.token.contract_address_hash, to_string(@token_id)), "data-test": "token_link") %><%= "]" %> \ No newline at end of file diff --git a/apps/block_scout_web/lib/block_scout_web/templates/transaction/_link_to_token_symbol.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/transaction/_link_to_token_symbol.html.eex new file mode 100644 index 0000000000..73cb4a2c2c --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/templates/transaction/_link_to_token_symbol.html.eex @@ -0,0 +1 @@ +<%= link(token_symbol(@transfer.token), to: token_path(BlockScoutWeb.Endpoint, :show, @transfer.token.contract_address_hash), "data-test": "token_link") %> \ No newline at end of file diff --git a/apps/block_scout_web/lib/block_scout_web/templates/transaction/_total_transfers.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/transaction/_total_transfers.html.eex index d056ea0536..fd9efa4435 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/transaction/_total_transfers.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/transaction/_total_transfers.html.eex @@ -1,15 +1,23 @@ <%= case token_transfer_amount(@transfer) do %> <% {:ok, :erc721_instance} -> %> - <%= "TokenID ["%><%= link(short_token_id(@transfer.token_id, 30), to: token_instance_path(BlockScoutWeb.Endpoint, :show, @transfer.token.contract_address_hash, to_string(@transfer.token_id)), "data-test": "token_link") %><%= "]" %> + <%= render BlockScoutWeb.TransactionView, "_transfer_token_with_id.html", transfer: @transfer, token_id: @transfer.token_id %> <% {:ok, :erc1155_instance, value} -> %> <% transfer_type = Chain.get_token_transfer_type(@transfer) %> <%= if transfer_type == :token_spawning do %> - <%= "TokenID ["%><%= link(short_token_id(@transfer.token_id, 30), to: token_instance_path(BlockScoutWeb.Endpoint, :show, @transfer.token.contract_address_hash, to_string(@transfer.token_id)), "data-test": "token_link") %><%= "]" %> + <%= render BlockScoutWeb.TransactionView, "_transfer_token_with_id.html", transfer: @transfer, token_id: @transfer.token_id %> <% else %> - <%= "#{value} TokenID ["%><%= link(short_token_id(@transfer.token_id, 30), to: token_instance_path(BlockScoutWeb.Endpoint, :show, @transfer.token.contract_address_hash, to_string(@transfer.token_id)), "data-test": "token_link") %><%= "]" %> + <%= "#{value} " %> + <%= render BlockScoutWeb.TransactionView, "_transfer_token_with_id.html", transfer: @transfer, token_id: @transfer.token_id %> + <% end %> + <% {:ok, :erc1155_instance, values, token_ids, _decimals} -> %> + <% values_ids = Enum.zip(values, token_ids) %> + <%= for {value, token_id} <- values_ids do %> +
+ <%= "#{value} "%> + <%= render BlockScoutWeb.TransactionView, "_transfer_token_with_id.html", transfer: @transfer, token_id: token_id %> +
<% end %> <% {:ok, value} -> %> <%= value %> -<% end %> -<%= " " %> -<%= link(token_symbol(@transfer.token), to: token_path(BlockScoutWeb.Endpoint, :show, @transfer.token.contract_address_hash), "data-test": "token_link") %> \ No newline at end of file + <%= " " %><%= render BlockScoutWeb.TransactionView, "_link_to_token_symbol.html", transfer: @transfer %> +<% end %> \ No newline at end of file diff --git a/apps/block_scout_web/lib/block_scout_web/templates/transaction/_transfer_token_with_id.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/transaction/_transfer_token_with_id.html.eex new file mode 100644 index 0000000000..44a3444aa1 --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/templates/transaction/_transfer_token_with_id.html.eex @@ -0,0 +1,2 @@ +<%= "TokenID " %><%= render BlockScoutWeb.TransactionView, "_link_to_token_instance.html", transfer: @transfer, token_id: @token_id %> +<%= " " %><%= render BlockScoutWeb.TransactionView, "_link_to_token_symbol.html", transfer: @transfer %> \ No newline at end of file diff --git a/apps/block_scout_web/lib/block_scout_web/views/address_view.ex b/apps/block_scout_web/lib/block_scout_web/views/address_view.ex index f0dc1ed29d..c2f735ee4b 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/address_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/address_view.ex @@ -406,6 +406,8 @@ defmodule BlockScoutWeb.AddressView do short_string(token_id, max_length) end + def short_string(nil, _max_length), do: "" + def short_string(name, max_length) do part_length = Kernel.trunc(max_length / 4) diff --git a/apps/block_scout_web/lib/block_scout_web/views/tokens/helpers.ex b/apps/block_scout_web/lib/block_scout_web/views/tokens/helpers.ex index f585fbd6ea..7b8d3276d6 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/tokens/helpers.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/tokens/helpers.ex @@ -16,31 +16,39 @@ defmodule BlockScoutWeb.Tokens.Helpers do When the token's type is ERC-721, the function will return a string with the token_id that represents the ERC-721 token since this kind of token doesn't have amount and decimals. """ + def token_transfer_amount(%{token: token, amount: amount, amounts: amounts, token_id: token_id, token_ids: token_ids}) do + do_token_transfer_amount(token, amount, amounts, token_id, token_ids) + end + def token_transfer_amount(%{token: token, amount: amount, token_id: token_id}) do - do_token_transfer_amount(token, amount, token_id) + do_token_transfer_amount(token, amount, nil, token_id, nil) end - defp do_token_transfer_amount(%Token{type: "ERC-20"}, nil, _token_id) do + defp do_token_transfer_amount(%Token{type: "ERC-20"}, nil, nil, _token_id, _token_ids) do {:ok, "--"} end - defp do_token_transfer_amount(%Token{type: "ERC-20", decimals: nil}, amount, _token_id) do + defp do_token_transfer_amount(%Token{type: "ERC-20", decimals: nil}, amount, _amounts, _token_id, _token_ids) do {:ok, CurrencyHelpers.format_according_to_decimals(amount, Decimal.new(0))} end - defp do_token_transfer_amount(%Token{type: "ERC-20", decimals: decimals}, amount, _token_id) do + defp do_token_transfer_amount(%Token{type: "ERC-20", decimals: decimals}, amount, _amounts, _token_id, _token_ids) do {:ok, CurrencyHelpers.format_according_to_decimals(amount, decimals)} end - defp do_token_transfer_amount(%Token{type: "ERC-721"}, _amount, _token_id) do + defp do_token_transfer_amount(%Token{type: "ERC-721"}, _amount, _amounts, _token_id, _token_ids) do {:ok, :erc721_instance} end - defp do_token_transfer_amount(%Token{type: "ERC-1155", decimals: decimals}, amount, _token_id) do - {:ok, :erc1155_instance, CurrencyHelpers.format_according_to_decimals(amount, decimals)} + defp do_token_transfer_amount(%Token{type: "ERC-1155", decimals: decimals}, amount, amounts, _token_id, token_ids) do + if amount do + {:ok, :erc1155_instance, CurrencyHelpers.format_according_to_decimals(amount, decimals)} + else + {:ok, :erc1155_instance, amounts, token_ids, decimals} + end end - defp do_token_transfer_amount(_token, _amount, _token_id) do + defp do_token_transfer_amount(_token, _amount, _amounts, _token_id, _token_ids) do nil 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 21fb441170..7258284084 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 @@ -138,11 +138,29 @@ defmodule BlockScoutWeb.TransactionView do %{transfers: transfers, mintings: mintings, burnings: burnings, creations: creations} end - defp aggregate_reducer(%{amount: amount} = token_transfer, {acc1, acc2}) when is_nil(amount) do + defp aggregate_reducer(%{amount: amount, amounts: amounts} = token_transfer, {acc1, acc2}) + when is_nil(amount) and is_nil(amounts) do new_entry = %{ token: token_transfer.token, amount: nil, + amounts: [], token_id: token_transfer.token_id, + token_ids: [], + to_address_hash: token_transfer.to_address_hash, + from_address_hash: token_transfer.from_address_hash + } + + {acc1, [new_entry | acc2]} + end + + defp aggregate_reducer(%{amount: amount, amounts: amounts} = token_transfer, {acc1, acc2}) + when is_nil(amount) and not is_nil(amounts) do + new_entry = %{ + token: token_transfer.token, + amount: nil, + amounts: amounts, + token_id: nil, + token_ids: token_transfer.token_ids, to_address_hash: token_transfer.to_address_hash, from_address_hash: token_transfer.from_address_hash } @@ -154,7 +172,9 @@ defmodule BlockScoutWeb.TransactionView do new_entry = %{ token: token_transfer.token, amount: token_transfer.amount, + amounts: [], token_id: token_transfer.token_id, + token_ids: [], to_address_hash: token_transfer.to_address_hash, from_address_hash: token_transfer.from_address_hash } diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index 0e10f98dd0..abfcdbb977 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -59,7 +59,7 @@ msgid "%{subnetwork} Explorer - BlockScout" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:262 +#: lib/block_scout_web/views/transaction_view.ex:310 msgid "(Awaiting internal transactions for status)" msgstr "" @@ -187,7 +187,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:50 +#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:43 msgid "Block #%{number}" msgstr "" @@ -222,7 +222,7 @@ msgid "Block Number" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:34 +#: lib/block_scout_web/views/transaction_view.ex:33 msgid "Block Pending" msgstr "" @@ -361,12 +361,12 @@ msgid "Contract Byte Code" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:351 +#: lib/block_scout_web/views/transaction_view.ex:400 msgid "Contract Call" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:348 +#: lib/block_scout_web/views/transaction_view.ex:397 msgid "Contract Creation" msgstr "" @@ -556,12 +556,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:148 +#: lib/block_scout_web/views/transaction_view.ex:195 msgid "ERC-20 " msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:149 +#: lib/block_scout_web/views/transaction_view.ex:196 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:266 +#: lib/block_scout_web/views/transaction_view.ex:314 msgid "Error: %{reason}" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:264 +#: lib/block_scout_web/views/transaction_view.ex:312 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:33 #: lib/block_scout_web/templates/transaction/overview.html.eex:215 -#: lib/block_scout_web/templates/transaction/overview.html.eex:268 +#: lib/block_scout_web/templates/transaction/overview.html.eex:279 #: lib/block_scout_web/views/wei_helpers.ex:78 msgid "Ether" msgstr "" @@ -777,7 +777,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/transaction/_emission_reward_tile.html.eex:8 -#: lib/block_scout_web/views/transaction_view.ex:263 +#: lib/block_scout_web/views/transaction_view.ex:311 msgid "Success" msgstr "" @@ -890,9 +890,10 @@ msgid "Token ID" msgstr "" #, elixir-format -#: 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:344 +#: +#: lib/block_scout_web/templates/common_components/_token_transfer_type_display_name.html.eex:9 +#: lib/block_scout_web/templates/common_components/_token_transfer_type_display_name.html.eex:11 +#: lib/block_scout_web/views/transaction_view.ex:393 msgid "Token Transfer" msgstr "" @@ -908,7 +909,7 @@ msgstr "" #: lib/block_scout_web/views/address_view.ex:346 #: lib/block_scout_web/views/tokens/instance/overview_view.ex:125 #: lib/block_scout_web/views/tokens/overview_view.ex:41 -#: lib/block_scout_web/views/transaction_view.ex:405 +#: lib/block_scout_web/views/transaction_view.ex:454 msgid "Token Transfers" msgstr "" @@ -923,8 +924,8 @@ msgid "Total Difficulty" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_logs/_logs.html.eex:25 -#: lib/block_scout_web/views/transaction_view.ex:354 +#: lib/block_scout_web/templates/address_logs/_logs.html.eex:18 +#: lib/block_scout_web/views/transaction_view.ex:403 msgid "Transaction" msgstr "" @@ -1006,7 +1007,7 @@ msgid "License ID" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:296 +#: lib/block_scout_web/templates/transaction/overview.html.eex:307 msgid "Limit" msgstr "" @@ -1049,7 +1050,7 @@ msgid "Market Cap" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:243 +#: lib/block_scout_web/views/transaction_view.ex:291 msgid "Max of" msgstr "" @@ -1164,8 +1165,8 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/layout/_topnav.html.eex:67 #: lib/block_scout_web/templates/stakes/_stakes_modal_delegators_list.html.eex:184 -#: lib/block_scout_web/views/transaction_view.ex:261 -#: lib/block_scout_web/views/transaction_view.ex:295 +#: lib/block_scout_web/views/transaction_view.ex:309 +#: lib/block_scout_web/views/transaction_view.ex:343 msgid "Pending" msgstr "" @@ -1210,7 +1211,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:408 +#: lib/block_scout_web/views/transaction_view.ex:457 msgid "Raw Trace" msgstr "" @@ -1543,7 +1544,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:290 +#: lib/block_scout_web/templates/transaction/overview.html.eex:301 msgid "Used" msgstr "" @@ -1574,7 +1575,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/transaction/overview.html.eex:215 -#: lib/block_scout_web/templates/transaction/overview.html.eex:268 +#: lib/block_scout_web/templates/transaction/overview.html.eex:279 msgid "Value" msgstr "" @@ -1755,7 +1756,7 @@ msgid "Decimals" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:286 +#: lib/block_scout_web/templates/transaction/overview.html.eex:297 msgid "Gas" msgstr "" @@ -1841,7 +1842,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:344 -#: lib/block_scout_web/views/transaction_view.ex:406 +#: lib/block_scout_web/views/transaction_view.ex:455 msgid "Internal Transactions" msgstr "" @@ -1851,7 +1852,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:355 -#: lib/block_scout_web/views/transaction_view.ex:407 +#: lib/block_scout_web/views/transaction_view.ex:456 msgid "Logs" msgstr "" @@ -1886,26 +1887,26 @@ msgid "Transactions" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:252 +#: lib/block_scout_web/templates/transaction/overview.html.eex:250 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:343 +#: +#: lib/block_scout_web/templates/common_components/_token_transfer_type_display_name.html.eex:3 +#: lib/block_scout_web/views/transaction_view.ex:391 msgid "Token Burning" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:241 +#: lib/block_scout_web/templates/transaction/overview.html.eex:240 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:342 +#: +#: lib/block_scout_web/templates/common_components/_token_transfer_type_display_name.html.eex:5 +#: lib/block_scout_web/views/transaction_view.ex:390 msgid "Token Minting" msgstr "" @@ -2786,6 +2787,16 @@ msgstr "" msgid "Next" msgstr "" +#, elixir-format +#: lib/block_scout_web/templates/transaction/overview.html.eex:261 +msgid " Token Creation" +msgstr "" + +#, elixir-format +#: lib/block_scout_web/views/transaction_view.ex:197 +msgid "ERC-1155 " +msgstr "" + #, elixir-format #: #: lib/block_scout_web/templates/address_contract_verification_via_json/new.html.eex:23 @@ -2801,3 +2812,9 @@ msgstr "" #: lib/block_scout_web/templates/address_contract/index.html.eex:31 msgid "This contract has been verified via Sourcify." msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/common_components/_token_transfer_type_display_name.html.eex:7 +#: lib/block_scout_web/views/transaction_view.ex:392 +msgid "Token Creation" +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 0e10f98dd0..89044ee647 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 @@ -59,7 +59,7 @@ msgid "%{subnetwork} Explorer - BlockScout" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:262 +#: lib/block_scout_web/views/transaction_view.ex:310 msgid "(Awaiting internal transactions for status)" msgstr "" @@ -187,7 +187,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:50 +#: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:43 msgid "Block #%{number}" msgstr "" @@ -222,7 +222,7 @@ msgid "Block Number" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:34 +#: lib/block_scout_web/views/transaction_view.ex:33 msgid "Block Pending" msgstr "" @@ -361,12 +361,12 @@ msgid "Contract Byte Code" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:351 +#: lib/block_scout_web/views/transaction_view.ex:400 msgid "Contract Call" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:348 +#: lib/block_scout_web/views/transaction_view.ex:397 msgid "Contract Creation" msgstr "" @@ -556,12 +556,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:148 +#: lib/block_scout_web/views/transaction_view.ex:195 msgid "ERC-20 " msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:149 +#: lib/block_scout_web/views/transaction_view.ex:196 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:266 +#: lib/block_scout_web/views/transaction_view.ex:314 msgid "Error: %{reason}" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:264 +#: lib/block_scout_web/views/transaction_view.ex:312 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:33 #: lib/block_scout_web/templates/transaction/overview.html.eex:215 -#: lib/block_scout_web/templates/transaction/overview.html.eex:268 +#: lib/block_scout_web/templates/transaction/overview.html.eex:279 #: lib/block_scout_web/views/wei_helpers.ex:78 msgid "Ether" msgstr "" @@ -777,7 +777,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/transaction/_emission_reward_tile.html.eex:8 -#: lib/block_scout_web/views/transaction_view.ex:263 +#: lib/block_scout_web/views/transaction_view.ex:311 msgid "Success" msgstr "" @@ -890,9 +890,10 @@ msgid "Token ID" msgstr "" #, elixir-format -#: 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:344 +#: +#: lib/block_scout_web/templates/common_components/_token_transfer_type_display_name.html.eex:9 +#: lib/block_scout_web/templates/common_components/_token_transfer_type_display_name.html.eex:11 +#: lib/block_scout_web/views/transaction_view.ex:393 msgid "Token Transfer" msgstr "" @@ -908,7 +909,7 @@ msgstr "" #: lib/block_scout_web/views/address_view.ex:346 #: lib/block_scout_web/views/tokens/instance/overview_view.ex:125 #: lib/block_scout_web/views/tokens/overview_view.ex:41 -#: lib/block_scout_web/views/transaction_view.ex:405 +#: lib/block_scout_web/views/transaction_view.ex:454 msgid "Token Transfers" msgstr "" @@ -923,8 +924,8 @@ msgid "Total Difficulty" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_logs/_logs.html.eex:25 -#: lib/block_scout_web/views/transaction_view.ex:354 +#: lib/block_scout_web/templates/address_logs/_logs.html.eex:18 +#: lib/block_scout_web/views/transaction_view.ex:403 msgid "Transaction" msgstr "" @@ -1006,7 +1007,7 @@ msgid "License ID" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:296 +#: lib/block_scout_web/templates/transaction/overview.html.eex:307 msgid "Limit" msgstr "" @@ -1049,7 +1050,7 @@ msgid "Market Cap" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:243 +#: lib/block_scout_web/views/transaction_view.ex:291 msgid "Max of" msgstr "" @@ -1164,8 +1165,8 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/layout/_topnav.html.eex:67 #: lib/block_scout_web/templates/stakes/_stakes_modal_delegators_list.html.eex:184 -#: lib/block_scout_web/views/transaction_view.ex:261 -#: lib/block_scout_web/views/transaction_view.ex:295 +#: lib/block_scout_web/views/transaction_view.ex:309 +#: lib/block_scout_web/views/transaction_view.ex:343 msgid "Pending" msgstr "" @@ -1210,7 +1211,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:408 +#: lib/block_scout_web/views/transaction_view.ex:457 msgid "Raw Trace" msgstr "" @@ -1543,7 +1544,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:290 +#: lib/block_scout_web/templates/transaction/overview.html.eex:301 msgid "Used" msgstr "" @@ -1574,7 +1575,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/transaction/overview.html.eex:215 -#: lib/block_scout_web/templates/transaction/overview.html.eex:268 +#: lib/block_scout_web/templates/transaction/overview.html.eex:279 msgid "Value" msgstr "" @@ -1755,7 +1756,7 @@ msgid "Decimals" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:286 +#: lib/block_scout_web/templates/transaction/overview.html.eex:297 msgid "Gas" msgstr "" @@ -1841,7 +1842,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:344 -#: lib/block_scout_web/views/transaction_view.ex:406 +#: lib/block_scout_web/views/transaction_view.ex:455 msgid "Internal Transactions" msgstr "" @@ -1851,7 +1852,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:355 -#: lib/block_scout_web/views/transaction_view.ex:407 +#: lib/block_scout_web/views/transaction_view.ex:456 msgid "Logs" msgstr "" @@ -1886,26 +1887,26 @@ msgid "Transactions" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:252 +#: lib/block_scout_web/templates/transaction/overview.html.eex:250 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:343 +#: +#: lib/block_scout_web/templates/common_components/_token_transfer_type_display_name.html.eex:3 +#: lib/block_scout_web/views/transaction_view.ex:391 msgid "Token Burning" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:241 +#: lib/block_scout_web/templates/transaction/overview.html.eex:240 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:342 +#: +#: lib/block_scout_web/templates/common_components/_token_transfer_type_display_name.html.eex:5 +#: lib/block_scout_web/views/transaction_view.ex:390 msgid "Token Minting" msgstr "" @@ -2786,6 +2787,16 @@ msgstr "" msgid "Next" msgstr "" +#, elixir-format +#: lib/block_scout_web/templates/transaction/overview.html.eex:261 +msgid " Token Creation" +msgstr "" + +#, elixir-format, fuzzy +#: lib/block_scout_web/views/transaction_view.ex:197 +msgid "ERC-1155 " +msgstr "" + #, elixir-format #: #: lib/block_scout_web/templates/address_contract_verification_via_json/new.html.eex:23 @@ -2801,3 +2812,9 @@ msgstr "" #: lib/block_scout_web/templates/address_contract/index.html.eex:31 msgid "This contract has been verified via Sourcify." msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/common_components/_token_transfer_type_display_name.html.eex:7 +#: lib/block_scout_web/views/transaction_view.ex:392 +msgid "Token Creation" +msgstr "" diff --git a/apps/explorer/lib/explorer/chain/address/current_token_balance.ex b/apps/explorer/lib/explorer/chain/address/current_token_balance.ex index 590bdf9a5d..63c2b13521 100644 --- a/apps/explorer/lib/explorer/chain/address/current_token_balance.ex +++ b/apps/explorer/lib/explorer/chain/address/current_token_balance.ex @@ -34,7 +34,9 @@ defmodule Explorer.Chain.Address.CurrentTokenBalance do block_number: Block.block_number(), inserted_at: DateTime.t(), updated_at: DateTime.t(), - value: Decimal.t() | nil + value: Decimal.t() | nil, + token_id: non_neg_integer() | nil, + token_type: String.t() } schema "address_current_token_balances" do diff --git a/apps/explorer/lib/explorer/chain/address/token_balance.ex b/apps/explorer/lib/explorer/chain/address/token_balance.ex index 96b0cb1462..cc0d579da1 100644 --- a/apps/explorer/lib/explorer/chain/address/token_balance.ex +++ b/apps/explorer/lib/explorer/chain/address/token_balance.ex @@ -34,7 +34,9 @@ defmodule Explorer.Chain.Address.TokenBalance do block_number: Block.block_number(), inserted_at: DateTime.t(), updated_at: DateTime.t(), - value: Decimal.t() | nil + value: Decimal.t() | nil, + token_id: non_neg_integer() | nil, + token_type: String.t() } schema "address_token_balances" do diff --git a/apps/explorer/lib/explorer/chain/import/runner/address/current_token_balances.ex b/apps/explorer/lib/explorer/chain/import/runner/address/current_token_balances.ex index ce3a22a365..1245245ebb 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/address/current_token_balances.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/address/current_token_balances.ex @@ -206,7 +206,7 @@ defmodule Explorer.Chain.Import.Runner.Address.CurrentTokenBalances do Import.insert_changes_list( repo, ordered_changes_list, - conflict_target: ~w(address_hash token_contract_address_hash)a, + conflict_target: ~w(address_hash token_contract_address_hash token_id)a, on_conflict: on_conflict, for: CurrentTokenBalance, returning: true, diff --git a/apps/explorer/lib/explorer/chain/import/runner/address/token_balances.ex b/apps/explorer/lib/explorer/chain/import/runner/address/token_balances.ex index 8189a5845c..b21cadff6f 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/address/token_balances.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/address/token_balances.ex @@ -67,7 +67,7 @@ defmodule Explorer.Chain.Import.Runner.Address.TokenBalances do Import.insert_changes_list( repo, ordered_changes_list, - conflict_target: ~w(address_hash token_contract_address_hash block_number)a, + conflict_target: ~w(address_hash token_contract_address_hash token_id block_number)a, on_conflict: on_conflict, for: TokenBalance, returning: true, diff --git a/apps/explorer/lib/explorer/chain/token_transfer.ex b/apps/explorer/lib/explorer/chain/token_transfer.ex index 38c7318192..34ab5076c0 100644 --- a/apps/explorer/lib/explorer/chain/token_transfer.ex +++ b/apps/explorer/lib/explorer/chain/token_transfer.ex @@ -47,9 +47,11 @@ defmodule Explorer.Chain.TokenTransfer do * `:transaction` - The `t:Explorer.Chain.Transaction.t/0` ledger * `:transaction_hash` - Transaction foreign key * `:log_index` - Index of the corresponding `t:Explorer.Chain.Log.t/0` in the transaction. + * `:amounts` - Tokens transferred amounts in case of batched transfer in ERC-1155 + * `:token_ids` - IDs of the tokens (applicable to ERC-1155 tokens) """ @type t :: %TokenTransfer{ - amount: Decimal.t(), + amount: Decimal.t() | nil, block_number: non_neg_integer() | nil, block_hash: Hash.Full.t(), from_address: %Ecto.Association.NotLoaded{} | Address.t(), @@ -61,7 +63,9 @@ defmodule Explorer.Chain.TokenTransfer do token_id: non_neg_integer() | nil, transaction: %Ecto.Association.NotLoaded{} | Transaction.t(), transaction_hash: Hash.Full.t(), - log_index: non_neg_integer() + log_index: non_neg_integer(), + amounts: [Decimal.t()] | nil, + token_ids: [non_neg_integer()] | nil } @typep paging_options :: {:paging_options, PagingOptions.t()} @@ -78,6 +82,8 @@ defmodule Explorer.Chain.TokenTransfer do field(:block_number, :integer) field(:log_index, :integer, primary_key: true) field(:token_id, :decimal) + field(:amounts, {:array, :decimal}) + field(:token_ids, {:array, :decimal}) belongs_to(:from_address, Address, foreign_key: :from_address_hash, references: :hash, type: Hash.Address) belongs_to(:to_address, Address, foreign_key: :to_address_hash, references: :hash, type: Hash.Address) @@ -117,7 +123,7 @@ defmodule Explorer.Chain.TokenTransfer do end @required_attrs ~w(block_number log_index from_address_hash to_address_hash token_contract_address_hash transaction_hash block_hash)a - @optional_attrs ~w(amount token_id)a + @optional_attrs ~w(amount token_id amounts token_ids)a @doc false def changeset(%TokenTransfer{} = struct, params \\ %{}) do diff --git a/apps/explorer/priv/repo/migrations/20210423084253_address_current_token_balances_add_token_id_to_unique_index.exs b/apps/explorer/priv/repo/migrations/20210423084253_address_current_token_balances_add_token_id_to_unique_index.exs new file mode 100644 index 0000000000..b256010800 --- /dev/null +++ b/apps/explorer/priv/repo/migrations/20210423084253_address_current_token_balances_add_token_id_to_unique_index.exs @@ -0,0 +1,8 @@ +defmodule Explorer.Repo.Migrations.AddressCurrentTokenBalancesAddTokenIdToUniqueIndex do + use Ecto.Migration + + def change do + drop(unique_index(:address_current_token_balances, ~w(address_hash token_contract_address_hash)a)) + create(unique_index(:address_current_token_balances, ~w(address_hash token_contract_address_hash token_id)a)) + end +end diff --git a/apps/explorer/priv/repo/migrations/20210423091652_address_token_balances_add_token_id_to_unique_index.exs b/apps/explorer/priv/repo/migrations/20210423091652_address_token_balances_add_token_id_to_unique_index.exs new file mode 100644 index 0000000000..d4b406f95a --- /dev/null +++ b/apps/explorer/priv/repo/migrations/20210423091652_address_token_balances_add_token_id_to_unique_index.exs @@ -0,0 +1,8 @@ +defmodule Explorer.Repo.Migrations.AddressTokenBalancesAddTokenIdToUniqueIndex do + use Ecto.Migration + + def change do + drop(unique_index(:address_token_balances, ~w(address_hash token_contract_address_hash block_number)a)) + create(unique_index(:address_token_balances, ~w(address_hash token_contract_address_hash token_id block_number)a)) + end +end diff --git a/apps/explorer/priv/repo/migrations/20210423094801_address_token_balances_change_unfetched_token_balances_unique_index.exs b/apps/explorer/priv/repo/migrations/20210423094801_address_token_balances_change_unfetched_token_balances_unique_index.exs new file mode 100644 index 0000000000..57a1806684 --- /dev/null +++ b/apps/explorer/priv/repo/migrations/20210423094801_address_token_balances_change_unfetched_token_balances_unique_index.exs @@ -0,0 +1,23 @@ +defmodule Explorer.Repo.Migrations.AddressTokenBalancesChangeUnfetchedTokenBalancesUniqueIndex do + use Ecto.Migration + + def change do + drop( + unique_index( + :address_token_balances, + ~w(address_hash token_contract_address_hash block_number)a, + name: :unfetched_token_balances, + where: "value_fetched_at IS NULL" + ) + ) + + create( + unique_index( + :address_token_balances, + ~w(address_hash token_contract_address_hash token_id block_number)a, + name: :unfetched_token_balances, + where: "value_fetched_at IS NULL" + ) + ) + end +end diff --git a/apps/explorer/priv/repo/migrations/20210423115108_extend_token_transfers_for_erc1155.exs b/apps/explorer/priv/repo/migrations/20210423115108_extend_token_transfers_for_erc1155.exs new file mode 100644 index 0000000000..211524e954 --- /dev/null +++ b/apps/explorer/priv/repo/migrations/20210423115108_extend_token_transfers_for_erc1155.exs @@ -0,0 +1,10 @@ +defmodule Explorer.Repo.Migrations.ExtendTokenTransfersForErc1155 do + use Ecto.Migration + + def change do + alter table(:token_transfers) do + add(:amounts, {:array, :decimal}, null: true) + add(:token_ids, {:array, :numeric}, precision: 78, scale: 0, null: true) + end + end +end diff --git a/apps/indexer/lib/indexer/token_balances.ex b/apps/indexer/lib/indexer/token_balances.ex index 921ae1d49a..6b0aab725a 100644 --- a/apps/indexer/lib/indexer/token_balances.ex +++ b/apps/indexer/lib/indexer/token_balances.ex @@ -53,13 +53,17 @@ defmodule Indexer.TokenBalances do def to_address_current_token_balances(address_token_balances) when is_list(address_token_balances) do address_token_balances - |> Enum.group_by(fn %{address_hash: address_hash, token_contract_address_hash: token_contract_address_hash} -> - {address_hash, token_contract_address_hash} + |> Enum.group_by(fn %{ + address_hash: address_hash, + token_contract_address_hash: token_contract_address_hash, + token_id: token_id + } -> + {address_hash, token_contract_address_hash, token_id} end) |> Enum.map(fn {_, grouped_address_token_balances} -> Enum.max_by(grouped_address_token_balances, fn %{block_number: block_number} -> block_number end) end) - |> Enum.sort_by(&{&1.token_contract_address_hash, &1.address_hash}) + |> Enum.sort_by(&{&1.token_contract_address_hash, &1.token_id, &1.address_hash}) end defp set_token_balance_value({:ok, balance}, token_balance) do diff --git a/apps/indexer/lib/indexer/transform/token_transfers.ex b/apps/indexer/lib/indexer/transform/token_transfers.ex index 060f05c5d3..b445a5e724 100644 --- a/apps/indexer/lib/indexer/transform/token_transfers.ex +++ b/apps/indexer/lib/indexer/transform/token_transfers.ex @@ -187,7 +187,7 @@ defmodule Indexer.Transform.TokenTransfers do token_type: "ERC-1155", token_ids: token_ids, token_id: nil, - values: values + amounts: values } token = %{