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
@impl BufferedTask
def run([%{contract_address_hash: hash, token_ids: token_ids}], _json_rpc_named_arguments) do
Enum.each(token_ids, &fetch_instance(hash, &1))
update_current_token_balances(hash, token_ids)
def run([%{contract_address_hash: hash, token_id: token_id}], _json_rpc_named_arguments) do
fetch_instance(hash, token_id)
update_current_token_balances(hash, token_id)
:ok
end
@ -92,16 +92,17 @@ defmodule Indexer.Fetcher.TokenInstance do
end
end
defp update_current_token_balances(token_contract_address_hash, token_ids) do
token_ids
|> Enum.map(&instance_owner_request(token_contract_address_hash, &1))
defp update_current_token_balances(token_contract_address_hash, token_id) do
token_id
|> instance_owner_request(token_contract_address_hash)
|> List.wrap()
|> InstanceOwnerReader.get_owner_of()
|> Enum.map(&current_token_balances_import_params/1)
|> all_import_params()
|> Chain.import()
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_id: Decimal.to_integer(token_id)
@ -157,11 +158,14 @@ defmodule Indexer.Fetcher.TokenInstance do
token_transfers
|> Enum.reject(fn token_transfer -> is_nil(token_transfer.token_ids) end)
|> Enum.map(fn token_transfer ->
Enum.map(token_transfer.token_ids, fn token_id ->
%{
contract_address_hash: token_transfer.token_contract_address_hash,
token_ids: token_transfer.token_ids
token_id: token_id
}
end)
end)
|> List.flatten()
|> Enum.uniq()
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
token_transfers_params
|> ignore_burn_address_transfers_for_token_erc_721
|> ignore_burn_address_transfers_for_token_erc_721()
|> Enum.reduce(initial, fn %{
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_id: token_id,
token_ids: token_ids,
token_type: token_type
} = params,
},
acc
when is_integer(block_number) and is_binary(from_address_hash) and
is_binary(to_address_hash) and is_binary(token_contract_address_hash) ->
if params[:token_ids] && token_type == "ERC-1155" do
params[:token_ids]
|> Enum.reduce(acc, fn id, sub_acc ->
Enum.reduce(token_ids || [nil], acc, fn id, sub_acc ->
sub_acc
|> 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)
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

@ -35,7 +35,7 @@ defmodule Indexer.Fetcher.TokenInstanceTest do
end)
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
)
@ -70,7 +70,7 @@ defmodule Indexer.Fetcher.TokenInstanceTest do
end)
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
)

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

Loading…
Cancel
Save