pull/6391/head
Qwerty5Uiop 2 years ago
parent bfa4296a42
commit 039be2566b
  1. 20
      apps/indexer/lib/indexer/fetcher/token_instance.ex
  2. 15
      apps/indexer/lib/indexer/transform/address_token_balances.ex
  3. 4
      apps/indexer/test/indexer/fetcher/token_instance_test.exs
  4. 4
      apps/indexer/test/indexer/transform/address_token_balances_test.exs

@ -51,9 +51,9 @@ defmodule Indexer.Fetcher.TokenInstance do
end end
@impl BufferedTask @impl BufferedTask
def run([%{contract_address_hash: hash, token_ids: token_ids}], _json_rpc_named_arguments) do def run([%{contract_address_hash: hash, token_id: token_id}], _json_rpc_named_arguments) do
Enum.each(token_ids, &fetch_instance(hash, &1)) fetch_instance(hash, token_id)
update_current_token_balances(hash, token_ids) update_current_token_balances(hash, token_id)
:ok :ok
end end
@ -92,16 +92,17 @@ defmodule Indexer.Fetcher.TokenInstance do
end end
end end
defp update_current_token_balances(token_contract_address_hash, token_ids) do defp update_current_token_balances(token_contract_address_hash, token_id) do
token_ids token_id
|> Enum.map(&instance_owner_request(token_contract_address_hash, &1)) |> instance_owner_request(token_contract_address_hash)
|> List.wrap()
|> InstanceOwnerReader.get_owner_of() |> InstanceOwnerReader.get_owner_of()
|> Enum.map(&current_token_balances_import_params/1) |> Enum.map(&current_token_balances_import_params/1)
|> all_import_params() |> all_import_params()
|> Chain.import() |> Chain.import()
end end
defp instance_owner_request(token_contract_address_hash, token_id) do defp instance_owner_request(token_id, token_contract_address_hash) do
%{ %{
token_contract_address_hash: to_string(token_contract_address_hash), token_contract_address_hash: to_string(token_contract_address_hash),
token_id: Decimal.to_integer(token_id) token_id: Decimal.to_integer(token_id)
@ -157,11 +158,14 @@ defmodule Indexer.Fetcher.TokenInstance do
token_transfers token_transfers
|> Enum.reject(fn token_transfer -> is_nil(token_transfer.token_ids) end) |> Enum.reject(fn token_transfer -> is_nil(token_transfer.token_ids) end)
|> Enum.map(fn token_transfer -> |> Enum.map(fn token_transfer ->
Enum.map(token_transfer.token_ids, fn token_id ->
%{ %{
contract_address_hash: token_transfer.token_contract_address_hash, contract_address_hash: token_transfer.token_contract_address_hash,
token_ids: token_transfer.token_ids token_id: token_id
} }
end) end)
end)
|> List.flatten()
|> Enum.uniq() |> Enum.uniq()
BufferedTask.buffer(__MODULE__, data) BufferedTask.buffer(__MODULE__, data)

@ -11,30 +11,23 @@ defmodule Indexer.Transform.AddressTokenBalances do
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
token_transfers_params token_transfers_params
|> ignore_burn_address_transfers_for_token_erc_721 |> ignore_burn_address_transfers_for_token_erc_721()
|> Enum.reduce(initial, fn %{ |> Enum.reduce(initial, fn %{
block_number: block_number, block_number: block_number,
from_address_hash: from_address_hash, from_address_hash: from_address_hash,
to_address_hash: to_address_hash, to_address_hash: to_address_hash,
token_contract_address_hash: token_contract_address_hash, token_contract_address_hash: token_contract_address_hash,
token_id: token_id, token_ids: token_ids,
token_type: token_type token_type: token_type
} = params, },
acc acc
when is_integer(block_number) and is_binary(from_address_hash) and when is_integer(block_number) and is_binary(from_address_hash) and
is_binary(to_address_hash) and is_binary(token_contract_address_hash) -> is_binary(to_address_hash) and is_binary(token_contract_address_hash) ->
if params[:token_ids] && token_type == "ERC-1155" do Enum.reduce(token_ids || [nil], acc, fn id, sub_acc ->
params[:token_ids]
|> Enum.reduce(acc, fn id, sub_acc ->
sub_acc sub_acc
|> add_token_balance_address(from_address_hash, token_contract_address_hash, id, token_type, block_number) |> add_token_balance_address(from_address_hash, token_contract_address_hash, id, token_type, block_number)
|> add_token_balance_address(to_address_hash, token_contract_address_hash, id, token_type, block_number) |> add_token_balance_address(to_address_hash, token_contract_address_hash, id, token_type, block_number)
end) end)
else
acc
|> add_token_balance_address(from_address_hash, token_contract_address_hash, token_id, token_type, block_number)
|> add_token_balance_address(to_address_hash, token_contract_address_hash, token_id, token_type, block_number)
end
end) end)
end end

@ -35,7 +35,7 @@ defmodule Indexer.Fetcher.TokenInstanceTest do
end) end)
TokenInstance.run( TokenInstance.run(
[%{contract_address_hash: token_contract_address_hash, token_ids: [token_id]}], [%{contract_address_hash: token_contract_address_hash, token_id: token_id}],
nil nil
) )
@ -70,7 +70,7 @@ defmodule Indexer.Fetcher.TokenInstanceTest do
end) end)
TokenInstance.run( TokenInstance.run(
[%{contract_address_hash: token_contract_address_hash, token_ids: [token_id]}], [%{contract_address_hash: token_contract_address_hash, token_id: token_id}],
nil nil
) )

@ -25,7 +25,7 @@ defmodule Indexer.Transform.AddressTokenBalancesTest do
from_address_hash: from_address_hash, from_address_hash: from_address_hash,
to_address_hash: to_address_hash, to_address_hash: to_address_hash,
token_contract_address_hash: token_contract_address_hash, token_contract_address_hash: token_contract_address_hash,
token_id: nil, token_ids: nil,
token_type: "ERC-20" token_type: "ERC-20"
} }
@ -49,7 +49,7 @@ defmodule Indexer.Transform.AddressTokenBalancesTest do
to_address_hash: to_address_hash, to_address_hash: to_address_hash,
token_contract_address_hash: token_contract_address_hash, token_contract_address_hash: token_contract_address_hash,
token_type: "ERC-721", token_type: "ERC-721",
token_id: nil token_ids: nil
} }
params_set = AddressTokenBalances.params_set(%{token_transfers_params: [token_transfer_params]}) params_set = AddressTokenBalances.params_set(%{token_transfers_params: [token_transfer_params]})

Loading…
Cancel
Save