Merge pull request #5480 from blockscout/vb-remove-double-balances_params_to_address_params-func

Remove duplicate of balances_params_to_address_params function
pull/5488/head
Victor Baranov 3 years ago committed by GitHub
commit 1b815df72b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 13
      apps/indexer/lib/indexer/fetcher/contract_code.ex

@ -30,6 +30,7 @@
- [#5239](https://github.com/blockscout/blockscout/pull/5239) - Add accounting for block rewards in `getblockreward` api method
### Chore
- [#5480](https://github.com/blockscout/blockscout/pull/5480) - Remove duplicate of balances_params_to_address_params function
- [#5473](https://github.com/blockscout/blockscout/pull/5473) - Refactor daily coin balances fetcher
- [#5458](https://github.com/blockscout/blockscout/pull/5458) - Decrease min safe polling period for realtime fetcher
- [#5456](https://github.com/blockscout/blockscout/pull/5456) - Ignore arbitrary block details fields for custom Ethereum clients

@ -14,6 +14,7 @@ defmodule Indexer.Fetcher.ContractCode do
alias Explorer.Chain.{Block, Hash}
alias Explorer.Chain.Cache.Accounts
alias Indexer.{BufferedTask, Tracer}
alias Indexer.Fetcher.CoinBalance, as: CoinBalanceFetcher
alias Indexer.Transform.Addresses
@behaviour BufferedTask
@ -119,7 +120,7 @@ defmodule Indexer.Fetcher.ContractCode do
|> EthereumJSONRPC.fetch_balances(json_rpc_named_arguments)
|> case do
{:ok, fetched_balances} ->
balance_addresses_params = balances_params_to_address_params(fetched_balances.params_list)
balance_addresses_params = CoinBalanceFetcher.balances_params_to_address_params(fetched_balances.params_list)
merged_addresses_params = Addresses.merge_addresses(addresses_params ++ balance_addresses_params)
@ -154,16 +155,6 @@ defmodule Indexer.Fetcher.ContractCode do
end
end
def balances_params_to_address_params(balances_params) do
balances_params
|> Enum.group_by(fn %{address_hash: address_hash} -> address_hash end)
|> Map.values()
|> Stream.map(&Enum.max_by(&1, fn %{block_number: block_number} -> block_number end))
|> Enum.map(fn %{address_hash: address_hash, block_number: block_number, value: value} ->
%{hash: address_hash, fetched_coin_balance_block_number: block_number, fetched_coin_balance: value}
end)
end
defp coin_balances_request_params(entries) do
Enum.map(entries, fn {block_number, created_contract_address_hash_bytes, _transaction_hash_bytes} ->
{:ok, created_contract_address_hash} = Hash.Address.cast(created_contract_address_hash_bytes)

Loading…
Cancel
Save