diff --git a/apps/explorer_web/lib/explorer_web/controllers/internal_transaction_controller.ex b/apps/explorer_web/lib/explorer_web/controllers/internal_transaction_controller.ex deleted file mode 100644 index 439b6fc348..0000000000 --- a/apps/explorer_web/lib/explorer_web/controllers/internal_transaction_controller.ex +++ /dev/null @@ -1,17 +0,0 @@ -defmodule ExplorerWeb.InternalTransactionController do - use ExplorerWeb, :controller - - alias Explorer.Transaction.Service, as: Transaction - - def index(conn, %{"transaction_id" => transaction_id}) do - hash = String.downcase(transaction_id) - - internal_transactions = Transaction.internal_transactions(hash) - - render( - conn, - internal_transactions: internal_transactions, - transaction_hash: hash - ) - end -end diff --git a/apps/explorer_web/lib/explorer_web/controllers/transaction_controller.ex b/apps/explorer_web/lib/explorer_web/controllers/transaction_controller.ex index 5839678720..d3774e0f21 100644 --- a/apps/explorer_web/lib/explorer_web/controllers/transaction_controller.ex +++ b/apps/explorer_web/lib/explorer_web/controllers/transaction_controller.ex @@ -3,9 +3,11 @@ defmodule ExplorerWeb.TransactionController do import Ecto.Query + alias Explorer.Log alias Explorer.Repo.NewRelic, as: Repo alias Explorer.Transaction alias Explorer.TransactionForm + alias Explorer.Transaction.Service alias Explorer.Transaction.Service.Query def index(conn, %{"last_seen" => last_seen}) do @@ -64,13 +66,19 @@ defmodule ExplorerWeb.TransactionController do def show(conn, params) do transaction = Transaction - |> Query.by_hash(params["id"]) + |> Query.by_hash(String.downcase(params["id"])) |> Query.include_addresses() |> Query.include_receipt() |> Query.include_block() |> Repo.one() |> TransactionForm.build_and_merge() - render(conn, "show.html", transaction: transaction) + internal_transactions = Service.internal_transactions(transaction.hash) + + render( + conn, + internal_transactions: internal_transactions, + transaction: transaction + ) end end diff --git a/apps/explorer_web/lib/explorer_web/controllers/transaction_log_controller.ex b/apps/explorer_web/lib/explorer_web/controllers/transaction_log_controller.ex index 9e4900fd69..96273c913d 100644 --- a/apps/explorer_web/lib/explorer_web/controllers/transaction_log_controller.ex +++ b/apps/explorer_web/lib/explorer_web/controllers/transaction_log_controller.ex @@ -5,18 +5,36 @@ defmodule ExplorerWeb.TransactionLogController do alias Explorer.Log alias Explorer.Repo.NewRelic, as: Repo + alias Explorer.Transaction + alias Explorer.TransactionForm + alias Explorer.Transaction.Service + alias Explorer.Transaction.Service.Query def index(conn, %{"transaction_id" => transaction_id}) do - hash = String.downcase(transaction_id) + transaction_hash = String.downcase(transaction_id) + + transaction = + Transaction + |> Query.by_hash(transaction_hash) + |> Query.include_addresses() + |> Query.include_receipt() + |> Query.include_block() + |> Repo.one() + |> TransactionForm.build_and_merge() logs = from( log in Log, join: transaction in assoc(log, :transaction), preload: [:address], - where: fragment("lower(?)", transaction.hash) == ^hash + where: fragment("lower(?)", transaction.hash) == ^transaction_hash ) - render(conn, "index.html", logs: Repo.paginate(logs), transaction_hash: hash) + render( + conn, + "index.html", + logs: Repo.paginate(logs), + transaction: transaction + ) end end diff --git a/apps/explorer_web/lib/explorer_web/router.ex b/apps/explorer_web/lib/explorer_web/router.ex index d8736955f2..42cd8a3b4c 100644 --- a/apps/explorer_web/lib/explorer_web/router.ex +++ b/apps/explorer_web/lib/explorer_web/router.ex @@ -74,7 +74,6 @@ defmodule ExplorerWeb.Router do resources "/transactions", TransactionController, only: [:index, :show] do resources("/logs", TransactionLogController, only: [:index], as: :log) - resources("/internal", InternalTransactionController, only: [:index]) end resources "/addresses", AddressController, only: [:show] do diff --git a/apps/explorer_web/lib/explorer_web/templates/internal_transaction/index.html.eex b/apps/explorer_web/lib/explorer_web/templates/internal_transaction/index.html.eex deleted file mode 100644 index 9c26f0b9e0..0000000000 --- a/apps/explorer_web/lib/explorer_web/templates/internal_transaction/index.html.eex +++ /dev/null @@ -1,43 +0,0 @@ -
-
-

