Update existing tokens type if got transfer with higher type priority

pull/8812/head
Qwerty5Uiop 1 year ago
parent 47f2075f2d
commit 209e65d849
  1. 1
      CHANGELOG.md
  2. 2
      apps/indexer/lib/indexer/block/fetcher.ex
  3. 16
      apps/indexer/lib/indexer/transform/token_transfers.ex

@ -10,6 +10,7 @@
- [#9062](https://github.com/blockscout/blockscout/pull/9062) - Fix blockscout-ens integration
- [#9061](https://github.com/blockscout/blockscout/pull/9061) - Arbitrum allow tx receipt gasUsedForL1 field
- [#8812](https://github.com/blockscout/blockscout/pull/8812) - Update existing tokens type if got transfer with higher type priority
### Chore

@ -190,7 +190,7 @@ defmodule Indexer.Block.Fetcher do
block_rewards: %{errors: beneficiaries_errors, params: beneficiaries_with_gas_payment},
logs: %{params: logs},
token_transfers: %{params: token_transfers},
tokens: %{on_conflict: :nothing, params: tokens},
tokens: %{params: tokens},
transactions: %{params: transactions_with_receipts},
withdrawals: %{params: withdrawals_params},
token_instances: %{params: token_instances}

@ -81,22 +81,18 @@ defmodule Indexer.Transform.TokenTransfers do
end)
|> Map.new()
existing_tokens =
existing_token_types_map
|> Map.keys()
|> Enum.map(&to_string/1)
new_tokens_token_transfers = Enum.filter(token_transfers, &(&1.token_contract_address_hash not in existing_tokens))
new_token_types_map =
new_tokens_token_transfers
token_types_map =
token_transfers
|> Enum.group_by(& &1.token_contract_address_hash)
|> Enum.map(fn {contract_address_hash, transfers} ->
{contract_address_hash, define_token_type(transfers)}
end)
|> Map.new()
actual_token_types_map = Map.merge(new_token_types_map, existing_token_types_map)
actual_token_types_map =
Map.merge(token_types_map, existing_token_types_map, fn _k, new_type, old_type ->
if token_type_priority(old_type) > token_type_priority(new_type), do: old_type, else: new_type
end)
actual_tokens =
Enum.map(tokens, fn %{contract_address_hash: hash} = token ->

Loading…
Cancel
Save