Finalize ERC-1155 support

pull/4761/head
Viktor Baranov 3 years ago
parent 7a4eb8f72a
commit ee54656026
  1. 1
      CHANGELOG.md
  2. 5
      apps/block_scout_web/lib/block_scout_web/controllers/tokens/token_controller.ex
  3. 2
      apps/block_scout_web/lib/block_scout_web/templates/address_token_balance/_tokens.html.eex
  4. 32
      apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex
  5. 7
      apps/block_scout_web/lib/block_scout_web/web_router.ex
  6. 82
      apps/block_scout_web/priv/gettext/default.pot
  7. 193
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
  8. 2
      apps/explorer/lib/explorer/chain.ex
  9. 16
      apps/explorer/lib/explorer/chain/address/current_token_balance.ex
  10. 35
      apps/explorer/lib/explorer/chain/address/token.ex
  11. 23
      apps/explorer/lib/explorer/chain/import/runner/address/current_token_balances.ex
  12. 8
      apps/explorer/lib/explorer/chain/import/runner/address/token_balances.ex
  13. 62
      apps/explorer/lib/explorer/chain/import/runner/blocks.ex
  14. 2
      apps/explorer/lib/explorer/token/balance_reader.ex
  15. 25
      apps/explorer/priv/repo/migrations/20211013190346_remove_duplicates_of_current_token_balances.exs
  16. 26
      apps/explorer/test/explorer/chain/import/runner/address/current_token_balances_test.exs
  17. 23
      apps/indexer/lib/indexer/transform/token_transfers.ex