<%= gettext "Internal Transactions" %>

-

<%= @transaction_hash %>

-
-
-
-

<%= link(gettext("Overview"), to: transaction_path(@conn, :show, @conn.assigns.locale, @transaction_hash), class: "transaction__link") %>

-

<%= link(gettext("Internal Transactions"), to: transaction_internal_transaction_path(@conn, :index, @conn.assigns.locale, @transaction_hash), class: "transaction__link transaction__link--active") %>

-

<%= link(gettext("Logs"), to: transaction_log_path(@conn, :index, @conn.assigns.locale, @transaction_hash), class: "transaction__link") %>

-
-
- - - - - - - - - <%= for transaction <- @internal_transactions do %> - - - - - - - - - - <% end %> -
<%= gettext "Type" %><%= gettext "From" %><%= gettext "To" %><%= gettext "Value" %><%= gettext "Gas Limit" %>
<%= transaction.call_type %> - <%= link(transaction.to_address.hash, - to: address_path(@conn, :show, @conn.assigns.locale, transaction.to_address.hash), - class: "transaction-log__link") %> - - <%= link(transaction.from_address.hash, - to: address_path(@conn, :show, @conn.assigns.locale, transaction.from_address.hash), - class: "transaction-log__link") %> - <%= transaction.value %><%= ExplorerWeb.TransactionView.format_gas_limit(transaction.gas) %>
-
-
-
diff --git a/apps/explorer_web/lib/explorer_web/templates/transaction/overview.html.eex b/apps/explorer_web/lib/explorer_web/templates/transaction/overview.html.eex new file mode 100644 index 0000000000..89ff3d77d0 --- /dev/null +++ b/apps/explorer_web/lib/explorer_web/templates/transaction/overview.html.eex @@ -0,0 +1,96 @@ +
+

<%= gettext "Transaction Details" %>

+

<%= @transaction.hash %>

+
+
+
+
+
+
+
<%= gettext "Transaction Hash" %>
+
<%= @transaction.hash %>
+
+
+
<%= gettext "Transaction Status" %>
+
+
+ <%= @transaction.formatted_status %> +
+
+
+
+
+
<%= gettext "Block Number" %>
+
+ + <%= link(@transaction.block_number, to: block_path(@conn, :show, @conn.assigns.locale, @transaction.block_number), class: "transaction__link") %> + + + (<%= gettext "%{confirmations} block confirmations", confirmations: @transaction.confirmations %>) + +
+
+
+
<%= gettext "Age" %>
+
<%= @transaction.formatted_age %>
+
+
+
<%= gettext "Value" %>
+
<%= Decimal.div(Decimal.new(@transaction.value), Decimal.new(1_000_000_000_000_000_000)) |> Decimal.to_string(:normal) %> <%= gettext "POA" %>
+
+
+
<%= gettext "From" %>
+
+ <%= if @transaction.from_address do %> + <%= link(@transaction.from_address.hash, to: address_path(@conn, :show, @conn.assigns.locale, @transaction.from_address.hash), class: "transaction__link") %> + <% else %> + <%= gettext "Pending" %> + <% end %> +
+
+
+
<%= gettext "To" %>
+
+ <%= if @transaction.to_address do %> + <%= link(@transaction.to_address.hash, to: address_path(@conn, :show, @conn.assigns.locale, @transaction.to_address.hash), class: "transaction__link") %> + <% else %> + <%= gettext "Pending" %> + <% end %> +
+
+
+
+
+
+
+
<%= gettext "First Seen" %>
+
<%= @transaction.first_seen %>
+
+
+
<%= gettext "Last Seen" %>
+
<%= @transaction.last_seen %>
+
+
+
<%= gettext "Gas Limit" %>
+
<%= format_gas_limit(@transaction.gas) %>
+
+
+
<%= gettext "Gas Price" %>
+
<%= @transaction.gas_price |> Cldr.Number.to_string! %> (<%= Decimal.div(Decimal.new(@transaction.gas_price), Decimal.new(1_000_000_000)) |> Decimal.to_string(:normal) %> Gwei)
+
+
+
<%= gettext "Cumulative Gas Used" %>
+
<%= @transaction.cumulative_gas_used %>
+
+
+
<%= gettext "Nonce" %>
+
<%= @transaction.nonce %>
+
+
+
<%= gettext "Input" %>
+
<%= @transaction.input %>
+
+
+
+
+
diff --git a/apps/explorer_web/lib/explorer_web/templates/transaction/show.html.eex b/apps/explorer_web/lib/explorer_web/templates/transaction/show.html.eex index 5f583f91a6..e4db1c7a77 100644 --- a/apps/explorer_web/lib/explorer_web/templates/transaction/show.html.eex +++ b/apps/explorer_web/lib/explorer_web/templates/transaction/show.html.eex @@ -1,103 +1,44 @@
-
-

