Skip to content

Commit

Permalink
Fix txlist RPC endpoint to use the token info for fee currencies (#1047)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
carterqw2 authored May 8, 2024
1 parent 7cee218 commit 0d33ce2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 3 additions & 6 deletions apps/explorer/lib/explorer/celo/util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions apps/explorer/lib/explorer/etherscan.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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, Hash, InternalTransaction, Log, Token, TokenTransfer, Transaction}
alias Explorer.Chain.Transaction.History.TransactionStats

@default_options %{
Expand Down Expand Up @@ -490,16 +490,16 @@ 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}],
limit: ^options.page_size,
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)
})
Expand Down

0 comments on commit 0d33ce2

Please sign in to comment.