@ -1,6 +1,7 @@
## Current
### Features
- [#4761](https://github.com/blockscout/blockscout/pull/4761) - ERC-1155 support
- [#4739](https://github.com/blockscout/blockscout/pull/4739) - Improve logs and inputs decoding
- [#4747](https://github.com/blockscout/blockscout/pull/4747) - Advanced CSV export
- [#4745](https://github.com/blockscout/blockscout/pull/4745) - Vyper contracts verification

@ -12,11 +12,12 @@ defmodule BlockScoutWeb.Tokens.TokenController do
end
def token_counters(conn, %{"id" => address_hash_string}) do
with {:ok, address_hash} <- Chain.string_to_address_hash(address_hash_string) do
case Chain.string_to_address_hash(address_hash_string) do
{:ok, address_hash} ->
{transfer_count, token_holder_count} = fetch_token_counters(address_hash, 200)
json(conn, %{transfer_count: transfer_count, token_holder_count: token_holder_count})
else
_ ->
not_found(conn)
end

@ -17,7 +17,7 @@
end
%>
<%= link(
to: token_path(@conn, :show, to_string(token.contract_address_hash)),
to: path,
class: "dropdown-item"
) do %>
<div class="row">

@ -123,17 +123,13 @@ defmodule BlockScoutWeb.TransactionView do
end
)
final_ft_transfers = Map.values(ft_transfers)
transfers = final_ft_transfers ++ nft_transfers
transfers = ft_transfers ++ nft_transfers
final_ft_mintings = Map.values(ft_mintings)
mintings = final_ft_mintings ++ nft_mintings
mintings = ft_mintings ++ nft_mintings
final_ft_burnings = Map.values(ft_burnings)
burnings = final_ft_burnings ++ nft_burnings
burnings = ft_burnings ++ nft_burnings
final_ft_creations = Map.values(ft_creations)
creations = final_ft_creations ++ nft_creations
creations = ft_creations ++ nft_creations
%{transfers: transfers, mintings: mintings, burnings: burnings, creations: creations}
end
@ -188,24 +184,16 @@ defmodule BlockScoutWeb.TransactionView do
end)
new_acc1 =
if token_transfer.token_id do
[new_entry | acc1]
else
if existing_entry do
acc1
|> Enum.map(fn entry ->
if entry.to_address_hash == token_transfer.to_address_hash &&
entry.from_address_hash == token_transfer.from_address_hash &&
entry.token == token_transfer.token do
updated_entry =
if new_entry.amount do
%{
updated_entry = %{
entry
| amount: Decimal.add(new_entry.amount, entry.amount)
}
else
entry
end
updated_entry
else
@ -215,7 +203,6 @@ defmodule BlockScoutWeb.TransactionView do
else
[new_entry | acc1]
end
end
{new_acc1, acc2}
end
@ -536,7 +523,6 @@ defmodule BlockScoutWeb.TransactionView do
creations_count =
Enum.count(token_transfers_types, fn token_transfers_type -> token_transfers_type == @token_creation_type end)
<<<<<<< HEAD
cond do
Enum.count(token_transfers_types) == burnings_count -> @token_burning_type
@ -560,14 +546,6 @@ defmodule BlockScoutWeb.TransactionView do
case Integer.parse(string_value) do
{integer, ""} -> integer
_ -> 0
=======
cond do
Enum.count(token_transfers_types) == burnings_count -> @token_burning_type
Enum.count(token_transfers_types) == mintings_count -> @token_minting_type
Enum.count(token_transfers_types) == creations_count -> @token_creation_type
true -> @token_transfer_type
>>>>>>> d8b6f073c (ERC-1155 transfers support in UI)
end
end

@ -267,6 +267,13 @@ defmodule BlockScoutWeb.WebRouter do
only: [:index],
as: :metadata
)
resources(
"/token-holders",
Tokens.Instance.HolderController,
only: [:index],
as: :holder
)
end
end

@ -81,7 +81,7 @@ msgid "%{subnetwork} Staking DApp - BlockScout"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:356
#: lib/block_scout_web/views/transaction_view.ex:348
msgid "(Awaiting internal transactions for status)"
msgstr ""
@ -348,7 +348,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/internal_transaction/_tile.html.eex:28 lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:43
msgid "Block #%{number}"
msgstr ""
@ -580,7 +580,7 @@ msgid "Compiler version"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:349
#: lib/block_scout_web/views/transaction_view.ex:341
msgid "Confirmed"
msgstr ""
@ -654,12 +654,12 @@ msgid "Contract Address Pending"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:460
#: lib/block_scout_web/views/transaction_view.ex:452
msgid "Contract Call"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:457
#: lib/block_scout_web/views/transaction_view.ex:449
msgid "Contract Creation"
msgstr ""
@ -987,12 +987,12 @@ msgid "EIP-1167"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:221
#: lib/block_scout_web/views/transaction_view.ex:212
msgid "ERC-20 "
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:222
#: lib/block_scout_web/views/transaction_view.ex:213
msgid "ERC-721 "
msgstr ""
@ -1061,12 +1061,12 @@ msgid "Error trying to fetch balances."
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:360
#: lib/block_scout_web/views/transaction_view.ex:352
msgid "Error: %{reason}"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:358
#: lib/block_scout_web/views/transaction_view.ex:350
msgid "Error: (Awaiting internal transactions for reason)"
msgstr ""
@ -1313,7 +1313,7 @@ msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:28
#: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:21 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:346
#: lib/block_scout_web/views/transaction_view.ex:515
#: lib/block_scout_web/views/transaction_view.ex:507
msgid "Internal Transactions"
msgstr ""
@ -1440,7 +1440,7 @@ msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:41
#: lib/block_scout_web/templates/address_logs/index.html.eex:10 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:357
#: lib/block_scout_web/views/transaction_view.ex:516
#: lib/block_scout_web/views/transaction_view.ex:508
msgid "Logs"
msgstr ""
@ -1481,7 +1481,7 @@ msgid "Max Priority Fee per Gas"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:330
#: lib/block_scout_web/views/transaction_view.ex:322
msgid "Max of"
msgstr ""
@ -1497,7 +1497,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/tokens/instance/metadata/index.html.eex:18
#: lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex:10 lib/block_scout_web/views/tokens/instance/overview_view.ex:178
#: lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex:10 lib/block_scout_web/views/tokens/instance/overview_view.ex:179
msgid "Metadata"
msgstr ""
@ -1684,7 +1684,7 @@ msgid "Other Explorers"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/tokens/inventory/_token.html.eex:18
#: lib/block_scout_web/templates/tokens/inventory/_token.html.eex:24
msgid "Owner Address"
msgstr ""
@ -1712,8 +1712,8 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/layout/_topnav.html.eex:53
#: lib/block_scout_web/templates/stakes/_stakes_modal_delegators_list.html.eex:184 lib/block_scout_web/views/transaction_view.ex:355
#: lib/block_scout_web/views/transaction_view.ex:389
#: lib/block_scout_web/templates/stakes/_stakes_modal_delegators_list.html.eex:184 lib/block_scout_web/views/transaction_view.ex:347
#: lib/block_scout_web/views/transaction_view.ex:381
msgid "Pending"
msgstr ""
@ -1831,7 +1831,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:517
#: lib/block_scout_web/templates/transaction_raw_trace/index.html.eex:7 lib/block_scout_web/views/transaction_view.ex:509
msgid "Raw Trace"
msgstr ""
@ -2037,9 +2037,9 @@ msgstr ""
#: lib/block_scout_web/templates/address_transaction/index.html.eex:54 lib/block_scout_web/templates/address_validation/index.html.eex:24
#: lib/block_scout_web/templates/block_transaction/index.html.eex:22 lib/block_scout_web/templates/chain/show.html.eex:180
#: lib/block_scout_web/templates/pending_transaction/index.html.eex:22 lib/block_scout_web/templates/stakes/_table.html.eex:49
#: lib/block_scout_web/templates/tokens/holder/index.html.eex:27 lib/block_scout_web/templates/tokens/instance/transfer/index.html.eex:23
#: lib/block_scout_web/templates/tokens/inventory/index.html.eex:22 lib/block_scout_web/templates/tokens/transfer/index.html.eex:21
#: lib/block_scout_web/templates/transaction/index.html.eex:29
#: lib/block_scout_web/templates/tokens/holder/index.html.eex:27 lib/block_scout_web/templates/tokens/instance/holder/index.html.eex:23
#: lib/block_scout_web/templates/tokens/instance/transfer/index.html.eex:23 lib/block_scout_web/templates/tokens/inventory/index.html.eex:22
#: lib/block_scout_web/templates/tokens/transfer/index.html.eex:21 lib/block_scout_web/templates/transaction/index.html.eex:29
#: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:13 lib/block_scout_web/templates/transaction_log/index.html.eex:15
#: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:14
msgid "Something went wrong, click to reload."
@ -2144,7 +2144,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/transaction/_emission_reward_tile.html.eex:8
#: lib/block_scout_web/views/transaction_view.ex:357
#: lib/block_scout_web/views/transaction_view.ex:349
msgid "Success"
msgstr ""
@ -2365,8 +2365,8 @@ msgid "There are no transactions."
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/tokens/instance/transfer/index.html.eex:28
#: lib/block_scout_web/templates/tokens/transfer/index.html.eex:26
#: lib/block_scout_web/templates/tokens/instance/holder/index.html.eex:28
#: lib/block_scout_web/templates/tokens/instance/transfer/index.html.eex:28 lib/block_scout_web/templates/tokens/transfer/index.html.eex:26
msgid "There are no transfers for this Token."
msgstr ""
@ -2477,13 +2477,12 @@ msgid "Token"
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:451
#: lib/block_scout_web/templates/common_components/_token_transfer_type_display_name.html.eex:3 lib/block_scout_web/views/transaction_view.ex:443
msgid "Token Burning"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:452
#: lib/block_scout_web/templates/common_components/_token_transfer_type_display_name.html.eex:7 lib/block_scout_web/views/transaction_view.ex:444
msgid "Token Creation"
msgstr ""
@ -2495,25 +2494,25 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/tokens/holder/index.html.eex:20
#: lib/block_scout_web/templates/tokens/instance/holder/index.html.eex:16 lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex:17
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:9 lib/block_scout_web/views/tokens/overview_view.ex:42
msgid "Token Holders"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex:38
#: lib/block_scout_web/templates/tokens/inventory/_token.html.eex:11
#: lib/block_scout_web/templates/tokens/inventory/_token.html.eex:18 lib/block_scout_web/templates/tokens/inventory/_token.html.eex:37
msgid "Token ID"
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:450
#: lib/block_scout_web/templates/common_components/_token_transfer_type_display_name.html.eex:5 lib/block_scout_web/views/transaction_view.ex:442
msgid "Token Minting"
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:453
#: 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:445
msgid "Token Transfer"
msgstr ""
@ -2523,8 +2522,8 @@ msgstr ""
#: lib/block_scout_web/templates/tokens/instance/transfer/index.html.eex:16 lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:3
#: lib/block_scout_web/templates/tokens/transfer/index.html.eex:14 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/address_view.ex:348
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:177 lib/block_scout_web/views/tokens/overview_view.ex:41
#: lib/block_scout_web/views/transaction_view.ex:514
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:178 lib/block_scout_web/views/tokens/overview_view.ex:41
#: lib/block_scout_web/views/transaction_view.ex:506
msgid "Token Transfers"
msgstr ""
@ -2620,7 +2619,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_logs/_logs.html.eex:19
#: lib/block_scout_web/views/transaction_view.ex:463
#: lib/block_scout_web/views/transaction_view.ex:455
msgid "Transaction"
msgstr ""
@ -2750,12 +2749,12 @@ msgid "Uncles"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:348
#: lib/block_scout_web/views/transaction_view.ex:340
msgid "Unconfirmed"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/tokens/inventory/_token.html.eex:6
#: lib/block_scout_web/templates/tokens/inventory/_token.html.eex:9
msgid "Unique Token"
msgstr ""
@ -3193,8 +3192,11 @@ msgid "validator"
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"
#: lib/block_scout_web/views/transaction_view.ex:214
msgid "ERC-1155 "
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/tokens/inventory/_token.html.eex:11
msgid "Not unique Token"
msgstr ""

@ -81,7 +81,7 @@ msgid "%{subnetwork} Staking DApp - BlockScout"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:356
#: lib/block_scout_web/views/transaction_view.ex:348
msgid "(Awaiting internal transactions for status)"
msgstr ""
@ -348,7 +348,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/internal_transaction/_tile.html.eex:28 lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:43
msgid "Block #%{number}"
msgstr ""
@ -580,7 +580,7 @@ msgid "Compiler version"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:349
#: lib/block_scout_web/views/transaction_view.ex:341
msgid "Confirmed"
msgstr ""
@ -654,12 +654,12 @@ msgid "Contract Address Pending"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:460
#: lib/block_scout_web/views/transaction_view.ex:452
msgid "Contract Call"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:457
#: lib/block_scout_web/views/transaction_view.ex:449
msgid "Contract Creation"
msgstr ""
@ -933,18 +933,8 @@ msgid "Delegators of "
msgstr ""
#, elixir-format
<<<<<<< HEAD
<<<<<<< HEAD
#: lib/block_scout_web/templates/stakes/_stakes_modal_pool_info.html.eex:53
msgid "Delegators’ Staked Amount"
=======
#: lib/block_scout_web/templates/address_logs/_logs.html.eex:18
=======
#: lib/block_scout_web/templates/address_logs/_logs.html.eex:25
>>>>>>> 03b4f4b7d (ERC-1155: token balanaces indexer update)
#: lib/block_scout_web/views/transaction_view.ex:403
msgid "Transaction"
>>>>>>> 7148d5f99 (ERC-1155 finalization)
msgstr ""
#, elixir-format
@ -997,12 +987,12 @@ msgid "EIP-1167"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:221
#: lib/block_scout_web/views/transaction_view.ex:212
msgid "ERC-20 "
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:222
#: lib/block_scout_web/views/transaction_view.ex:213
msgid "ERC-721 "
msgstr ""
@ -1019,14 +1009,9 @@ msgid "ETH RPC API Documentation"
msgstr ""
#, elixir-format
<<<<<<< HEAD
#: lib/block_scout_web/templates/address_contract/index.html.eex:68
#: lib/block_scout_web/templates/address_contract_verification_via_flattened_code/new.html.eex:82
msgid "EVM Version"
=======
#: lib/block_scout_web/templates/transaction/overview.html.eex:307
msgid "Limit"
>>>>>>> 7148d5f99 (ERC-1155 finalization)
msgstr ""
#, elixir-format
@ -1060,13 +1045,8 @@ msgid "Epoch number"
msgstr ""
#, elixir-format
<<<<<<< HEAD
#: lib/block_scout_web/templates/stakes/_stakes_modal_claim_reward_content.html.eex:44
msgid "Epochs range(s) or enum, e.g.: 5-9,23-27,47,50"
=======
#: lib/block_scout_web/views/transaction_view.ex:291
msgid "Max of"
>>>>>>> 7148d5f99 (ERC-1155 finalization)
msgstr ""
#, elixir-format
@ -1081,12 +1061,12 @@ msgid "Error trying to fetch balances."
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:360
#: lib/block_scout_web/views/transaction_view.ex:352
msgid "Error: %{reason}"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:358
#: lib/block_scout_web/views/transaction_view.ex:350
msgid "Error: (Awaiting internal transactions for reason)"
msgstr ""
@ -1171,19 +1151,11 @@ msgid "Forked Blocks (Reorgs)"
msgstr ""
#, elixir-format
<<<<<<< HEAD
#: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:42
#: lib/block_scout_web/templates/address_token_transfer/index.html.eex:40 lib/block_scout_web/templates/address_transaction/index.html.eex:38
#: lib/block_scout_web/templates/transaction/overview.html.eex:182 lib/block_scout_web/views/address_internal_transaction_view.ex:10
#: lib/block_scout_web/views/address_token_transfer_view.ex:10 lib/block_scout_web/views/address_transaction_view.ex:10
msgid "From"
=======
#: 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:309
#: lib/block_scout_web/views/transaction_view.ex:343
msgid "Pending"
>>>>>>> 7148d5f99 (ERC-1155 finalization)
msgstr ""
#, elixir-format
@ -1225,15 +1197,8 @@ msgid "Genesis Block"
msgstr ""
#, elixir-format
<<<<<<< HEAD
#: lib/block_scout_web/templates/layout/_footer.html.eex:22
msgid "Github"
=======
#: 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:457
msgid "Raw Trace"
>>>>>>> 7148d5f99 (ERC-1155 finalization)
msgstr ""
#, elixir-format
@ -1348,7 +1313,7 @@ msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:28
#: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:21 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:346
#: lib/block_scout_web/views/transaction_view.ex:515
#: lib/block_scout_web/views/transaction_view.ex:507
msgid "Internal Transactions"
msgstr ""
@ -1475,7 +1440,7 @@ msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:41
#: lib/block_scout_web/templates/address_logs/index.html.eex:10 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:357
#: lib/block_scout_web/views/transaction_view.ex:516
#: lib/block_scout_web/views/transaction_view.ex:508
msgid "Logs"
msgstr ""
@ -1516,7 +1481,7 @@ msgid "Max Priority Fee per Gas"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:330
#: lib/block_scout_web/views/transaction_view.ex:322
msgid "Max of"
msgstr ""
@ -1532,7 +1497,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/tokens/instance/metadata/index.html.eex:18
#: lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex:10 lib/block_scout_web/views/tokens/instance/overview_view.ex:178
#: lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex:10 lib/block_scout_web/views/tokens/instance/overview_view.ex:179
msgid "Metadata"
msgstr ""
@ -1554,13 +1519,8 @@ msgid "Miner Reward"
msgstr ""
#, elixir-format
<<<<<<< HEAD
#: lib/block_scout_web/templates/common_components/_minimal_proxy_pattern.html.eex:3
msgid "Minimal Proxy Contract for"
=======
#: lib/block_scout_web/templates/transaction/overview.html.eex:301
msgid "Used"
>>>>>>> 7148d5f99 (ERC-1155 finalization)
msgstr ""
#, elixir-format
@ -1589,14 +1549,8 @@ msgid "Model"
msgstr ""
#, elixir-format
<<<<<<< HEAD
#: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:58
msgid "Module"
=======
#: lib/block_scout_web/templates/transaction/overview.html.eex:215
#: lib/block_scout_web/templates/transaction/overview.html.eex:279
msgid "Value"
>>>>>>> 7148d5f99 (ERC-1155 finalization)
msgstr ""
#, elixir-format
@ -1730,7 +1684,7 @@ msgid "Other Explorers"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/tokens/inventory/_token.html.eex:18
#: lib/block_scout_web/templates/tokens/inventory/_token.html.eex:24
msgid "Owner Address"
msgstr ""
@ -1758,8 +1712,8 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/layout/_topnav.html.eex:53
#: lib/block_scout_web/templates/stakes/_stakes_modal_delegators_list.html.eex:184 lib/block_scout_web/views/transaction_view.ex:355
#: lib/block_scout_web/views/transaction_view.ex:389
#: lib/block_scout_web/templates/stakes/_stakes_modal_delegators_list.html.eex:184 lib/block_scout_web/views/transaction_view.ex:347
#: lib/block_scout_web/views/transaction_view.ex:381
msgid "Pending"
msgstr ""
@ -1769,13 +1723,8 @@ msgid "Pending Transactions"
msgstr ""
#, elixir-format
<<<<<<< HEAD
#: lib/block_scout_web/templates/stakes/_stakes_modal_stake.html.eex:45
msgid "Place stake"
=======
#: lib/block_scout_web/templates/transaction/overview.html.eex:297
msgid "Gas"
>>>>>>> 7148d5f99 (ERC-1155 finalization)
msgstr ""
#, elixir-format
@ -1849,7 +1798,6 @@ msgid "Price per unit of gas specified by the sender. Higher gas prices can prio
msgstr ""
#, elixir-format
<<<<<<< HEAD
#: lib/block_scout_web/templates/block/overview.html.eex:219
#: lib/block_scout_web/templates/transaction/overview.html.eex:390
msgid "Priority Fee / Tip"
@ -1858,25 +1806,6 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/block/_tile.html.eex:62
msgid "Priority Fees"
=======
#: lib/block_scout_web/templates/address/_tabs.html.eex:28
#: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:19
#: 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:455
msgid "Internal Transactions"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:41
#: lib/block_scout_web/templates/address_logs/index.html.eex:8
#: 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:456
msgid "Logs"
>>>>>>> 7148d5f99 (ERC-1155 finalization)
msgstr ""
#, elixir-format
@ -1896,14 +1825,13 @@ msgid "RPC"
msgstr ""
#, elixir-format
<<<<<<< HEAD
#: lib/block_scout_web/templates/transaction/overview.html.eex:435
msgid "Raw Input"
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:517
#: lib/block_scout_web/templates/transaction_raw_trace/index.html.eex:7 lib/block_scout_web/views/transaction_view.ex:509
msgid "Raw Trace"
msgstr ""
@ -1918,29 +1846,6 @@ msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:88
#: lib/block_scout_web/views/address_view.ex:352
msgid "Read Proxy"
=======
#: lib/block_scout_web/templates/transaction/overview.html.eex:250
msgid " Token Burning"
msgstr ""
#, elixir-format
#:
#: 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:240
msgid " Token Minting"
msgstr ""
#, elixir-format
#:
#: 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"
>>>>>>> 7148d5f99 (ERC-1155 finalization)
msgstr ""
#, elixir-format
@ -2132,9 +2037,9 @@ msgstr ""
#: lib/block_scout_web/templates/address_transaction/index.html.eex:54 lib/block_scout_web/templates/address_validation/index.html.eex:24
#: lib/block_scout_web/templates/block_transaction/index.html.eex:22 lib/block_scout_web/templates/chain/show.html.eex:180
#: lib/block_scout_web/templates/pending_transaction/index.html.eex:22 lib/block_scout_web/templates/stakes/_table.html.eex:49
#: lib/block_scout_web/templates/tokens/holder/index.html.eex:27 lib/block_scout_web/templates/tokens/instance/transfer/index.html.eex:23
#: lib/block_scout_web/templates/tokens/inventory/index.html.eex:22 lib/block_scout_web/templates/tokens/transfer/index.html.eex:21
#: lib/block_scout_web/templates/transaction/index.html.eex:29
#: lib/block_scout_web/templates/tokens/holder/index.html.eex:27 lib/block_scout_web/templates/tokens/instance/holder/index.html.eex:23
#: lib/block_scout_web/templates/tokens/instance/transfer/index.html.eex:23 lib/block_scout_web/templates/tokens/inventory/index.html.eex:22
#: lib/block_scout_web/templates/tokens/transfer/index.html.eex:21 lib/block_scout_web/templates/transaction/index.html.eex:29
#: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:13 lib/block_scout_web/templates/transaction_log/index.html.eex:15
#: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:14
msgid "Something went wrong, click to reload."
@ -2239,7 +2144,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/transaction/_emission_reward_tile.html.eex:8
#: lib/block_scout_web/views/transaction_view.ex:357
#: lib/block_scout_web/views/transaction_view.ex:349
msgid "Success"
msgstr ""
@ -2460,8 +2365,8 @@ msgid "There are no transactions."
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/tokens/instance/transfer/index.html.eex:28
#: lib/block_scout_web/templates/tokens/transfer/index.html.eex:26
#: lib/block_scout_web/templates/tokens/instance/holder/index.html.eex:28
#: lib/block_scout_web/templates/tokens/instance/transfer/index.html.eex:28 lib/block_scout_web/templates/tokens/transfer/index.html.eex:26
msgid "There are no transfers for this Token."
msgstr ""
@ -2572,13 +2477,12 @@ msgid "Token"
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:451
#: lib/block_scout_web/templates/common_components/_token_transfer_type_display_name.html.eex:3 lib/block_scout_web/views/transaction_view.ex:443
msgid "Token Burning"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:452
#: lib/block_scout_web/templates/common_components/_token_transfer_type_display_name.html.eex:7 lib/block_scout_web/views/transaction_view.ex:444
msgid "Token Creation"
msgstr ""
@ -2590,25 +2494,25 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/tokens/holder/index.html.eex:20
#: lib/block_scout_web/templates/tokens/instance/holder/index.html.eex:16 lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex:17
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:9 lib/block_scout_web/views/tokens/overview_view.ex:42
msgid "Token Holders"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/tokens/instance/overview/_details.html.eex:38
#: lib/block_scout_web/templates/tokens/inventory/_token.html.eex:11
#: lib/block_scout_web/templates/tokens/inventory/_token.html.eex:18 lib/block_scout_web/templates/tokens/inventory/_token.html.eex:37
msgid "Token ID"
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:450
#: lib/block_scout_web/templates/common_components/_token_transfer_type_display_name.html.eex:5 lib/block_scout_web/views/transaction_view.ex:442
msgid "Token Minting"
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:453
#: 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:445
msgid "Token Transfer"
msgstr ""
@ -2618,8 +2522,8 @@ msgstr ""
#: lib/block_scout_web/templates/tokens/instance/transfer/index.html.eex:16 lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:3
#: lib/block_scout_web/templates/tokens/transfer/index.html.eex:14 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/address_view.ex:348
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:177 lib/block_scout_web/views/tokens/overview_view.ex:41
#: lib/block_scout_web/views/transaction_view.ex:514
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:178 lib/block_scout_web/views/tokens/overview_view.ex:41
#: lib/block_scout_web/views/transaction_view.ex:506
msgid "Token Transfers"
msgstr ""
@ -2715,7 +2619,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_logs/_logs.html.eex:19
#: lib/block_scout_web/views/transaction_view.ex:463
#: lib/block_scout_web/views/transaction_view.ex:455
msgid "Transaction"
msgstr ""
@ -2845,12 +2749,12 @@ msgid "Uncles"
msgstr ""
#, elixir-format
#: lib/block_scout_web/views/transaction_view.ex:348
#: lib/block_scout_web/views/transaction_view.ex:340
msgid "Unconfirmed"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/tokens/inventory/_token.html.eex:6
#: lib/block_scout_web/templates/tokens/inventory/_token.html.eex:9
msgid "Unique Token"
msgstr ""
@ -3272,25 +3176,9 @@ msgid "specified epochs only"
msgstr ""
#, elixir-format
<<<<<<< HEAD
#: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:59
#: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:70
msgid "string"
=======
#: 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
msgid "Sources and Metadata JSON"
>>>>>>> 7148d5f99 (ERC-1155 finalization)
msgstr ""
#, elixir-format
@ -3304,8 +3192,11 @@ msgid "validator"
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"
#: lib/block_scout_web/views/transaction_view.ex:214
msgid "ERC-1155 "
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/tokens/inventory/_token.html.eex:11
msgid "Not unique Token"
msgstr ""

@ -5826,6 +5826,8 @@ defmodule Explorer.Chain do
|> Repo.all()
end
def token_id_1155_is_unique?(_, nil), do: false
def token_id_1155_is_unique?(contract_address_hash, token_id) do
result = contract_address_hash |> CurrentTokenBalance.token_balances_by_id_limit_2(token_id) |> Repo.all()

@ -9,7 +9,7 @@ defmodule Explorer.Chain.Address.CurrentTokenBalance do
use Explorer.Schema
import Ecto.Changeset
import Ecto.Query, only: [from: 2, limit: 2, offset: 2, order_by: 3, preload: 2, where: 3]
import Ecto.Query, only: [from: 2, limit: 2, offset: 2, order_by: 3, preload: 2]
alias Explorer.{Chain, PagingOptions}
alias Explorer.Chain.{Address, Block, BridgedToken, Hash, Token}
@ -32,6 +32,7 @@ defmodule Explorer.Chain.Address.CurrentTokenBalance do
token: %Ecto.Association.NotLoaded{} | Token.t(),
token_contract_address_hash: Hash.Address,
block_number: Block.block_number(),
max_block_number: Block.block_number(),
inserted_at: DateTime.t(),
updated_at: DateTime.t(),
value: Decimal.t() | nil,
@ -42,6 +43,7 @@ defmodule Explorer.Chain.Address.CurrentTokenBalance do
schema "address_current_token_balances" do
field(:value, :decimal)
field(:block_number, :integer)
field(:max_block_number, :integer, virtual: true)
field(:value_fetched_at, :utc_datetime_usec)
field(:token_id, :decimal)
field(:token_type, :string)
@ -121,7 +123,7 @@ defmodule Explorer.Chain.Address.CurrentTokenBalance do
|> token_holders_by_token_id_query(token_id)
|> preload(:address)
|> order_by([tb], desc: :value, desc: :address_hash)
|> page_token_balances(paging_options)
|> Chain.page_token_balances(paging_options)
|> limit(^paging_options.page_size)
|> offset(^offset)
end
@ -249,14 +251,4 @@ defmodule Explorer.Chain.Address.CurrentTokenBalance do
where: tb.value > 0
)
end
defp page_token_balances(query, %PagingOptions{key: nil}), do: query
defp page_token_balances(query, %PagingOptions{key: {value, address_hash}}) do
where(
query,
[tb],
tb.value < ^value or (tb.value == ^value and tb.address_hash < ^address_hash)
)
end
end

@ -34,17 +34,16 @@ defmodule Explorer.Chain.Address.Token do
address_hash
|> join_with_last_balance()
|> order_filter_and_group()
|> filter_and_group()
|> order()
|> page_tokens(paging_options)
|> limit(^paging_options.page_size)
end
defp order_filter_and_group(query) do
defp filter_and_group(query) do
from(
[token, balance] in query,
order_by: fragment("? DESC, LOWER(?) ASC NULLS LAST", token.type, token.name),
where: balance.value > 0,
group_by: [token.name, token.symbol, balance.value, token.type, token.contract_address_hash],
select: %Address.Token{
contract_address_hash: token.contract_address_hash,
inserted_at: max(token.inserted_at),
@ -53,22 +52,40 @@ defmodule Explorer.Chain.Address.Token do
balance: balance.value,
decimals: max(token.decimals),
type: token.type
}
},
group_by: [token.name, token.symbol, balance.value, token.type, token.contract_address_hash, balance.block_number]
)
end
defp order(query) do
from(
token in subquery(query),
order_by: fragment("? DESC, ? ASC NULLS LAST", token.type, token.name)
)
end
defp join_with_last_balance(address_hash) do
last_balance_query =
from(
tb in CurrentTokenBalance,
where: tb.address_hash == ^address_hash,
select: %{value: tb.value, token_contract_address_hash: tb.token_contract_address_hash}
ctb in CurrentTokenBalance,
where: ctb.address_hash == ^address_hash,
select: %{
value: ctb.value,
token_contract_address_hash: ctb.token_contract_address_hash,
block_number: ctb.block_number,
max_block_number: over(max(ctb.block_number), :w)
},
windows: [
w: [partition_by: [ctb.token_contract_address_hash, ctb.address_hash]]
]
)
from(
t in Chain.Token,
join: tb in subquery(last_balance_query),
on: tb.token_contract_address_hash == t.contract_address_hash
on: tb.token_contract_address_hash == t.contract_address_hash,
where: tb.block_number == tb.max_block_number,
distinct: t.contract_address_hash
)
end

@ -109,8 +109,16 @@ defmodule Explorer.Chain.Import.Runner.Address.CurrentTokenBalances do
# Enforce ShareLocks tables order (see docs: sharelocks.md)
multi
|> Multi.run(:acquire_contract_address_tokens, fn repo, _ ->
contract_address_hashes = changes_list |> Enum.map(& &1.token_contract_address_hash) |> Enum.uniq()
Tokens.acquire_contract_address_tokens(repo, contract_address_hashes)
token_contract_address_hashes_and_ids =
changes_list
|> Enum.map(fn change ->
token_id = get_tokend_id(change)
{change.token_contract_address_hash, token_id}
end)
|> Enum.uniq()
Tokens.acquire_contract_address_tokens(repo, token_contract_address_hashes_and_ids)
end)
|> Multi.run(:address_current_token_balances, fn repo, _ ->
insert(repo, changes_list, insert_options)
@ -131,6 +139,10 @@ defmodule Explorer.Chain.Import.Runner.Address.CurrentTokenBalances do
end)
end
defp get_tokend_id(change) do
if Map.has_key?(change, :token_id), do: change.token_id, else: nil
end
@impl Import.Runner
def timeout, do: @timeout
@ -198,6 +210,13 @@ defmodule Explorer.Chain.Import.Runner.Address.CurrentTokenBalances do
| {:error, [Changeset.t()]}
defp insert(repo, changes_list, %{timeout: timeout, timestamps: timestamps} = options)
when is_atom(repo) and is_list(changes_list) do
inserted_changes_list =
insert_changes_list_with_and_without_token_id(changes_list, repo, timestamps, timeout, options)
{:ok, inserted_changes_list}
end
def insert_changes_list_with_and_without_token_id(changes_list, repo, timestamps, timeout, options) do
on_conflict = Map.get_lazy(options, :on_conflict, &default_on_conflict/0)
# Enforce CurrentTokenBalance ShareLocks order (see docs: sharelocks.md)

@ -100,10 +100,12 @@ defmodule Explorer.Chain.Import.Runner.Address.TokenBalances do
{token_contract_address_hash, address_hash, block_number}
end)
|> Enum.map(fn {_, grouped_address_token_balances} ->
if Enum.count(grouped_address_token_balances) > 1 do
Enum.max_by(grouped_address_token_balances, fn %{value_fetched_at: value_fetched_at} -> value_fetched_at end)
dedup = Enum.dedup(grouped_address_token_balances)
if Enum.count(dedup) > 1 do
Enum.max_by(dedup, fn %{value_fetched_at: value_fetched_at} -> value_fetched_at end)
else
Enum.at(grouped_address_token_balances, 0)
Enum.at(dedup, 0)
end
end)
|> Enum.sort_by(&{&1.token_contract_address_hash, &1.address_hash, &1.block_number})

