diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c65d4c942..a63e6c2e1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,12 @@ - [#2151](https://github.com/poanetwork/blockscout/pull/2151) - hide dropdown menu then other networks list is empty - [#2191](https://github.com/poanetwork/blockscout/pull/2191) - allow to configure token metadata update interval - [#2146](https://github.com/poanetwork/blockscout/pull/2146) - feat: add eth_getLogs rpc endpoint +- [#2190](https://github.com/poanetwork/blockscout/pull/2190) - show all token transfers +- [#2193](https://github.com/poanetwork/blockscout/pull/2193) - feat: add BLOCKSCOUT_HOST, and use it in API docs ### Fixes - [#2242](https://github.com/poanetwork/blockscout/pull/2242) - added styles for 'download csv' button +- [#2254](https://github.com/poanetwork/blockscout/pull/2254) - search length issue, tile link wrapping issue - [#2238](https://github.com/poanetwork/blockscout/pull/2238) - header content alignment issue, hide navbar on outside click - [#2229](https://github.com/poanetwork/blockscout/pull/2229) - gap issue between qr and copy button in token transfers, top cards width and height issue - [#2201](https://github.com/poanetwork/blockscout/pull/2201) - footer columns fix diff --git a/apps/block_scout_web/assets/css/components/_navbar.scss b/apps/block_scout_web/assets/css/components/_navbar.scss index 1058c529c6..b8855a63ae 100644 --- a/apps/block_scout_web/assets/css/components/_navbar.scss +++ b/apps/block_scout_web/assets/css/components/_navbar.scss @@ -151,19 +151,13 @@ $navbar-logo-width: auto !default; } @include media-breakpoint-up(xl) { - width: 280px; + width: 340px; } @media (min-width: 1366px) { - width: 330px; + width: 500px; } @media (min-width: 1440px) { - width: 380px; - } - @media (min-width: 1580px) { - width: 430px; - } - @media (min-width: 1800px) { - width: 520px; + width: 580px; } } .input-group-append { diff --git a/apps/block_scout_web/config/config.exs b/apps/block_scout_web/config/config.exs index e601e299f8..28d142eb5c 100644 --- a/apps/block_scout_web/config/config.exs +++ b/apps/block_scout_web/config/config.exs @@ -41,7 +41,7 @@ config :block_scout_web, BlockScoutWeb.Endpoint, ] ], url: [ - host: "localhost", + host: System.get_env("BLOCKSCOUT_HOST") || "localhost", path: System.get_env("NETWORK_PATH") || "/" ], render_errors: [view: BlockScoutWeb.ErrorView, accepts: ~w(html json)], diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address/_responsive_hash.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address/_responsive_hash.html.eex index 22e0f76870..cad11f8ee6 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address/_responsive_hash.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address/_responsive_hash.html.eex @@ -5,8 +5,8 @@ <%= if assigns[:truncate] do %> <%= BlockScoutWeb.AddressView.trimmed_hash(@address.hash) %> <% else %> - <%= @address %> - <%= BlockScoutWeb.AddressView.trimmed_hash(@address.hash) %> + <%= @address %> + <%= BlockScoutWeb.AddressView.trimmed_hash(@address.hash) %> <% end %> <% end %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/api_docs/eth_rpc.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/api_docs/eth_rpc.html.eex index f85620681a..37b9ecdaa2 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/api_docs/eth_rpc.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/api_docs/eth_rpc.html.eex @@ -2,9 +2,9 @@

<%= gettext("ETH RPC API Documentation") %>

-

[ <%= gettext "Base URL:" %> <%= @conn.host %>/api/eth_rpc ]

+

[ <%= gettext "Base URL:" %> <%= url() %>/api/eth_rpc ]

- <%= gettext "This API is provided to support some rpc methods in the exact format specified for ethereum nodes, which can be found " %> + <%= gettext "This API is provided to support some rpc methods in the exact format specified for ethereum nodes, which can be found " %> <%= gettext "here." %> <%= gettext "This is useful to allow sending requests to blockscout without having to change anything about the request." %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/api_docs/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/api_docs/index.html.eex index c665fb88e6..5244458bb6 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/api_docs/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/api_docs/index.html.eex @@ -2,7 +2,7 @@

<%= gettext("API Documentation") %>

-

[ <%= gettext "Base URL:" %> <%= @conn.host %>/api ]

+

[ <%= gettext "Base URL:" %> <%= url() %>/api ]

<%= gettext "This API is provided for developers transitioning their applications from Etherscan to BlockScout. It supports GET and POST requests." %>

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 396b8dd7c0..fe347ee904 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 @@ -170,17 +170,21 @@
<%= case token_transfer_type(@transaction) do %> - <% {type, token_transfer} -> %> + <% {type, transaction_with_transfers} when is_atom(type) -> %>
-

<%= if type == :erc20, do: gettext("ERC-20"), else: gettext("ERC-721")%><%= gettext " Token Transfer" %>

+

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

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

- <%= token_transfer_amount(token_transfer) %> - <%= link(token_symbol(token_transfer.token), to: token_path(BlockScoutWeb.Endpoint, :show, token_transfer.token.contract_address_hash)) %> + <%= token_transfer_amount(transfer) %> + <%= link(token_symbol(transfer.token), to: token_path(BlockScoutWeb.Endpoint, :show, transfer.token.contract_address_hash)) %>

+ + <% end %>
diff --git a/apps/block_scout_web/lib/block_scout_web/views/api_docs_view.ex b/apps/block_scout_web/lib/block_scout_web/views/api_docs_view.ex index cbc096aeb8..267099fa2b 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/api_docs_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/api_docs_view.ex @@ -1,7 +1,7 @@ defmodule BlockScoutWeb.APIDocsView do use BlockScoutWeb, :view - alias BlockScoutWeb.LayoutView + alias BlockScoutWeb.{Endpoint, LayoutView} def action_tile_id(module, action) do "#{module}-#{action}" @@ -33,4 +33,12 @@ defmodule BlockScoutWeb.APIDocsView do "&#{param.key}=" <> "{#{param.placeholder}}" end) end + + defp url do + if System.get_env("BLOCKSCOUT_HOST") do + "http://" <> System.get_env("BLOCKSCOUT_HOST") + else + Endpoint.url() + end + end 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 026147ac3e..1ed50d28ab 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 @@ -3,7 +3,7 @@ defmodule BlockScoutWeb.TransactionView do alias BlockScoutWeb.{AddressView, BlockView, TabHelpers} alias Cldr.Number - alias Explorer.Chain + alias Explorer.{Chain, Repo} alias Explorer.Chain.Block.Reward alias Explorer.Chain.{Address, Block, InternalTransaction, Transaction, Wei} alias Explorer.ExchangeRates.Token @@ -33,7 +33,18 @@ defmodule BlockScoutWeb.TransactionView do def value_transfer?(_), do: false def token_transfer_type(transaction) do - Chain.transaction_token_transfer_type(transaction) + transaction_with_transfers = Repo.preload(transaction, token_transfers: :token) + + type = Chain.transaction_token_transfer_type(transaction) + if type, do: {type, transaction_with_transfers} + end + + def token_type_name(type) do + case type do + :erc20 -> gettext("ERC-20 ") + :erc721 -> gettext("ERC-721 ") + :token_transfer -> "" + end end def processing_time_duration(%Transaction{block: nil}) do diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index a0c6482690..ff2262709a 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -49,7 +49,7 @@ msgid "%{subnetwork} Explorer - BlockScout" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:133 +#: lib/block_scout_web/views/transaction_view.ex:144 msgid "(Awaiting internal transactions for status)" msgstr "" @@ -275,12 +275,12 @@ msgid "Contract Address Pending" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:210 +#: lib/block_scout_web/views/transaction_view.ex:221 msgid "Contract Call" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:209 +#: lib/block_scout_web/views/transaction_view.ex:220 msgid "Contract Creation" msgstr "" @@ -363,12 +363,12 @@ msgid "Error trying to fetch balances." msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:137 +#: lib/block_scout_web/views/transaction_view.ex:148 msgid "Error: %{reason}" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:135 +#: lib/block_scout_web/views/transaction_view.ex:146 msgid "Error: (Awaiting internal transactions for reason)" msgstr "" @@ -378,7 +378,7 @@ msgstr "" #: lib/block_scout_web/templates/layout/app.html.eex:55 #: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:20 #: lib/block_scout_web/templates/transaction/_tile.html.eex:30 -#: lib/block_scout_web/templates/transaction/overview.html.eex:192 +#: lib/block_scout_web/templates/transaction/overview.html.eex:196 #: lib/block_scout_web/views/wei_helpers.ex:78 msgid "Ether" msgstr "" @@ -473,7 +473,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:306 -#: lib/block_scout_web/views/transaction_view.ex:263 +#: lib/block_scout_web/views/transaction_view.ex:274 msgid "Internal Transactions" msgstr "" @@ -490,7 +490,7 @@ msgid "Less than" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:220 +#: lib/block_scout_web/templates/transaction/overview.html.eex:224 msgid "Limit" msgstr "" @@ -500,7 +500,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:312 -#: lib/block_scout_web/views/transaction_view.ex:264 +#: lib/block_scout_web/views/transaction_view.ex:275 msgid "Logs" msgstr "" @@ -512,7 +512,7 @@ msgid "Market Cap" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:118 +#: lib/block_scout_web/views/transaction_view.ex:129 msgid "Max of" msgstr "" @@ -602,8 +602,8 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/layout/_topnav.html.eex:44 -#: lib/block_scout_web/views/transaction_view.ex:132 -#: lib/block_scout_web/views/transaction_view.ex:166 +#: lib/block_scout_web/views/transaction_view.ex:143 +#: lib/block_scout_web/views/transaction_view.ex:177 msgid "Pending" msgstr "" @@ -690,7 +690,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/transaction/_emission_reward_tile.html.eex:8 -#: lib/block_scout_web/views/transaction_view.ex:134 +#: lib/block_scout_web/views/transaction_view.ex:145 msgid "Success" msgstr "" @@ -795,7 +795,7 @@ 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:208 +#: lib/block_scout_web/views/transaction_view.ex:219 msgid "Token Transfer" msgstr "" @@ -805,7 +805,7 @@ msgstr "" #: lib/block_scout_web/templates/transaction/_tabs.html.eex:4 #: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7 #: lib/block_scout_web/views/tokens/overview_view.ex:35 -#: lib/block_scout_web/views/transaction_view.ex:262 +#: lib/block_scout_web/views/transaction_view.ex:273 msgid "Token Transfers" msgstr "" @@ -845,7 +845,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address_logs/_logs.html.eex:3 -#: lib/block_scout_web/views/transaction_view.ex:211 +#: lib/block_scout_web/views/transaction_view.ex:222 msgid "Transaction" msgstr "" @@ -907,7 +907,7 @@ msgid "Unique Token" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:214 +#: lib/block_scout_web/templates/transaction/overview.html.eex:218 msgid "Used" msgstr "" @@ -927,7 +927,7 @@ msgid "Validations" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:192 +#: lib/block_scout_web/templates/transaction/overview.html.eex:196 msgid "Value" msgstr "" @@ -1520,16 +1520,6 @@ msgstr "" msgid "Optimization runs" msgstr "" -#, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:178 -msgid "ERC-20" -msgstr "" - -#, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:178 -msgid "ERC-721" -msgstr "" - #, elixir-format #: lib/block_scout_web/templates/api_docs/index.html.eex:4 msgid "API Documentation" @@ -1546,14 +1536,14 @@ msgid "View All Transactions" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:210 +#: lib/block_scout_web/templates/transaction/overview.html.eex:214 msgid "Gas" 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:265 +#: lib/block_scout_web/views/transaction_view.ex:276 msgid "Raw Trace" msgstr "" @@ -1709,6 +1699,16 @@ msgstr "" msgid "Anything not in this list is not supported. Click on the method to be taken to the documentation for that method, and check the notes section for any potential differences." msgstr "" +#, elixir-format +#: lib/block_scout_web/views/transaction_view.ex:44 +msgid "ERC-20 " +msgstr "" + +#, elixir-format +#: lib/block_scout_web/views/transaction_view.ex:45 +msgid "ERC-721 " +msgstr "" + #, elixir-format #: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:4 msgid "ETH RPC API Documentation" 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 f114a87464..2c6736bc90 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 @@ -49,7 +49,7 @@ msgid "%{subnetwork} Explorer - BlockScout" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:133 +#: lib/block_scout_web/views/transaction_view.ex:144 msgid "(Awaiting internal transactions for status)" msgstr "" @@ -275,12 +275,12 @@ msgid "Contract Address Pending" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:210 +#: lib/block_scout_web/views/transaction_view.ex:221 msgid "Contract Call" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:209 +#: lib/block_scout_web/views/transaction_view.ex:220 msgid "Contract Creation" msgstr "" @@ -363,12 +363,12 @@ msgid "Error trying to fetch balances." msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:137 +#: lib/block_scout_web/views/transaction_view.ex:148 msgid "Error: %{reason}" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:135 +#: lib/block_scout_web/views/transaction_view.ex:146 msgid "Error: (Awaiting internal transactions for reason)" msgstr "" @@ -378,7 +378,7 @@ msgstr "" #: lib/block_scout_web/templates/layout/app.html.eex:55 #: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:20 #: lib/block_scout_web/templates/transaction/_tile.html.eex:30 -#: lib/block_scout_web/templates/transaction/overview.html.eex:192 +#: lib/block_scout_web/templates/transaction/overview.html.eex:196 #: lib/block_scout_web/views/wei_helpers.ex:78 msgid "Ether" msgstr "POA" @@ -473,7 +473,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:306 -#: lib/block_scout_web/views/transaction_view.ex:263 +#: lib/block_scout_web/views/transaction_view.ex:274 msgid "Internal Transactions" msgstr "" @@ -490,7 +490,7 @@ msgid "Less than" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:220 +#: lib/block_scout_web/templates/transaction/overview.html.eex:224 msgid "Limit" msgstr "" @@ -500,7 +500,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:312 -#: lib/block_scout_web/views/transaction_view.ex:264 +#: lib/block_scout_web/views/transaction_view.ex:275 msgid "Logs" msgstr "" @@ -512,7 +512,7 @@ msgid "Market Cap" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:118 +#: lib/block_scout_web/views/transaction_view.ex:129 msgid "Max of" msgstr "" @@ -602,8 +602,8 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/layout/_topnav.html.eex:44 -#: lib/block_scout_web/views/transaction_view.ex:132 -#: lib/block_scout_web/views/transaction_view.ex:166 +#: lib/block_scout_web/views/transaction_view.ex:143 +#: lib/block_scout_web/views/transaction_view.ex:177 msgid "Pending" msgstr "" @@ -690,7 +690,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/transaction/_emission_reward_tile.html.eex:8 -#: lib/block_scout_web/views/transaction_view.ex:134 +#: lib/block_scout_web/views/transaction_view.ex:145 msgid "Success" msgstr "" @@ -795,7 +795,7 @@ 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:208 +#: lib/block_scout_web/views/transaction_view.ex:219 msgid "Token Transfer" msgstr "" @@ -805,7 +805,7 @@ msgstr "" #: lib/block_scout_web/templates/transaction/_tabs.html.eex:4 #: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7 #: lib/block_scout_web/views/tokens/overview_view.ex:35 -#: lib/block_scout_web/views/transaction_view.ex:262 +#: lib/block_scout_web/views/transaction_view.ex:273 msgid "Token Transfers" msgstr "" @@ -845,7 +845,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address_logs/_logs.html.eex:3 -#: lib/block_scout_web/views/transaction_view.ex:211 +#: lib/block_scout_web/views/transaction_view.ex:222 msgid "Transaction" msgstr "" @@ -907,7 +907,7 @@ msgid "Unique Token" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:214 +#: lib/block_scout_web/templates/transaction/overview.html.eex:218 msgid "Used" msgstr "" @@ -927,7 +927,7 @@ msgid "Validations" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:192 +#: lib/block_scout_web/templates/transaction/overview.html.eex:196 msgid "Value" msgstr "" @@ -1520,16 +1520,6 @@ msgstr "" msgid "Optimization runs" msgstr "" -#, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:178 -msgid "ERC-20" -msgstr "" - -#, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:178 -msgid "ERC-721" -msgstr "" - #, elixir-format #: lib/block_scout_web/templates/api_docs/index.html.eex:4 msgid "API Documentation" @@ -1546,14 +1536,14 @@ msgid "View All Transactions" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:210 +#: lib/block_scout_web/templates/transaction/overview.html.eex:214 msgid "Gas" 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:265 +#: lib/block_scout_web/views/transaction_view.ex:276 msgid "Raw Trace" msgstr "" @@ -1709,12 +1699,6 @@ msgstr "" msgid "Anything not in this list is not supported. Click on the method to be taken to the documentation for that method, and check the notes section for any potential differences." msgstr "" -#, elixir-format -#: lib/block_scout_web/templates/address_token/index.html.eex:8 -msgid "Download all token transfers as csv" -msgstr "" - -#, elixir-format, fuzzy #: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:4 msgid "ETH RPC API Documentation" msgstr "" @@ -1749,7 +1733,7 @@ msgstr "" msgid "custom RPC" msgstr "" -#, elixir-format, fuzzy +#, elixir-format #: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:9 msgid "here." msgstr "" diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index ff8c32e535..e4416030b0 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -2923,7 +2923,7 @@ defmodule Explorer.Chain do end @spec transaction_token_transfer_type(Transaction.t()) :: - {:erc20, TokenTransfer.t()} | {:erc721, TokenTransfer.t()} | nil + :erc20 | :erc721 | :token_transfer | nil def transaction_token_transfer_type( %Transaction{ status: :ok, @@ -2933,8 +2933,19 @@ defmodule Explorer.Chain do } = transaction ) do zero_wei = %Wei{value: Decimal.new(0)} + result = find_token_transfer_type(transaction, input, value) - transaction = Repo.preload(transaction, token_transfers: :token) + if is_nil(result) && Enum.count(transaction.token_transfers) > 0 && value == zero_wei, + do: :token_transfer, + else: result + rescue + _ -> nil + end + + def transaction_token_transfer_type(_), do: nil + + defp find_token_transfer_type(transaction, input, value) do + zero_wei = %Wei{value: Decimal.new(0)} # https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/token/ERC721/ERC721.sol#L35 case {to_string(input), value} do @@ -2959,6 +2970,9 @@ defmodule Explorer.Chain do find_erc721_token_transfer(transaction.token_transfers, {from_address, to_address}) + {"0xf907fc5b" <> _params, ^zero_wei} -> + :erc20 + # check for ERC 20 or for old ERC 721 token versions {unquote(TokenTransfer.transfer_function_signature()) <> params, ^zero_wei} -> types = [:address, {:uint, 256}] @@ -2972,34 +2986,31 @@ defmodule Explorer.Chain do _ -> nil end - rescue - _ -> nil end - def transaction_token_transfer_type(_), do: nil - defp find_erc721_token_transfer(token_transfers, {from_address, to_address}) do token_transfer = Enum.find(token_transfers, fn token_transfer -> token_transfer.from_address_hash.bytes == from_address && token_transfer.to_address_hash.bytes == to_address end) - if token_transfer, do: {:erc721, token_transfer} + if token_transfer, do: :erc721 end defp find_erc721_or_erc20_token_transfer(token_transfers, {address, decimal_value}) do token_transfer = Enum.find(token_transfers, fn token_transfer -> - token_transfer.to_address_hash.bytes == address && - (token_transfer.amount == decimal_value || token_transfer.token_id) + token_transfer.to_address_hash.bytes == address && token_transfer.amount == decimal_value end) if token_transfer do case token_transfer.token do - %Token{type: "ERC-20"} -> {:erc20, token_transfer} - %Token{type: "ERC-721"} -> {:erc721, token_transfer} + %Token{type: "ERC-20"} -> :erc20 + %Token{type: "ERC-721"} -> :erc721 _ -> nil end + else + :erc20 end end diff --git a/apps/explorer/test/explorer/chain_test.exs b/apps/explorer/test/explorer/chain_test.exs index 442d051e0d..f789a883ea 100644 --- a/apps/explorer/test/explorer/chain_test.exs +++ b/apps/explorer/test/explorer/chain_test.exs @@ -3954,7 +3954,7 @@ defmodule Explorer.ChainTest do insert(:token_transfer, from_address: from_address, to_address: to_address, transaction: transaction) - assert {:erc721, _found_token_transfer} = Chain.transaction_token_transfer_type(transaction) + assert :erc721 = Chain.transaction_token_transfer_type(Repo.preload(transaction, token_transfers: :token)) end test "detects erc20 token transfer" do @@ -3980,7 +3980,7 @@ defmodule Explorer.ChainTest do amount: 8_025_000_000_000_000_000_000 ) - assert {:erc20, _found_token_transfer} = Chain.transaction_token_transfer_type(transaction) + assert :erc20 = Chain.transaction_token_transfer_type(Repo.preload(transaction, token_transfers: :token)) end end