From f8a149640fcf5cd409f76f369661926b52cff810 Mon Sep 17 00:00:00 2001 From: Valentin Rodygin Date: Wed, 8 May 2024 13:16:51 +0200 Subject: [PATCH 1/3] Fix txlist RPC endpoint to use the token info for fee currencies The txlist RPC endpoint uses the CeloParams table to fetch names of stable tokens used as gas currencies. It can take it from the Tokens table instead. --- apps/explorer/lib/explorer/etherscan.ex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/explorer/lib/explorer/etherscan.ex b/apps/explorer/lib/explorer/etherscan.ex index b64aeae0e312..e4248c038de3 100644 --- a/apps/explorer/lib/explorer/etherscan.ex +++ b/apps/explorer/lib/explorer/etherscan.ex @@ -8,7 +8,7 @@ defmodule Explorer.Etherscan do alias Explorer.Etherscan.Logs alias Explorer.{Chain, Repo} alias Explorer.Chain.Address.{CurrentTokenBalance, TokenBalance} - alias Explorer.Chain.{Address, Block, CeloParams, Hash, InternalTransaction, Log, TokenTransfer, Transaction} + alias Explorer.Chain.{Address, Block, CeloParams, Hash, InternalTransaction, Log, Token, TokenTransfer, Transaction} alias Explorer.Chain.Transaction.History.TransactionStats @default_options %{ @@ -490,8 +490,8 @@ defmodule Explorer.Etherscan do t in Transaction, join: a in ^addresses_wrapped_subquery, on: t.hash == a.hash, - left_join: p in CeloParams, - on: t.gas_currency_hash == p.address_value, + left_join: k in Token, + on: t.gas_currency_hash == k.contract_address_hash, inner_join: b in Block, on: b.number == t.block_number, order_by: [{^options.order_by_direction, t.block_number}], @@ -499,7 +499,7 @@ defmodule Explorer.Etherscan do offset: ^offset(options), select: merge(map(t, ^@transaction_fields), %{ - fee_currency: p.name, + fee_currency: k.symbol, block_timestamp: b.timestamp, confirmations: fragment("? - ?", ^max_block_number, t.block_number) }) From e898424e869f09bcd5d53c2c63dfd4d6f13777fe Mon Sep 17 00:00:00 2001 From: Valentin Rodygin Date: Wed, 8 May 2024 15:03:35 +0200 Subject: [PATCH 2/3] Removed unused import --- apps/explorer/lib/explorer/etherscan.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/explorer/lib/explorer/etherscan.ex b/apps/explorer/lib/explorer/etherscan.ex index e4248c038de3..3c46281fe54d 100644 --- a/apps/explorer/lib/explorer/etherscan.ex +++ b/apps/explorer/lib/explorer/etherscan.ex @@ -8,7 +8,7 @@ defmodule Explorer.Etherscan do alias Explorer.Etherscan.Logs alias Explorer.{Chain, Repo} alias Explorer.Chain.Address.{CurrentTokenBalance, TokenBalance} - alias Explorer.Chain.{Address, Block, CeloParams, Hash, InternalTransaction, Log, Token, TokenTransfer, Transaction} + alias Explorer.Chain.{Address, Block, Hash, InternalTransaction, Log, Token, TokenTransfer, Transaction} alias Explorer.Chain.Transaction.History.TransactionStats @default_options %{ From d61d04ff2e28d8c451736e1931b6271b8d27c4f9 Mon Sep 17 00:00:00 2001 From: Valentin Rodygin Date: Wed, 8 May 2024 15:34:44 +0200 Subject: [PATCH 3/3] Fixed symbol formatting --- .../lib/block_scout_web/views/api/rpc/address_view.ex | 2 +- apps/explorer/lib/explorer/celo/util.ex | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/views/api/rpc/address_view.ex b/apps/block_scout_web/lib/block_scout_web/views/api/rpc/address_view.ex index 8fa9a76d506d..75fc0a670806 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/api/rpc/address_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/api/rpc/address_view.ex @@ -129,7 +129,7 @@ defmodule BlockScoutWeb.API.RPC.AddressView do "confirmations" => "#{transaction.confirmations}", "gatewayFeeRecipient" => "#{transaction.gas_fee_recipient_hash}", "gatewayFee" => "#{transaction.gateway_fee}", - "feeCurrency" => Util.contract_name_to_symbol(transaction.fee_currency, true) + "feeCurrency" => Util.fee_currency_token_symbol(transaction.fee_currency) } end diff --git a/apps/explorer/lib/explorer/celo/util.ex b/apps/explorer/lib/explorer/celo/util.ex index 6dd221aa5efe..ea7721968166 100644 --- a/apps/explorer/lib/explorer/celo/util.ex +++ b/apps/explorer/lib/explorer/celo/util.ex @@ -79,13 +79,10 @@ defmodule Explorer.Celo.Util do Map.values(@celo_token_contract_symbols) end - def contract_name_to_symbol(name, use_celo_instead_cgld?) do + def fee_currency_token_symbol(name) do case name do - n when n in [nil, "goldToken"] -> - if(use_celo_instead_cgld?, do: "CELO", else: "cGLD") - - _ -> - @celo_token_contract_symbols[name] + n when n in [nil, "cGLD"] -> "CELO" + _ -> name end end end