diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_log_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_log_controller.ex index 8b4e3877e0..2735d265f1 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_log_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_log_controller.ex @@ -4,10 +4,12 @@ defmodule BlockScoutWeb.TransactionLogController do import BlockScoutWeb.Chain, only: [paging_options: 1, next_page_params: 3, split_list_by_page: 1] alias BlockScoutWeb.TransactionView + alias BlockScoutWeb.TransactionLogView alias Explorer.{Chain, Market} alias Explorer.ExchangeRates.Token + alias Phoenix.View - def index(conn, %{"transaction_id" => transaction_hash_string} = params) do + def index(conn, %{"transaction_id" => transaction_hash_string, "type" => "JSON"} = params) do with {:ok, transaction_hash} <- Chain.string_to_transaction_hash(transaction_hash_string), {:ok, transaction} <- Chain.hash_to_transaction( @@ -35,13 +37,69 @@ defmodule BlockScoutWeb.TransactionLogController do {logs, next_page} = split_list_by_page(logs_plus_one) + next_page_url = + case next_page_params(next_page, logs, params) do + nil -> + nil + + next_page_params -> + transaction_log_path(conn, :index, transaction, Map.delete(next_page_params, "type")) + end + + items = + logs + |> Enum.map(fn log -> + View.render_to_string( + TransactionLogView, + "_logs.html", + log: log, + conn: conn, + transaction: transaction + ) + end) + + json( + conn, + %{ + items: items, + next_page_path: next_page_url + } + ) + else + :error -> + conn + |> put_status(422) + |> put_view(TransactionView) + |> render("invalid.html", transaction_hash: transaction_hash_string) + + {:error, :not_found} -> + conn + |> put_status(404) + |> put_view(TransactionView) + |> render("not_found.html", transaction_hash: transaction_hash_string) + end + end + + def index(conn, %{"transaction_id" => transaction_hash_string}) do + with {:ok, transaction_hash} <- Chain.string_to_transaction_hash(transaction_hash_string), + {:ok, transaction} <- + Chain.hash_to_transaction( + transaction_hash, + necessity_by_association: %{ + :block => :optional, + [created_contract_address: :names] => :optional, + [from_address: :names] => :required, + [to_address: :names] => :optional, + [to_address: :smart_contract] => :optional, + :token_transfers => :optional + } + ) do render( conn, "index.html", - logs: logs, block_height: Chain.block_height(), show_token_transfers: Chain.transaction_has_token_transfers?(transaction_hash), - next_page_params: next_page_params(next_page, logs, params), + current_path: current_path(conn), transaction: transaction, exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null() ) diff --git a/apps/block_scout_web/lib/block_scout_web/templates/transaction_log/_logs.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/transaction_log/_logs.html.eex new file mode 100644 index 0000000000..5a52821601 --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/templates/transaction_log/_logs.html.eex @@ -0,0 +1,123 @@ +
+
+
<%= gettext "Address" %>
+
+

+ <%= link( + @log.address, + to: address_path(@conn, :show, @log.address), + "data-test": "log_address_link", + "data-address-hash": @log.address + ) %> +

+
+
<%= gettext "Decoded" %>
+
+ <%= case decode(@log, @transaction) do %> + <% {:error, :contract_not_verified} -> %> +
+ <%= gettext "To see decoded input data, the contract must be verified." %> + <%= case @transaction do %> + <% %{to_address: %{hash: hash}} -> %> + <%= gettext "Verify the contract " %><%= gettext "here" %> + <% _ -> %> + <%= nil %> + <% end %> +
+ <% {:error, :could_not_decode} -> %> +
+ <%= gettext "Failed to decode log data." %> +
+ <% {:ok, method_id, text, mapping} -> %> + + + + + + + + + +
Method Id0x<%= method_id %>
Call<%= text %>
+ " class="table thead-light table-bordered table-responsive"> + + + + + + + + <%= for {name, type, indexed?, value} <- mapping do %> + + + + + + + + <% end %> +
<%= gettext "Name" %><%= gettext "Type" %><%= gettext "Indexed?" %><%= gettext "Data" %>
+ <%= case BlockScoutWeb.ABIEncodedValueView.copy_text(type, value) do %> + <% :error -> %> + <%= nil %> + <% copy_text -> %> + + + + + + <% end %> + <%= name %><%= type %><%= indexed? %> +
<%= BlockScoutWeb.ABIEncodedValueView.value_html(type, value) %>
+
+ <% _ -> %> + <%= nil %> + <% end %> + +
<%= gettext "Topics" %>
+
+
+ <%= unless is_nil(@log.first_topic) do %> +
+ [0] + <%= @log.first_topic %> +
+ <% end %> + <%= unless is_nil(@log.second_topic) do %> +
+ [1] + <%= @log.second_topic %> +
+ <% end %> + <%= unless is_nil(@log.third_topic) do %> +
+ [2] + <%= @log.third_topic %> +
+ <% end %> + <%= unless is_nil(@log.fourth_topic) do %> +
+ [3] + <%= @log.fourth_topic %> +
+ <% end %> +
+
+
+ <%= gettext "Data" %> +
+
+ <%= unless is_nil(@log.data) do %> +
+ <%= @log.data %> +
+ <% end %> +
+
+
diff --git a/apps/block_scout_web/lib/block_scout_web/templates/transaction_log/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/transaction_log/index.html.eex index b0e8260d4e..3c84e7c4f9 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/transaction_log/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/transaction_log/index.html.eex @@ -4,172 +4,25 @@
<%= render BlockScoutWeb.TransactionView, "_tabs.html", assigns %> -
+

<%= gettext "Logs" %>

- <%= if @next_page_params do %> - <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", cur_page_number: "1", show_pagination_limit: true, next_page_path: transaction_log_path(@conn,:index, @transaction, @next_page_params) %> - <% end %> + <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> - <%= if !@next_page_params do %> - <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", cur_page_number: "1", show_pagination_limit: true %> - <% end %> + - <%= if Enum.count(@logs) > 0 do %> - <%= for log <- @logs do %> -
-
-
<%= gettext "Address" %>
-
-

- <%= link( - log.address, - to: address_path(@conn, :show, log.address), - "data-test": "log_address_link", - "data-address-hash": log.address - ) %> -

-
-
<%= gettext "Decoded" %>
-
- <%= case decode(log, @transaction) do %> - <% {:error, :contract_not_verified} -> %> -
- <%= gettext "To see decoded input data, the contract must be verified." %> - <%= case @transaction do %> - <% %{to_address: %{hash: hash}} -> %> - <%= gettext "Verify the contract " %><%= gettext "here" %> - <% _ -> %> - <%= nil %> - <% end %> -
- <% {:error, :could_not_decode} -> %> -
- <%= gettext "Failed to decode log data." %> -
- <% {:ok, method_id, text, mapping} -> %> - - - - - - - - - -
Method Id0x<%= method_id %>
Call<%= text %>
- " class="table thead-light table-bordered table-responsive"> - - - - - - - - <%= for {name, type, indexed?, value} <- mapping do %> - - - - - - - - <% end %> -
<%= gettext "Name" %><%= gettext "Type" %><%= gettext "Indexed?" %><%= gettext "Data" %>
- <%= case BlockScoutWeb.ABIEncodedValueView.copy_text(type, value) do %> - <% :error -> %> - <%= nil %> - <% copy_text -> %> - - - - - - <% end %> - <%= name %><%= type %><%= indexed? %> -
<%= BlockScoutWeb.ABIEncodedValueView.value_html(type, value) %>
-
- <% _ -> %> - <%= nil %> - <% end %> - -
-
<%= gettext "Topics" %>
-
-
- <%= unless is_nil(log.first_topic) do %> -
- [0] - <%= log.first_topic %> -
- <% end %> - <%= unless is_nil(log.second_topic) do %> -
- [1] - <%= log.second_topic %> -
- <% end %> - <%= unless is_nil(log.third_topic) do %> -
- [2] - <%= log.third_topic %> -
- <% end %> - <%= unless is_nil(log.fourth_topic) do %> -
- [3] - <%= log.fourth_topic %> -
- <% end %> -
-
-
- <%= gettext "Data" %> -
-
- <%= unless is_nil(log.data) do %> -
- <%= log.data %> -
- <% end %> -
-
+
+
+ <%= gettext "There are no logs for this transaction." %>
- <% end %> - <% else %> -
- <%= gettext "There are no logs for this transaction." %> -
- <% end %> +
- <%= if @next_page_params do %> - <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "bottom", cur_page_number: "1", show_pagination_limit: true, next_page_path: transaction_log_path(@conn,:index, @transaction, @next_page_params) %> - <% end %> +
- <%= if !@next_page_params do %> - <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "bottom", cur_page_number: "1", show_pagination_limit: true %> - <% end %> + <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "bottom", cur_page_number: "1", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> -