|
|
@ -9,6 +9,7 @@ defmodule Indexer.Fetcher.TokenTotalSupplyOnDemand do |
|
|
|
alias Explorer.{Chain, Repo} |
|
|
|
alias Explorer.{Chain, Repo} |
|
|
|
alias Explorer.Chain.{Address, Token} |
|
|
|
alias Explorer.Chain.{Address, Token} |
|
|
|
alias Explorer.Chain.Cache.BlockNumber |
|
|
|
alias Explorer.Chain.Cache.BlockNumber |
|
|
|
|
|
|
|
alias Explorer.Chain.Events.Publisher |
|
|
|
alias Explorer.Token.MetadataRetriever |
|
|
|
alias Explorer.Token.MetadataRetriever |
|
|
|
|
|
|
|
|
|
|
|
@ttl_in_blocks 1 |
|
|
|
@ttl_in_blocks 1 |
|
|
@ -33,14 +34,14 @@ defmodule Indexer.Fetcher.TokenTotalSupplyOnDemand do |
|
|
|
|
|
|
|
|
|
|
|
@impl true |
|
|
|
@impl true |
|
|
|
def handle_cast({:fetch_and_update, address}, state) do |
|
|
|
def handle_cast({:fetch_and_update, address}, state) do |
|
|
|
do_trigger_fetch(address) |
|
|
|
do_fetch(address) |
|
|
|
|
|
|
|
|
|
|
|
{:noreply, state} |
|
|
|
{:noreply, state} |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
## Implementation |
|
|
|
## Implementation |
|
|
|
|
|
|
|
|
|
|
|
defp do_trigger_fetch(address) when not is_nil(address) do |
|
|
|
defp do_fetch(address) when not is_nil(address) do |
|
|
|
token = |
|
|
|
token = |
|
|
|
Token |
|
|
|
Token |
|
|
|
|> Repo.get_by(contract_address_hash: address) |
|
|
|
|> Repo.get_by(contract_address_hash: address) |
|
|
@ -54,12 +55,10 @@ defmodule Indexer.Fetcher.TokenTotalSupplyOnDemand do |
|
|
|
token_address_hash |
|
|
|
token_address_hash |
|
|
|
|> MetadataRetriever.get_total_supply_of() |
|
|
|
|> MetadataRetriever.get_total_supply_of() |
|
|
|
|
|
|
|
|
|
|
|
token = |
|
|
|
{:ok, token} = |
|
|
|
Token |
|
|
|
Chain.update_token(token, Map.put(token_params, :total_supply_updated_at_block, BlockNumber.get_max())) |
|
|
|
|> Repo.get_by(contract_address_hash: address) |
|
|
|
|
|
|
|
|> Repo.preload([:contract_address]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{:ok, _} = Chain.update_token(token, Map.put(token_params, :total_supply_updated_at_block, BlockNumber.get_max())) |
|
|
|
Publisher.broadcast(%{token_total_supply: [token]}, :on_demand) |
|
|
|
:ok |
|
|
|
:ok |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|