Ignore burn address token balance for Tokens ERC-721

As we always get errors trying to fetch token balances when the address
is the burn addres for Tokens ERC-721, we are gonna ignore them when we
are processing the token balances from the token transfer.
pull/830/head
Felipe Renan 6 years ago committed by Luke Imhoff
parent 30e2bb4d65
commit cc89b1f6db
  1. 37
      apps/indexer/lib/indexer/address/token_balances.ex
  2. 9
      apps/indexer/lib/indexer/token_transfers.ex
  3. 38
      apps/indexer/test/indexer/address/token_balances_test.exs
  4. 9
      apps/indexer/test/indexer/token_transfers_test.exs

@ -8,16 +8,17 @@ defmodule Indexer.Address.TokenBalances do
end end
defp reducer({:token_transfers_params, token_transfers_params}, initial) when is_list(token_transfers_params) do defp reducer({:token_transfers_params, token_transfers_params}, initial) when is_list(token_transfers_params) do
Enum.reduce(token_transfers_params, initial, fn %{ token_transfers_params
block_number: block_number, |> ignore_burn_address_transfers_for_token_erc_721
from_address_hash: from_address_hash, |> Enum.reduce(initial, fn %{
to_address_hash: to_address_hash, block_number: block_number,
token_contract_address_hash: token_contract_address_hash from_address_hash: from_address_hash,
}, to_address_hash: to_address_hash,
acc token_contract_address_hash: token_contract_address_hash
when is_integer(block_number) and is_binary(from_address_hash) and },
is_binary(to_address_hash) and acc
is_binary(token_contract_address_hash) -> when is_integer(block_number) and is_binary(from_address_hash) and
is_binary(to_address_hash) and is_binary(token_contract_address_hash) ->
acc acc
|> MapSet.put(%{ |> MapSet.put(%{
address_hash: from_address_hash, address_hash: from_address_hash,
@ -36,4 +37,20 @@ defmodule Indexer.Address.TokenBalances do
}) })
end) end)
end end
defp ignore_burn_address_transfers_for_token_erc_721(token_transfers_params) do
Enum.filter(token_transfers_params, &do_filter_burn_address/1)
end
def do_filter_burn_address(%{from_address_hash: "0x0000000000000000000000000000000000000000", token_type: "ERC-721"}) do
false
end
def do_filter_burn_address(%{to_address_hash: "0x0000000000000000000000000000000000000000", token_type: "ERC-721"}) do
false
end
def do_filter_burn_address(_token_balance_param) do
true
end
end end

@ -44,7 +44,8 @@ defmodule Indexer.TokenTransfers do
from_address_hash: truncate_address_hash(log.second_topic), from_address_hash: truncate_address_hash(log.second_topic),
to_address_hash: truncate_address_hash(log.third_topic), to_address_hash: truncate_address_hash(log.third_topic),
token_contract_address_hash: log.address_hash, token_contract_address_hash: log.address_hash,
transaction_hash: log.transaction_hash transaction_hash: log.transaction_hash,
token_type: "ERC-20"
} }
token = %{ token = %{
@ -67,7 +68,8 @@ defmodule Indexer.TokenTransfers do
to_address_hash: truncate_address_hash(log.third_topic), to_address_hash: truncate_address_hash(log.third_topic),
token_contract_address_hash: log.address_hash, token_contract_address_hash: log.address_hash,
token_id: token_id || 0, token_id: token_id || 0,
transaction_hash: log.transaction_hash transaction_hash: log.transaction_hash,
token_type: "ERC-721"
} }
token = %{ token = %{
@ -90,7 +92,8 @@ defmodule Indexer.TokenTransfers do
to_address_hash: encode_address_hash(to_address_hash), to_address_hash: encode_address_hash(to_address_hash),
token_contract_address_hash: log.address_hash, token_contract_address_hash: log.address_hash,
token_id: token_id, token_id: token_id,
transaction_hash: log.transaction_hash transaction_hash: log.transaction_hash,
token_type: "ERC-721"
} }
token = %{ token = %{

@ -34,5 +34,43 @@ defmodule Indexer.Address.TokenBalancesTest do
assert %{address_hash: to_address_hash, block_number: block_number} assert %{address_hash: to_address_hash, block_number: block_number}
assert %{address_hash: token_contract_address_hash, block_number: block_number} assert %{address_hash: token_contract_address_hash, block_number: block_number}
end end
test "does not set params when the from_address_hash is the burn address for the Token ERC-721" do
block_number = 1
from_address_hash = "0x0000000000000000000000000000000000000000"
to_address_hash = "0x5b8410f67eb8040bb1cd1e8a4ff9d5f6ce678a15"
token_contract_address_hash = "0xe18035bf8712672935fdb4e5e431b1a0183d2dfc"
token_transfer_params = %{
block_number: block_number,
from_address_hash: from_address_hash,
to_address_hash: to_address_hash,
token_contract_address_hash: token_contract_address_hash,
token_type: "ERC-721"
}
params_set = TokenBalances.params_set(%{token_transfers_params: [token_transfer_params]})
assert MapSet.size(params_set) == 0
end
test "does not set params when the to_address_hash is the burn address for the Token ERC-721" do
block_number = 1
from_address_hash = "0x5b8410f67eb8040bb1cd1e8a4ff9d5f6ce678a15"
to_address_hash = "0x0000000000000000000000000000000000000000"
token_contract_address_hash = "0xe18035bf8712672935fdb4e5e431b1a0183d2dfc"
token_transfer_params = %{
block_number: block_number,
from_address_hash: from_address_hash,
to_address_hash: to_address_hash,
token_contract_address_hash: token_contract_address_hash,
token_type: "ERC-721"
}
params_set = TokenBalances.params_set(%{token_transfers_params: [token_transfer_params]})
assert MapSet.size(params_set) == 0
end
end end
end end

@ -66,7 +66,8 @@ defmodule Indexer.TokenTransfersTest do
to_address_hash: truncated_hash(log_3.third_topic), to_address_hash: truncated_hash(log_3.third_topic),
token_contract_address_hash: log_3.address_hash, token_contract_address_hash: log_3.address_hash,
token_id: 183, token_id: 183,
transaction_hash: log_3.transaction_hash transaction_hash: log_3.transaction_hash,
token_type: "ERC-721"
}, },
%{ %{
amount: Decimal.new(17_000_000_000_000_000_000), amount: Decimal.new(17_000_000_000_000_000_000),
@ -75,7 +76,8 @@ defmodule Indexer.TokenTransfersTest do
from_address_hash: truncated_hash(log_1.second_topic), from_address_hash: truncated_hash(log_1.second_topic),
to_address_hash: truncated_hash(log_1.third_topic), to_address_hash: truncated_hash(log_1.third_topic),
token_contract_address_hash: log_1.address_hash, token_contract_address_hash: log_1.address_hash,
transaction_hash: log_1.transaction_hash transaction_hash: log_1.transaction_hash,
token_type: "ERC-20"
} }
] ]
} }
@ -113,7 +115,8 @@ defmodule Indexer.TokenTransfersTest do
to_address_hash: "0xbe8cdfc13ffda20c844ac3da2b53a23ac5787f1e", to_address_hash: "0xbe8cdfc13ffda20c844ac3da2b53a23ac5787f1e",
token_contract_address_hash: log.address_hash, token_contract_address_hash: log.address_hash,
token_id: 14_939, token_id: 14_939,
transaction_hash: log.transaction_hash transaction_hash: log.transaction_hash,
token_type: "ERC-721"
} }
] ]
} }

Loading…
Cancel
Save