diff --git a/apps/indexer/lib/indexer/address/coin_balances.ex b/apps/indexer/lib/indexer/address/coin_balances.ex index 03f0c4f847..83441927c1 100644 --- a/apps/indexer/lib/indexer/address/coin_balances.ex +++ b/apps/indexer/lib/indexer/address/coin_balances.ex @@ -28,11 +28,18 @@ defmodule Indexer.Address.CoinBalances do end defp reducer({:logs_params, logs_params}, acc) when is_list(logs_params) do - # a log MUST have and address_hash - Enum.into(logs_params, acc, fn %{address_hash: address_hash, block_number: block_number} - when is_binary(address_hash) and is_integer(block_number) -> + # a log MUST have address_hash and block_number + logs_params + |> Enum.into(acc, fn %{address_hash: address_hash, block_number: block_number} + when is_binary(address_hash) and is_integer(block_number) -> + %{address_hash: address_hash, block_number: block_number} + + %{type: "pending"} -> + nil end) + |> Enum.reject(fn val -> is_nil(val) end) + |> MapSet.new() end defp reducer({:transactions_params, transactions_params}, initial) when is_list(transactions_params) do diff --git a/apps/indexer/test/indexer/address/coin_balances_test.exs b/apps/indexer/test/indexer/address/coin_balances_test.exs index a0161ce013..5eae99b22c 100644 --- a/apps/indexer/test/indexer/address/coin_balances_test.exs +++ b/apps/indexer/test/indexer/address/coin_balances_test.exs @@ -114,7 +114,33 @@ defmodule Indexer.Address.CoinBalancesTest do params_set = CoinBalances.params_set(%{logs_params: [log_params]}) assert MapSet.size(params_set) == 1 - assert %{address_hash: address_hash, block_number: block_number} + assert MapSet.new([%{address_hash: address_hash, block_number: block_number}]) == params_set + end + + test "with log skips pending transactions" do + block_number = 1 + + address_hash = + Factory.address_hash() + |> to_string() + + log_params1 = + :log + |> Factory.params_for() + |> Map.put(:block_number, nil) + |> Map.put(:address_hash, address_hash) + |> Map.put(:type, "pending") + + log_params2 = + :log + |> Factory.params_for() + |> Map.put(:block_number, block_number) + |> Map.put(:address_hash, address_hash) + + params_set = CoinBalances.params_set(%{logs_params: [log_params1, log_params2]}) + + assert MapSet.size(params_set) == 1 + assert MapSet.new([%{address_hash: address_hash, block_number: block_number}]) == params_set end test "with transaction without to_address_hash extracts from_address_hash" do