<%= gettext "Transaction Details" %>

-

<%= @transaction.hash %>

-
+ <%= render "overview.html", assigns %> +
-

<%= link(gettext("Overview"), to: transaction_path(@conn, :show, @conn.assigns.locale, @transaction.hash), class: "transaction__link transaction__link--active") %>

-

<%= link(gettext("Internal Transactions"), to: transaction_internal_transaction_path(@conn, :index, @conn.assigns.locale, @transaction.hash), class: "transaction__link") %>

+

<%= link(gettext("Internal Transactions"), to: transaction_path(@conn, :show, @conn.assigns.locale, @transaction.hash), class: "transaction__link transaction__link--active") %>

<%= link(gettext("Logs"), to: transaction_log_path(@conn, :index, @conn.assigns.locale, @transaction.hash), class: "transaction__link") %>

-
-
-
-
-
<%= gettext "Transaction Hash" %>
-
<%= @transaction.hash %>
-
-
-
<%= gettext "Transaction Status" %>
-
-
- <%= @transaction.formatted_status %> -
-
-
-
-
-
<%= gettext "Block Number" %>
-
- - <%= link(@transaction.block_number, to: block_path(@conn, :show, @conn.assigns.locale, @transaction.block_number), class: "transaction__link") %> - - - (<%= gettext "%{confirmations} block confirmations", confirmations: @transaction.confirmations %>) - -
-
-
-
<%= gettext "Age" %>
-
<%= @transaction.formatted_age %>
-
-
-
<%= gettext "Value" %>
-
<%= Decimal.div(Decimal.new(@transaction.value), Decimal.new(1_000_000_000_000_000_000)) |> Decimal.to_string(:normal) %> <%= gettext "POA" %>
-
-
-
<%= gettext "From" %>
-
- <%= if @transaction.from_address do %> - <%= link(@transaction.from_address.hash, to: address_path(@conn, :show, @conn.assigns.locale, @transaction.from_address.hash), class: "transaction__link") %> - <% else %> - <%= gettext "Pending" %> - <% end %> -
-
-
-
<%= gettext "To" %>
-
- <%= if @transaction.to_address do %> - <%= link(@transaction.to_address.hash, to: address_path(@conn, :show, @conn.assigns.locale, @transaction.to_address.hash), class: "transaction__link") %> - <% else %> - <%= gettext "Pending" %> - <% end %> -
-
-
-
-
-
-
-
<%= gettext "First Seen" %>
-
<%= @transaction.first_seen %>
-
-
-
<%= gettext "Last Seen" %>
-
<%= @transaction.last_seen %>
-
-
-
<%= gettext "Gas Limit" %>
-
<%= format_gas_limit(@transaction.gas) %>
-
-
-
<%= gettext "Gas Price" %>
-
<%= @transaction.gas_price |> Cldr.Number.to_string! %> (<%= Decimal.div(Decimal.new(@transaction.gas_price), Decimal.new(1_000_000_000)) |> Decimal.to_string(:normal) %> Gwei)
-
-
-
<%= gettext "Cumulative Gas Used" %>
-
<%= @transaction.cumulative_gas_used %>
-
-
-
<%= gettext "Nonce" %>
-
<%= @transaction.nonce %>
-
-
-
<%= gettext "Input" %>
-
<%= @transaction.input %>
-
-
-
+
+ <%= if length(@internal_transactions) > 0 do %> + + + + + + + + + <%= for transaction <- @internal_transactions do %> + + + + + + + + + + <% end %> +
<%= gettext "Type" %><%= gettext "From" %><%= gettext "To" %><%= gettext "Value" %><%= gettext "Gas Limit" %>
<%= transaction.call_type %> + <%= link(transaction.to_address.hash, + to: address_path(@conn, :show, @conn.assigns.locale, transaction.to_address.hash), + class: "transaction-log__link") %> + + <%= link(transaction.from_address.hash, + to: address_path(@conn, :show, @conn.assigns.locale, transaction.from_address.hash), + class: "transaction-log__link") %> + <%= transaction.value %><%= ExplorerWeb.TransactionView.format_gas_limit(transaction.gas) %>
+ <% else %> +

