fix raw trace bug

pull/4346/head
nikitosing 3 years ago
parent e3d5778018
commit beeb9aa48f
  1. 1
      CHANGELOG.md
  2. 96
      apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex

@ -12,6 +12,7 @@
- [#4067](https://github.com/blockscout/blockscout/pull/4067) - Display LP tokens USD value and custom metadata in tokens dropdown at address page - [#4067](https://github.com/blockscout/blockscout/pull/4067) - Display LP tokens USD value and custom metadata in tokens dropdown at address page
### Fixes ### Fixes
- [#4346](https://github.com/blockscout/blockscout/pull/4346) - Fix internal server error on raw-trace transaction page
- [#4345](https://github.com/blockscout/blockscout/pull/4345) - Fix bug on validator's address transactions page - [#4345](https://github.com/blockscout/blockscout/pull/4345) - Fix bug on validator's address transactions page
- [#4342](https://github.com/blockscout/blockscout/pull/4342) - Remove dropped/replaced txs from address transactions page - [#4342](https://github.com/blockscout/blockscout/pull/4342) - Remove dropped/replaced txs from address transactions page
- [#4320](https://github.com/blockscout/blockscout/pull/4320) - Fix absence of imported smart-contracts' source code in `getsourcecode` api method - [#4320](https://github.com/blockscout/blockscout/pull/4320) - Fix absence of imported smart-contracts' source code in `getsourcecode` api method

@ -24,59 +24,55 @@ defmodule BlockScoutWeb.TransactionRawTraceController do
), ),
{:ok, false} <- AccessHelpers.restricted_access?(to_string(transaction.from_address_hash), params), {:ok, false} <- AccessHelpers.restricted_access?(to_string(transaction.from_address_hash), params),
{:ok, false} <- AccessHelpers.restricted_access?(to_string(transaction.to_address_hash), params) do {:ok, false} <- AccessHelpers.restricted_access?(to_string(transaction.to_address_hash), params) do
internal_transactions = Chain.all_transaction_to_internal_transactions(hash) if is_nil(transaction.block_number) do
render_raw_trace(conn, [], transaction, hash)
else
internal_transactions = Chain.all_transaction_to_internal_transactions(hash)
first_trace_exists = first_trace_exists =
Enum.find_index(internal_transactions, fn trace -> Enum.find_index(internal_transactions, fn trace ->
trace.index == 0 trace.index == 0
end) end)
json_rpc_named_arguments = Application.get_env(:explorer, :json_rpc_named_arguments) json_rpc_named_arguments = Application.get_env(:explorer, :json_rpc_named_arguments)
internal_transactions = internal_transactions =
if first_trace_exists do if first_trace_exists do
internal_transactions internal_transactions
else else
response = response =
Chain.fetch_first_trace( Chain.fetch_first_trace(
[ [
%{ %{
block_hash: transaction.block_hash, block_hash: transaction.block_hash,
block_number: transaction.block_number, block_number: transaction.block_number,
hash_data: hash_string, hash_data: hash_string,
transaction_index: transaction.index transaction_index: transaction.index
} }
], ],
json_rpc_named_arguments json_rpc_named_arguments
) )
case response do case response do
{:ok, first_trace_params} -> {:ok, first_trace_params} ->
InternalTransactions.run_insert_only(first_trace_params, %{ InternalTransactions.run_insert_only(first_trace_params, %{
timeout: :infinity, timeout: :infinity,
timestamps: Import.timestamps(), timestamps: Import.timestamps(),
internal_transactions: %{params: first_trace_params} internal_transactions: %{params: first_trace_params}
}) })
Chain.all_transaction_to_internal_transactions(hash) Chain.all_transaction_to_internal_transactions(hash)
{:error, _} -> {:error, _} ->
internal_transactions internal_transactions
:ignore -> :ignore ->
internal_transactions internal_transactions
end
end end
end
render( render_raw_trace(conn, internal_transactions, transaction, hash)
conn, end
"index.html",
exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(),
internal_transactions: internal_transactions,
block_height: Chain.block_height(),
show_token_transfers: Chain.transaction_has_token_transfers?(hash),
transaction: transaction
)
else else
{:restricted_access, _} -> {:restricted_access, _} ->
TransactionController.set_not_found_view(conn, hash_string) TransactionController.set_not_found_view(conn, hash_string)
@ -88,4 +84,16 @@ defmodule BlockScoutWeb.TransactionRawTraceController do
TransactionController.set_not_found_view(conn, hash_string) TransactionController.set_not_found_view(conn, hash_string)
end end
end end
defp render_raw_trace(conn, internal_transactions, transaction, hash) do
render(
conn,
"index.html",
exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(),
internal_transactions: internal_transactions,
block_height: Chain.block_height(),
show_token_transfers: Chain.transaction_has_token_transfers?(hash),
transaction: transaction
)
end
end end

Loading…
Cancel
Save