From 0a362ee98182d93eee91157d187bd2deddc755de Mon Sep 17 00:00:00 2001 From: Donald Hutchison Date: Tue, 6 Feb 2024 17:45:52 +0100 Subject: [PATCH] Queue unknown gas currency for token indexing. --- .../lib/block_scout_web/views/transaction_view.ex | 11 +++++++++-- apps/explorer/lib/explorer/chain/token.ex | 8 ++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex b/apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex index 24d9d387a10c..955f7e097420 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex @@ -1,6 +1,8 @@ defmodule BlockScoutWeb.TransactionView do use BlockScoutWeb, :view + require Logger + alias BlockScoutWeb.{AccessHelpers, AddressView, BlockView, TabHelpers} alias BlockScoutWeb.Account.AuthController alias BlockScoutWeb.Cldr.Number @@ -8,6 +10,7 @@ defmodule BlockScoutWeb.TransactionView do alias Explorer.{Chain, CustomContractsHelpers, Repo} alias Explorer.Chain.Block.Reward alias Explorer.Chain.{Address, Block, InternalTransaction, Transaction, Wei} + alias Explorer.Chain.Token, as: ChainToken alias Explorer.Counters.AverageBlockTime alias Explorer.ExchangeRates.Token alias Timex.Duration @@ -498,12 +501,16 @@ defmodule BlockScoutWeb.TransactionView do format_wei_value(Wei.from(fee, :wei), denomination, include_unit_label: include_label?, currency: currency)} end - def get_fee_token_name(transaction) do + def get_fee_token_name(transaction = %{gas_currency_hash: gch}) do token = Transaction.get_fee_token_name(transaction) case token do {:ok, address} -> address - {:error, :not_found} -> %{name: "", symbol: "#{gettext("CELO")}"} + {:error, :not_found} -> + Logger.info("Found unknown gas token at #{inspect(gch)}") + ChainToken.set_uncatalogued_token(transaction) + + %{name: "", symbol: "#{gettext("CELO")}"} end end diff --git a/apps/explorer/lib/explorer/chain/token.ex b/apps/explorer/lib/explorer/chain/token.ex index 87f538199d1f..dbcbbbf557a8 100644 --- a/apps/explorer/lib/explorer/chain/token.ex +++ b/apps/explorer/lib/explorer/chain/token.ex @@ -24,6 +24,7 @@ defmodule Explorer.Chain.Token do alias Ecto.Changeset alias Explorer.Chain.{Address, Hash, Token} + alias Explorer.Repo alias Explorer.SmartContract.Helper @typedoc """ @@ -140,4 +141,11 @@ defmodule Explorer.Chain.Token do where: token.cataloged == true and token.updated_at <= ^some_time_ago_date ) end + + def set_uncatalogued_token(%{gas_currency_hash: nil}), do: :ok + def set_uncatalogued_token(%{gas_currency_hash: address}) do + %Token{} + |> changeset(%{contract_address_hash: address, type: "ERC-20"}) + |> Repo.insert() + end end