Merge pull request #7546 from blockscout/vb-fix-today-con-price-api-v2

API v2: fix today coin price (use in-memory or cached in DB value)
pull/7547/head
Victor Baranov 2 years ago committed by GitHub
commit 1a83c82f81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      CHANGELOG.md
  2. 2
      apps/block_scout_web/lib/block_scout_web/controllers/api/v2/stats_controller.ex
  3. 18
      apps/explorer/lib/explorer/market/market.ex

@ -8,7 +8,8 @@
### Fixes ### Fixes
- [#7545](https://github.com/blockscout/blockscout/pull/7545) - Check if cached exchange rate is empty before replacing DB value in stats API - [](https://github.com/blockscout/blockscout/pull/7546) - API v2: fix today coin price (use in-memory or cached in DB value)
- [#7545](https://github.com/blockscout/blockscout/pull/7545) - API v2: Check if cached exchange rate is empty before replacing DB value in stats API
- [#7516](https://github.com/blockscout/blockscout/pull/7516) - Fix shrinking logo in Safari - [#7516](https://github.com/blockscout/blockscout/pull/7516) - Fix shrinking logo in Safari
### Chore ### Chore

@ -46,7 +46,7 @@ defmodule BlockScoutWeb.API.V2.StatsController do
"total_addresses" => @api_true |> Chain.address_estimated_count() |> to_string(), "total_addresses" => @api_true |> Chain.address_estimated_count() |> to_string(),
"total_transactions" => TransactionCache.estimated_count() |> to_string(), "total_transactions" => TransactionCache.estimated_count() |> to_string(),
"average_block_time" => AverageBlockTime.average_block_time() |> Duration.to_milliseconds(), "average_block_time" => AverageBlockTime.average_block_time() |> Duration.to_milliseconds(),
"coin_price" => exchange_rate.usd_value, "coin_price" => exchange_rate.usd_value || Market.get_native_coin_exchange_rate_from_db(),
"total_gas_used" => GasUsage.total() |> to_string(), "total_gas_used" => GasUsage.total() |> to_string(),
"transactions_today" => Enum.at(transaction_stats, 0).number_of_transactions |> to_string(), "transactions_today" => Enum.at(transaction_stats, 0).number_of_transactions |> to_string(),
"gas_used_today" => Enum.at(transaction_stats, 0).gas_used, "gas_used_today" => Enum.at(transaction_stats, 0).gas_used,

@ -25,6 +25,24 @@ defmodule Explorer.Market do
MarketHistoryCache.fetch() MarketHistoryCache.fetch()
end end
@doc """
Retrieves today's native coin exchange rate from the database.
"""
@spec get_native_coin_exchange_rate_from_db() :: Token.t() | nil
def get_native_coin_exchange_rate_from_db do
today =
case fetch_recent_history() do
[today | _the_rest] -> today
_ -> nil
end
if today do
Map.get(today, :closing_price)
else
nil
end
end
@doc false @doc false
def bulk_insert_history(records) do def bulk_insert_history(records) do
records_without_zeroes = records_without_zeroes =

Loading…
Cancel
Save