Merge pull request #8770 from blockscout/vb-eth-getbalance-api-latest-tag-fix

Fix for eth_getbalance API v1 endpoint when requesting latest tag
all-in-one-docker-image
Victor Baranov 1 year ago committed by GitHub
commit 3a914f0063
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 4
      apps/block_scout_web/test/block_scout_web/controllers/api/rpc/eth_controller_test.exs
  3. 16
      apps/explorer/lib/explorer/etherscan/blocks.ex

@ -9,6 +9,7 @@
### Fixes
- [#8784](https://github.com/blockscout/blockscout/pull/8784) - Fix Indexer.Transform.Addresses for non-Suave setup
- [#8770](https://github.com/blockscout/blockscout/pull/8770) - Fix for eth_getbalance API v1 endpoint when requesting latest tag
- [#8765](https://github.com/blockscout/blockscout/pull/8765) - Fix for tvl update in market history when row already exists
- [#8759](https://github.com/blockscout/blockscout/pull/8759) - Gnosis safe proxy via singleton input
- [#8752](https://github.com/blockscout/blockscout/pull/8752) - Add `TOKEN_INSTANCE_OWNER_MIGRATION_ENABLED` env

@ -400,9 +400,7 @@ defmodule BlockScoutWeb.API.RPC.EthControllerTest do
test "with a valid address that has a balance", %{conn: conn, api_params: api_params} do
block = insert(:block)
address = insert(:address)
insert(:fetched_balance, block_number: block.number, address_hash: address.hash, value: 1)
address = insert(:address, fetched_coin_balance: 1, fetched_coin_balance_block_number: block.number)
assert response =
conn

@ -11,7 +11,7 @@ defmodule Explorer.Etherscan.Blocks do
]
alias Explorer.{Chain, Repo}
alias Explorer.Chain.{Address.CoinBalance, Block, Hash, Wei}
alias Explorer.Chain.{Address, Address.CoinBalance, Block, Hash, Wei}
@doc """
Returns the balance of the given address and block combination.
@ -39,12 +39,16 @@ defmodule Explorer.Etherscan.Blocks do
end
def get_balance_as_of_block(address, :latest) do
case Chain.max_consensus_block_number() do
{:ok, latest_block_number} ->
get_balance_as_of_block(address, latest_block_number)
latest_coin_balance_query =
from(
a in Address,
select: a.fetched_coin_balance,
where: a.hash == ^address
)
{:error, :not_found} ->
{:error, :not_found}
case Repo.replica().one(latest_coin_balance_query) do
nil -> {:error, :not_found}
coin_balance -> {:ok, coin_balance}
end
end

Loading…
Cancel
Save