|
|
@ -9,7 +9,7 @@ defmodule Indexer.Fetcher.TokenInstance do |
|
|
|
require Logger |
|
|
|
require Logger |
|
|
|
|
|
|
|
|
|
|
|
alias Explorer.{Chain, Repo} |
|
|
|
alias Explorer.{Chain, Repo} |
|
|
|
alias Explorer.Chain.{Cache.BlockNumber, Token} |
|
|
|
alias Explorer.Chain.{Address, Cache.BlockNumber, Token} |
|
|
|
alias Explorer.Token.{InstanceMetadataRetriever, InstanceOwnerReader} |
|
|
|
alias Explorer.Token.{InstanceMetadataRetriever, InstanceOwnerReader} |
|
|
|
alias Indexer.BufferedTask |
|
|
|
alias Indexer.BufferedTask |
|
|
|
|
|
|
|
|
|
|
@ -100,17 +100,12 @@ defmodule Indexer.Fetcher.TokenInstance do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp update_current_token_balances(token_contract_address_hash, token_ids) do |
|
|
|
defp update_current_token_balances(token_contract_address_hash, token_ids) do |
|
|
|
import_params = |
|
|
|
|
|
|
|
token_ids |
|
|
|
token_ids |
|
|
|
|> Enum.map(&instance_owner_request(token_contract_address_hash, &1)) |
|
|
|
|> Enum.map(&instance_owner_request(token_contract_address_hash, &1)) |
|
|
|
|> InstanceOwnerReader.get_owner_of() |
|
|
|
|> InstanceOwnerReader.get_owner_of() |
|
|
|
|> Enum.map(¤t_token_balances_import_params/1) |
|
|
|
|> Enum.map(¤t_token_balances_import_params/1) |
|
|
|
|
|
|
|
|> all_import_params() |
|
|
|
Chain.import(%{ |
|
|
|
|> Chain.import() |
|
|
|
address_current_token_balances: %{ |
|
|
|
|
|
|
|
params: import_params |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp instance_owner_request(token_contract_address_hash, token_id) do |
|
|
|
defp instance_owner_request(token_contract_address_hash, token_id) do |
|
|
@ -132,6 +127,29 @@ defmodule Indexer.Fetcher.TokenInstance do |
|
|
|
} |
|
|
|
} |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defp all_import_params(balances_import_params) do |
|
|
|
|
|
|
|
addresses_import_params = |
|
|
|
|
|
|
|
balances_import_params |
|
|
|
|
|
|
|
|> Enum.reduce([], fn %{address_hash: address_hash}, acc -> |
|
|
|
|
|
|
|
case Repo.get_by(Address, hash: address_hash) do |
|
|
|
|
|
|
|
nil -> [%{hash: address_hash} | acc] |
|
|
|
|
|
|
|
_address -> acc |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end) |
|
|
|
|
|
|
|
|> case do |
|
|
|
|
|
|
|
[] -> %{} |
|
|
|
|
|
|
|
params -> %{addresses: %{params: params}} |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
current_token_balances_import_params = %{ |
|
|
|
|
|
|
|
address_current_token_balances: %{ |
|
|
|
|
|
|
|
params: balances_import_params |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map.merge(current_token_balances_import_params, addresses_import_params) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
|
Fetches token instance data asynchronously. |
|
|
|
Fetches token instance data asynchronously. |
|
|
|
""" |
|
|
|
""" |
|
|
|