There are no Internal Transactions

+ <% end %>
diff --git a/apps/explorer_web/lib/explorer_web/templates/transaction_log/index.html.eex b/apps/explorer_web/lib/explorer_web/templates/transaction_log/index.html.eex index d3892be7c2..c89254e5b0 100644 --- a/apps/explorer_web/lib/explorer_web/templates/transaction_log/index.html.eex +++ b/apps/explorer_web/lib/explorer_web/templates/transaction_log/index.html.eex @@ -1,39 +1,40 @@
-
-

<%= gettext "Transaction Logs" %>

-

<%= @transaction_hash %>

-
+ <%= render ExplorerWeb.TransactionView, "overview.html", assigns %> +
-

<%= link(gettext("Overview"), to: transaction_path(@conn, :show, @conn.assigns.locale, @transaction_hash), class: "transaction-log__link") %>

-

<%= link(gettext("Internal Transactions"), to: transaction_internal_transaction_path(@conn, :index, @conn.assigns.locale, @transaction_hash), class: "transaction__link") %>

-

<%= link(gettext("Logs"), to: transaction_log_path(@conn, :index, @conn.assigns.locale, @transaction_hash), class: "transaction-log__link transaction-log__link--active") %>

+

<%= link(gettext("Internal Transactions"), to: transaction_path(@conn, :show, @conn.assigns.locale, @transaction.hash), class: "transaction__link") %>

+

<%= link(gettext("Logs"), to: transaction_log_path(@conn, :index, @conn.assigns.locale, @transaction.hash), class: "transaction__link transaction__link--active") %>

- - - - - - <%= for log <- @logs.entries do %> - - - - - - <% unless is_nil(log.second_topic) do %> - - <% end %> - <% unless is_nil(log.third_topic) do %> - - <% end %> - <% unless is_nil(log.data) do %> - - <% end %> - - <% end %> -
<%= gettext "Address" %><%= gettext "Topic" %>
<%= link(log.address.hash, to: address_path(@conn, :show, @conn.assigns.locale, log.address.hash), class: "transaction-log__link") %><%= log.first_topic %>
topic[1]<%= log.second_topic %>
topic[2]<%= log.third_topic %>
<%= log.data %>
+ <%= if length(@logs.entries) > 0 do %> + + + + + + <%= for log <- @logs.entries do %> + + + + + + <% unless is_nil(log.second_topic) do %> + + <% end %> + <% unless is_nil(log.third_topic) do %> + + <% end %> + <% unless is_nil(log.data) do %> + + <% end %> + + <% end %> +
<%= gettext "Address" %><%= gettext "Topic" %>
<%= link(log.address.hash, to: address_path(@conn, :show, @conn.assigns.locale, log.address.hash), class: "transaction-log__link") %><%= log.first_topic %>
topic[1]<%= log.second_topic %>
topic[2]<%= log.third_topic %>
<%= log.data %>
+ <% else %> +

There are no logs currently.

