diff --git a/CHANGELOG.md b/CHANGELOG.md index d1d7d5902b..3236b60d7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,13 @@ ### Features - [#2499](https://github.com/poanetwork/blockscout/pull/2499) - import emission reward ranges +- [#2477](https://github.com/poanetwork/blockscout/pull/2477) - aggregate token transfers on transaction page - [#2458](https://github.com/poanetwork/blockscout/pull/2458) - Add LAST_BLOCK var to add ability indexing in the range of blocks - [#2456](https://github.com/poanetwork/blockscout/pull/2456) - fetch pending transactions for geth ### Fixes - [#2496](https://github.com/poanetwork/blockscout/pull/2496) - fix docker build +- [#2495](https://github.com/poanetwork/blockscout/pull/2495) - fix logs for indexed chain - [#2459](https://github.com/poanetwork/blockscout/pull/2459) - fix top addresses query - [#2425](https://github.com/poanetwork/blockscout/pull/2425) - Force to show address view for checksummed address even if it is not in DB 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 fe347ee904..e804ec81d9 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 @@ -177,7 +177,7 @@

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

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

<%= token_transfer_amount(transfer) %> 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 1ad70179bf..33569f3a97 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 @@ -4,7 +4,7 @@ defmodule BlockScoutWeb.Tokens.Helpers do """ alias BlockScoutWeb.{CurrencyHelpers} - alias Explorer.Chain.{Address, Token, TokenTransfer} + alias Explorer.Chain.{Address, Token} @doc """ Returns the token transfers' amount according to the token's type and decimals. @@ -16,7 +16,7 @@ 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(%TokenTransfer{token: token, amount: amount, token_id: token_id}) do + def token_transfer_amount(%{token: token, amount: amount, token_id: token_id}) do do_token_transfer_amount(token, amount, token_id) 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 1ed50d28ab..61a0d471b1 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 @@ -39,6 +39,25 @@ defmodule BlockScoutWeb.TransactionView do if type, do: {type, transaction_with_transfers} end + def aggregate_token_transfers(token_transfers) do + token_transfers + |> Enum.reduce(%{}, fn token_transfer, acc -> + new_entry = %{ + token: token_transfer.token, + amount: token_transfer.amount, + token_id: token_transfer.token_id + } + + existing_entry = Map.get(acc, token_transfer.token_contract_address, %{new_entry | amount: Decimal.new(0)}) + + Map.put(acc, token_transfer.token_contract_address, %{ + new_entry + | amount: Decimal.add(new_entry.amount, existing_entry.amount) + }) + end) + |> Enum.map(fn {_key, value} -> value end) + end + def token_type_name(type) do case type do :erc20 -> gettext("ERC-20 ") diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index e356d87df9..3b364fb078 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:144 +#: lib/block_scout_web/views/transaction_view.ex:163 msgid "(Awaiting internal transactions for status)" msgstr "" @@ -276,12 +276,12 @@ msgid "Contract Address Pending" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:221 +#: lib/block_scout_web/views/transaction_view.ex:240 msgid "Contract Call" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:220 +#: lib/block_scout_web/views/transaction_view.ex:239 msgid "Contract Creation" msgstr "" @@ -356,12 +356,12 @@ msgid "Error trying to fetch balances." msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:148 +#: lib/block_scout_web/views/transaction_view.ex:167 msgid "Error: %{reason}" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:146 +#: lib/block_scout_web/views/transaction_view.ex:165 msgid "Error: (Awaiting internal transactions for reason)" msgstr "" @@ -466,7 +466,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:274 +#: lib/block_scout_web/views/transaction_view.ex:293 msgid "Internal Transactions" msgstr "" @@ -493,7 +493,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:275 +#: lib/block_scout_web/views/transaction_view.ex:294 msgid "Logs" msgstr "" @@ -506,8 +506,8 @@ msgid "Market Cap" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:129 -#: lib/block_scout_web/views/transaction_view.ex:129 +#: lib/block_scout_web/views/transaction_view.ex:148 +#: lib/block_scout_web/views/transaction_view.ex:148 msgid "Max of" msgstr "" @@ -598,8 +598,8 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/layout/_topnav.html.eex:54 -#: lib/block_scout_web/views/transaction_view.ex:143 -#: lib/block_scout_web/views/transaction_view.ex:177 +#: lib/block_scout_web/views/transaction_view.ex:162 +#: lib/block_scout_web/views/transaction_view.ex:196 msgid "Pending" msgstr "" @@ -686,7 +686,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/transaction/_emission_reward_tile.html.eex:8 -#: lib/block_scout_web/views/transaction_view.ex:145 +#: lib/block_scout_web/views/transaction_view.ex:164 msgid "Success" msgstr "" @@ -791,7 +791,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:219 +#: lib/block_scout_web/views/transaction_view.ex:238 msgid "Token Transfer" msgstr "" @@ -801,7 +801,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:273 +#: lib/block_scout_web/views/transaction_view.ex:292 msgid "Token Transfers" msgstr "" @@ -835,7 +835,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address_logs/_logs.html.eex:3 -#: lib/block_scout_web/views/transaction_view.ex:222 +#: lib/block_scout_web/views/transaction_view.ex:241 msgid "Transaction" msgstr "" @@ -1495,7 +1495,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:276 +#: lib/block_scout_web/views/transaction_view.ex:295 msgid "Raw Trace" msgstr "" @@ -1703,12 +1703,12 @@ msgid "Change Network" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:44 +#: lib/block_scout_web/views/transaction_view.ex:63 msgid "ERC-20 " msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:45 +#: lib/block_scout_web/views/transaction_view.ex:64 msgid "ERC-721 " 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 58e159d0bb..96837d2512 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:144 +#: lib/block_scout_web/views/transaction_view.ex:163 msgid "(Awaiting internal transactions for status)" msgstr "" @@ -276,12 +276,12 @@ msgid "Contract Address Pending" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:221 +#: lib/block_scout_web/views/transaction_view.ex:240 msgid "Contract Call" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:220 +#: lib/block_scout_web/views/transaction_view.ex:239 msgid "Contract Creation" msgstr "" @@ -356,12 +356,12 @@ msgid "Error trying to fetch balances." msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:148 +#: lib/block_scout_web/views/transaction_view.ex:167 msgid "Error: %{reason}" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:146 +#: lib/block_scout_web/views/transaction_view.ex:165 msgid "Error: (Awaiting internal transactions for reason)" msgstr "" @@ -466,7 +466,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:274 +#: lib/block_scout_web/views/transaction_view.ex:293 msgid "Internal Transactions" msgstr "" @@ -493,7 +493,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:275 +#: lib/block_scout_web/views/transaction_view.ex:294 msgid "Logs" msgstr "" @@ -506,8 +506,8 @@ msgid "Market Cap" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:129 -#: lib/block_scout_web/views/transaction_view.ex:129 +#: lib/block_scout_web/views/transaction_view.ex:148 +#: lib/block_scout_web/views/transaction_view.ex:148 msgid "Max of" msgstr "" @@ -598,8 +598,8 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/layout/_topnav.html.eex:54 -#: lib/block_scout_web/views/transaction_view.ex:143 -#: lib/block_scout_web/views/transaction_view.ex:177 +#: lib/block_scout_web/views/transaction_view.ex:162 +#: lib/block_scout_web/views/transaction_view.ex:196 msgid "Pending" msgstr "" @@ -686,7 +686,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/transaction/_emission_reward_tile.html.eex:8 -#: lib/block_scout_web/views/transaction_view.ex:145 +#: lib/block_scout_web/views/transaction_view.ex:164 msgid "Success" msgstr "" @@ -791,7 +791,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:219 +#: lib/block_scout_web/views/transaction_view.ex:238 msgid "Token Transfer" msgstr "" @@ -801,7 +801,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:273 +#: lib/block_scout_web/views/transaction_view.ex:292 msgid "Token Transfers" msgstr "" @@ -835,7 +835,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address_logs/_logs.html.eex:3 -#: lib/block_scout_web/views/transaction_view.ex:222 +#: lib/block_scout_web/views/transaction_view.ex:241 msgid "Transaction" msgstr "" @@ -1496,7 +1496,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:276 +#: lib/block_scout_web/views/transaction_view.ex:295 msgid "Raw Trace" msgstr "" @@ -1704,12 +1704,12 @@ msgid "Change Network" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:44 +#: lib/block_scout_web/views/transaction_view.ex:63 msgid "ERC-20 " msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:45 +#: lib/block_scout_web/views/transaction_view.ex:64 msgid "ERC-721 " msgstr "" diff --git a/apps/block_scout_web/test/block_scout_web/views/transaction_view_test.exs b/apps/block_scout_web/test/block_scout_web/views/transaction_view_test.exs index 2a3e5492ed..8598f3826a 100644 --- a/apps/block_scout_web/test/block_scout_web/views/transaction_view_test.exs +++ b/apps/block_scout_web/test/block_scout_web/views/transaction_view_test.exs @@ -253,4 +253,20 @@ defmodule BlockScoutWeb.TransactionViewTest do assert TransactionView.current_tab_name(logs_path) == "Logs" end end + + describe "aggregate_token_transfers/1" do + test "aggregates token transfers" do + transaction = + :transaction + |> insert() + |> with_block() + + token_transfer = insert(:token_transfer, transaction: transaction, amount: Decimal.new(1)) + + result = TransactionView.aggregate_token_transfers([token_transfer, token_transfer, token_transfer]) + + assert Enum.count(result) == 1 + assert List.first(result).amount == Decimal.new(3) + end + end end diff --git a/apps/indexer/lib/indexer/block/catchup/bound_interval_supervisor.ex b/apps/indexer/lib/indexer/block/catchup/bound_interval_supervisor.ex index f1b216aa2b..b128ad4ca0 100644 --- a/apps/indexer/lib/indexer/block/catchup/bound_interval_supervisor.ex +++ b/apps/indexer/lib/indexer/block/catchup/bound_interval_supervisor.ex @@ -185,7 +185,12 @@ defmodule Indexer.Block.Catchup.BoundIntervalSupervisor do def handle_info( {ref, - %{first_block_number: first_block_number, missing_block_count: missing_block_count, shrunk: false = shrunk}}, + %{ + first_block_number: first_block_number, + last_block_number: last_block_number, + missing_block_count: missing_block_count, + shrunk: false = shrunk + }}, %__MODULE__{ bound_interval: bound_interval, task: %Task{ref: ref} @@ -197,7 +202,7 @@ defmodule Indexer.Block.Catchup.BoundIntervalSupervisor do 0 -> Logger.info("Index already caught up.", first_block_number: first_block_number, - last_block_number: 0, + last_block_number: last_block_number, missing_block_count: 0, shrunk: shrunk ) diff --git a/apps/indexer/lib/indexer/block/catchup/fetcher.ex b/apps/indexer/lib/indexer/block/catchup/fetcher.ex index 59088ebc3f..f228551a37 100644 --- a/apps/indexer/lib/indexer/block/catchup/fetcher.ex +++ b/apps/indexer/lib/indexer/block/catchup/fetcher.ex @@ -123,7 +123,7 @@ defmodule Indexer.Block.Catchup.Fetcher do Shrinkable.shrunk?(sequence) end - %{first_block_number: first, missing_block_count: missing_block_count, shrunk: shrunk} + %{first_block_number: first, last_block_number: last, missing_block_count: missing_block_count, shrunk: shrunk} end end