From 984f499910b57569e90e11809cc6dca29915cf57 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Wed, 30 Sep 2020 14:22:05 +0300 Subject: [PATCH] Fix logs api response --- CHANGELOG.md | 1 + .../lib/block_scout_web/notifier.ex | 9 ++++++++- .../lib/block_scout_web/views/api/rpc/logs_view.ex | 2 +- .../controllers/api/rpc/logs_controller_test.exs | 2 +- apps/explorer/lib/explorer/chain.ex | 9 ++------- apps/explorer/lib/explorer/etherscan/logs.ex | 14 +++++++++----- 6 files changed, 22 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed9f621ce7..fa2488d27a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - [#3261](https://github.com/poanetwork/blockscout/pull/3261) - Bridged tokens table ### Fixes +- [#3323](https://github.com/poanetwork/blockscout/pull/3323) - Fix logs list API endpoint response - [#3319](https://github.com/poanetwork/blockscout/pull/3319) - Eliminate horizontal scroll - [#3314](https://github.com/poanetwork/blockscout/pull/3314) - Handle nil values from response of CoinGecko price API - [#3313](https://github.com/poanetwork/blockscout/pull/3313) - Fix xDai styles: invisible tokens on address diff --git a/apps/block_scout_web/lib/block_scout_web/notifier.ex b/apps/block_scout_web/lib/block_scout_web/notifier.ex index 6f2fbcd144..2ce1d5f2e3 100644 --- a/apps/block_scout_web/lib/block_scout_web/notifier.ex +++ b/apps/block_scout_web/lib/block_scout_web/notifier.ex @@ -36,7 +36,14 @@ defmodule BlockScoutWeb.Notifier do result {:error, changeset} -> - {:ok, compiler_versions} = CompilerVersion.fetch_versions() + compiler_versions = + case CompilerVersion.fetch_versions() do + {:ok, compiler_versions} -> + compiler_versions + + {:error, _} -> + [] + end result = View.render_to_string(AddressContractVerificationView, "new.html", diff --git a/apps/block_scout_web/lib/block_scout_web/views/api/rpc/logs_view.ex b/apps/block_scout_web/lib/block_scout_web/views/api/rpc/logs_view.ex index 803ea6706a..6f2933d7c6 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/api/rpc/logs_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/api/rpc/logs_view.ex @@ -36,7 +36,7 @@ defmodule BlockScoutWeb.API.RPC.LogsView do [first_topic, second_topic, third_topic, fourth_topic] end - defp integer_to_hex(integer), do: Integer.to_string(integer, 16) + defp integer_to_hex(integer), do: "0x" <> String.downcase(Integer.to_string(integer, 16)) defp decimal_to_hex(decimal) do decimal diff --git a/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/logs_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/logs_controller_test.exs index 0b129939b8..ec4337eecd 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/logs_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/logs_controller_test.exs @@ -776,7 +776,7 @@ defmodule BlockScoutWeb.API.RPC.LogsControllerTest do [first_topic, second_topic, third_topic, fourth_topic] end - defp integer_to_hex(integer), do: Integer.to_string(integer, 16) + defp integer_to_hex(integer), do: "0x" <> String.downcase(Integer.to_string(integer, 16)) defp decimal_to_hex(decimal) do decimal diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 5e8de20254..98f68ea32a 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -237,13 +237,8 @@ defmodule Explorer.Chain do |> union(^query_from_address_hash_wrapped) |> union(^query_created_contract_address_hash_wrapped) - full_wrapped_query = - from( - q in subquery(full_query), - select: q - ) - - full_wrapped_query + full_query + |> wrapped_union_subquery() |> order_by( [q], desc: q.block_number, diff --git a/apps/explorer/lib/explorer/etherscan/logs.ex b/apps/explorer/lib/explorer/etherscan/logs.ex index 35dbfda1ba..c19a3c7d4f 100644 --- a/apps/explorer/lib/explorer/etherscan/logs.ex +++ b/apps/explorer/lib/explorer/etherscan/logs.ex @@ -109,9 +109,11 @@ defmodule Explorer.Etherscan.Logs do transaction.from_address_hash == ^address_hash or transaction.created_contract_address_hash == ^address_hash, select: map(log, ^@log_fields), - select_merge: map(transaction, [:gas_price, :gas_used, :block_number]), select_merge: %{ - transaction_index: transaction.index + gas_price: transaction.gas_price, + gas_used: transaction.gas_used, + transaction_index: transaction.index, + block_number: transaction.block_number }, union: ^internal_transaction_log_query ) @@ -124,9 +126,11 @@ defmodule Explorer.Etherscan.Logs do order_by: block.number, limit: 1000, select_merge: %{ + transaction_index: log_transaction_data.transaction_index, + block_hash: block.hash, + block_number: block.number, block_timestamp: block.timestamp, - block_consensus: block.consensus, - block_hash: block.hash + block_consensus: block.consensus } ) @@ -270,7 +274,7 @@ defmodule Explorer.Etherscan.Logs do gas_price: transaction.gas_price, gas_used: transaction.gas_used, transaction_index: transaction.index, - block_number: transaction.block_number + block_number: internal_transaction.block_number }) )