+ <% end %>
diff --git a/apps/explorer_web/test/explorer_web/controllers/internal_transaction_controller_test.exs b/apps/explorer_web/test/explorer_web/controllers/internal_transaction_controller_test.exs deleted file mode 100644 index 215d736f68..0000000000 --- a/apps/explorer_web/test/explorer_web/controllers/internal_transaction_controller_test.exs +++ /dev/null @@ -1,22 +0,0 @@ -defmodule ExplorerWeb.InternalTransactionControllerTest do - use ExplorerWeb.ConnCase - - import ExplorerWeb.Router.Helpers, only: [transaction_internal_transaction_path: 4] - - describe "GET index/2" do - test "returns internal transactions for the transaction", %{conn: conn} do - transaction = insert(:transaction) - internal_transaction = insert(:internal_transaction, transaction_id: transaction.id) - - path = - transaction_internal_transaction_path(ExplorerWeb.Endpoint, :index, :en, transaction.hash) - - conn = get(conn, path) - - first_internal_transaction = List.first(conn.assigns.internal_transactions) - - assert conn.assigns.transaction_hash == transaction.hash - assert first_internal_transaction.id == internal_transaction.id - end - end -end diff --git a/apps/explorer_web/test/explorer_web/controllers/transaction_controller_test.exs b/apps/explorer_web/test/explorer_web/controllers/transaction_controller_test.exs index 1da2db27f8..0b7d5e5bf7 100644 --- a/apps/explorer_web/test/explorer_web/controllers/transaction_controller_test.exs +++ b/apps/explorer_web/test/explorer_web/controllers/transaction_controller_test.exs @@ -1,6 +1,8 @@ defmodule ExplorerWeb.TransactionControllerTest do use ExplorerWeb.ConnCase + import ExplorerWeb.Router.Helpers, only: [transaction_path: 4] + describe "GET index/2" do test "returns a transaction with a receipt", %{conn: conn} do transaction = insert(:transaction) @@ -71,5 +73,19 @@ defmodule ExplorerWeb.TransactionControllerTest do assert conn.assigns.transaction.id == transaction.id assert conn.assigns.transaction.block_number == "" end + + test "returns internal transactions for the transaction", %{conn: conn} do + transaction = insert(:transaction) + internal_transaction = insert(:internal_transaction, transaction_id: transaction.id) + + path = transaction_path(ExplorerWeb.Endpoint, :show, :en, transaction.hash) + + conn = get(conn, path) + + first_internal_transaction = List.first(conn.assigns.internal_transactions) + + assert conn.assigns.transaction.hash == transaction.hash + assert first_internal_transaction.id == internal_transaction.id + end end end diff --git a/apps/explorer_web/test/explorer_web/controllers/transaction_log_controller_test.exs b/apps/explorer_web/test/explorer_web/controllers/transaction_log_controller_test.exs index dca349f8eb..ee94254538 100644 --- a/apps/explorer_web/test/explorer_web/controllers/transaction_log_controller_test.exs +++ b/apps/explorer_web/test/explorer_web/controllers/transaction_log_controller_test.exs @@ -10,7 +10,9 @@ defmodule ExplorerWeb.TransactionLogControllerTest do address = insert(:address) insert(:log, receipt: receipt, address: address) path = transaction_log_path(ExplorerWeb.Endpoint, :index, :en, transaction.hash) + conn = get(conn, path) + first_log = List.first(conn.assigns.logs.entries) assert first_log.receipt_id == receipt.id end @@ -18,7 +20,9 @@ defmodule ExplorerWeb.TransactionLogControllerTest do test "assigns no logs when there are none", %{conn: conn} do transaction = insert(:transaction) path = transaction_log_path(ExplorerWeb.Endpoint, :index, :en, transaction.hash) + conn = get(conn, path) + assert Enum.count(conn.assigns.logs.entries) == 0 end end diff --git a/apps/explorer_web/test/explorer_web/features/contributor_browsing_test.exs b/apps/explorer_web/test/explorer_web/features/contributor_browsing_test.exs index 168abf5e42..9f0a23a00c 100644 --- a/apps/explorer_web/test/explorer_web/features/contributor_browsing_test.exs +++ b/apps/explorer_web/test/explorer_web/features/contributor_browsing_test.exs @@ -190,7 +190,7 @@ defmodule ExplorerWeb.UserListTest do |> visit("/en/transactions/0xSk8") |> click(link("Logs")) |> assert_has(css(".transaction-log__link", text: "0xlincoln")) - |> click(link("0xlincoln")) + |> click(css(".transaction-log__link", text: "0xlincoln")) |> assert_has(css(".address__subheading", text: "0xlincoln")) |> click(css(".address__link", text: "Transactions To")) |> assert_has(css(".transactions__link--long-hash", text: "0xSk8"))