@ -119,13 +119,13 @@ defmodule Explorer.Chain.Import.Runner.Blocks do
query =
from(ctb in Address.CurrentTokenBalance,
where: ctb.block_number in ^consensus_block_numbers,
select: ctb.token_contract_address_hash,
distinct: ctb.token_contract_address_hash
select: {ctb.token_contract_address_hash, ctb.token_id},
distinct: [ctb.token_contract_address_hash, ctb.token_id]
)
contract_address_hashes = repo.all(query)
contract_address_hashes_and_token_ids = repo.all(query)
Tokens.acquire_contract_address_tokens(repo, contract_address_hashes)
Tokens.acquire_contract_address_tokens(repo, contract_address_hashes_and_token_ids)
end
defp fork_transactions(%{
@ -382,7 +382,7 @@ defmodule Explorer.Chain.Import.Runner.Blocks do
ordered_query =
from(ctb in Address.CurrentTokenBalance,
where: ctb.block_number in ^consensus_block_numbers,
select: map(ctb, [:address_hash, :token_contract_address_hash]),
select: map(ctb, [:address_hash, :token_contract_address_hash, :token_id]),
# Enforce CurrentTokenBalance ShareLocks order (see docs: sharelocks.md)
order_by: [
ctb.token_contract_address_hash,
@ -407,8 +407,10 @@ defmodule Explorer.Chain.Import.Runner.Blocks do
inner_join: ordered_address_current_token_balance in subquery(ordered_query),
on:
ordered_address_current_token_balance.address_hash == ctb.address_hash and
ordered_address_current_token_balance.token_contract_address_hash ==
ctb.token_contract_address_hash
ordered_address_current_token_balance.token_contract_address_hash == ctb.token_contract_address_hash and
((is_nil(ordered_address_current_token_balance.token_id) and is_nil(ctb.token_id)) or
(ordered_address_current_token_balance.token_id == ctb.token_id and
not is_nil(ordered_address_current_token_balance.token_id) and not is_nil(ctb.token_id)))
)
try do
@ -423,7 +425,11 @@ defmodule Explorer.Chain.Import.Runner.Blocks do
defp derive_address_current_token_balances(_, [], _), do: {:ok, []}
defp derive_address_current_token_balances(repo, deleted_address_current_token_balances, %{timeout: timeout})
defp derive_address_current_token_balances(
repo,
deleted_address_current_token_balances,
%{timeout: timeout} = options
)
when is_list(deleted_address_current_token_balances) do
final_query = derive_address_current_token_balances_grouped_query(deleted_address_current_token_balances)
@ -455,41 +461,17 @@ defmodule Explorer.Chain.Import.Runner.Blocks do
new_current_token_balance_query
|> repo.all()
ordered_current_token_balance_no_token_id =
current_token_balance
|> Enum.filter(&is_nil(&1.token_id))
# Enforce CurrentTokenBalance ShareLocks order (see docs: sharelocks.md)
|> Enum.sort_by(&{&1.token_contract_address_hash, &1.address_hash})
{_total, result_no_token_id} =
repo.insert_all(
Address.CurrentTokenBalance,
ordered_current_token_balance_no_token_id,
# No `ON CONFLICT` because `delete_address_current_token_balances`
# should have removed any conflicts.
#
returning: [:address_hash, :token_contract_address_hash, :block_number, :value],
timeout: timeout
)
ordered_current_token_balance_with_token_id =
current_token_balance
|> Enum.filter(&(!is_nil(&1.token_id)))
# Enforce CurrentTokenBalance ShareLocks order (see docs: sharelocks.md)
|> Enum.sort_by(&{&1.token_contract_address_hash, &1.token_id, &1.address_hash})
timestamps = Import.timestamps()
{_total, result_with_token_id} =
repo.insert_all(
Address.CurrentTokenBalance,
ordered_current_token_balance_with_token_id,
# No `ON CONFLICT` because `delete_address_current_token_balances`
# should have removed any conflicts.
returning: [:address_hash, :token_contract_address_hash, :block_number, :value],
timeout: timeout
result =
CurrentTokenBalances.insert_changes_list_with_and_without_token_id(
current_token_balance,
repo,
timestamps,
timeout,
options
)
result = result_with_token_id ++ result_no_token_id
derived_address_current_token_balances =
Enum.map(result, &Map.take(&1, [:address_hash, :token_contract_address_hash, :token_id, :block_number, :value]))

@ -53,7 +53,7 @@ defmodule Explorer.Token.BalanceReader do
[
%{token_contract_address_hash: String.t(), address_hash: String.t(), block_number: non_neg_integer()}
],
Map.t()
[%{}]
) :: [{:ok, non_neg_integer()} | {:error, String.t()}]
def get_balances_of_with_abi(token_balance_requests, abi) do
formatted_balances_requests =

@ -0,0 +1,25 @@
defmodule Explorer.Repo.Migrations.RemoveDuplicatesOfCurrentTokenBalances do
use Ecto.Migration
def change do
execute("""
DELETE FROM address_current_token_balances
WHERE id in (
SELECT a.id FROM (SELECT actb.*
FROM address_current_token_balances actb
INNER JOIN tokens t
ON actb.token_contract_address_hash = t.contract_address_hash
WHERE t.type='ERC-721') AS a
LEFT JOIN
(SELECT actb.address_hash, actb.token_contract_address_hash, MAX(actb.value_fetched_at) AS max_value_fetched_at
FROM address_current_token_balances actb
INNER JOIN tokens t
ON actb.token_contract_address_hash = t.contract_address_hash
WHERE t.type='ERC-721'
GROUP BY token_contract_address_hash, address_hash) c
ON a.address_hash=c.address_hash AND a.token_contract_address_hash = c.token_contract_address_hash AND a.value_fetched_at = c.max_value_fetched_at
WHERE c.address_hash IS NULL
);
""")
end
end

@ -86,6 +86,9 @@ defmodule Explorer.Chain.Import.Runner.Address.CurrentTokenBalancesTest do
value_4 = Decimal.new(1)
token_id_4 = Decimal.new(1)
value_5 = Decimal.new(2)
token_id_5 = Decimal.new(555)
block_number = 1
assert {:ok,
@ -98,6 +101,13 @@ defmodule Explorer.Chain.Import.Runner.Address.CurrentTokenBalancesTest do
value: ^value_3,
token_id: ^token_id_3
},
%Explorer.Chain.Address.CurrentTokenBalance{
address_hash: ^address_hash,
block_number: ^block_number,
token_contract_address_hash: ^token_erc_721_contract_address_hash,
value: ^value_5,
token_id: nil
},
%Explorer.Chain.Address.CurrentTokenBalance{
address_hash: ^address_hash,
block_number: ^block_number,
@ -111,13 +121,6 @@ defmodule Explorer.Chain.Import.Runner.Address.CurrentTokenBalancesTest do
token_contract_address_hash: ^token_contract_address_hash,
value: ^value_2,
token_id: ^token_id_2
},
%Explorer.Chain.Address.CurrentTokenBalance{
address_hash: ^address_hash,
block_number: ^block_number,
token_contract_address_hash: ^token_erc_721_contract_address_hash,
value: ^value_4,
token_id: ^token_id_4
}
],
address_current_token_balances_update_token_holder_counts: [
@ -172,6 +175,15 @@ defmodule Explorer.Chain.Import.Runner.Address.CurrentTokenBalancesTest do
value_fetched_at: DateTime.utc_now(),
token_id: token_id_4,
token_type: "ERC-721"
},
%{
address_hash: address_hash,
block_number: block_number,
token_contract_address_hash: token_erc_721.contract_address_hash,
value: value_5,
value_fetched_at: DateTime.utc_now(),
token_id: token_id_5,
token_type: "ERC-721"
}
],
options

@ -31,10 +31,27 @@ defmodule Indexer.Transform.TokenTransfers do
end)
|> Enum.reduce(initial_acc, &do_parse(&1, &2, :erc1155))
%{
tokens: erc1155_token_transfers.tokens ++ erc20_and_erc721_token_transfers.tokens,
token_transfers: erc1155_token_transfers.token_transfers ++ erc20_and_erc721_token_transfers.token_transfers
tokens = erc1155_token_transfers.tokens ++ erc20_and_erc721_token_transfers.tokens
token_transfers = erc1155_token_transfers.token_transfers ++ erc20_and_erc721_token_transfers.token_transfers
token_transfers
|> Enum.filter(fn token_transfer ->
token_transfer.to_address_hash == @burn_address || token_transfer.from_address_hash == @burn_address
end)
|> Enum.map(fn token_transfer ->
token_transfer.token_contract_address_hash
end)
|> Enum.dedup()
|> Enum.each(&update_token/1)
tokens_dedup = tokens |> Enum.dedup()
token_transfers_from_logs_dedup = %{
tokens: tokens_dedup,
token_transfers: token_transfers
}
token_transfers_from_logs_dedup
end
defp do_parse(log, %{tokens: tokens, token_transfers: token_transfers} = acc, type \\ :erc20_erc721) do

Loading…
Cancel
Save