|
|
|
@ -3,6 +3,8 @@ defmodule Indexer.TokenBalances do |
|
|
|
|
Reads Token's balances using Smart Contract functions from the blockchain. |
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
require Logger |
|
|
|
|
|
|
|
|
|
alias Explorer.Token.BalanceReader |
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@ -42,11 +44,11 @@ defmodule Indexer.TokenBalances do |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp set_token_balance_value({:ok, balance}, token_balance) do |
|
|
|
|
Map.merge(token_balance, %{value: balance, value_fetched_at: DateTime.utc_now()}) |
|
|
|
|
Map.merge(token_balance, %{value: balance, value_fetched_at: DateTime.utc_now(), error: nil}) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp set_token_balance_value({:error, _}, token_balance) do |
|
|
|
|
Map.merge(token_balance, %{value: nil, value_fetched_at: nil}) |
|
|
|
|
defp set_token_balance_value({:error, error_message}, token_balance) do |
|
|
|
|
Map.merge(token_balance, %{value: nil, value_fetched_at: nil, error: error_message}) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def format_task_results({:exit, :timeout}), do: {:error, :timeout} |
|
|
|
@ -54,4 +56,26 @@ defmodule Indexer.TokenBalances do |
|
|
|
|
|
|
|
|
|
def ignore_request_with_timeouts({:error, :timeout}), do: false |
|
|
|
|
def ignore_request_with_timeouts(_token_balance), do: true |
|
|
|
|
|
|
|
|
|
def log_fetching_errors(from, token_balances_params) do |
|
|
|
|
error_messages = |
|
|
|
|
token_balances_params |
|
|
|
|
|> Stream.filter(fn token_balance -> token_balance.error != nil end) |
|
|
|
|
|> Enum.map(fn token_balance -> |
|
|
|
|
"<address_hash: #{token_balance.token_contract_address_hash}, " <> |
|
|
|
|
"contract_address_hash: #{token_balance.address_hash}, " <> |
|
|
|
|
"block_number: #{token_balance.block_number}, " <> "error: #{token_balance.error}> \n" |
|
|
|
|
end) |
|
|
|
|
|
|
|
|
|
if Enum.any?(error_messages) do |
|
|
|
|
Logger.debug( |
|
|
|
|
[ |
|
|
|
|
"<#{from}> ", |
|
|
|
|
"Errors while fetching TokenBalances through Contract interaction: \n", |
|
|
|
|
error_messages |
|
|
|
|
], |
|
|
|
|
fetcher: :token_balances |
|
|
|
|
) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|