Add created_contract_address_hash to transaction detail overview

Co-authored-by: Timothy Mecklem <timothy@mecklem.com>
Co-authored-by: jimmay5469 <jimmay5469@gmail.com>
pull/275/head
Tim Mecklem 7 years ago committed by katibest
parent 1e449cca99
commit 6c9772daf5
  1. 17
      apps/explorer/lib/explorer/chain.ex
  2. 2
      apps/explorer/lib/explorer/chain/internal_transaction.ex
  3. 1
      apps/explorer/lib/explorer/chain/transaction.ex
  4. 21
      apps/explorer_web/lib/explorer_web/templates/transaction/overview.html.eex
  5. 9
      apps/explorer_web/test/explorer_web/controllers/transaction_internal_transaction_controller_test.exs
  6. 6
      apps/explorer_web/test/explorer_web/features/pages/transaction_page.ex
  7. 9
      apps/explorer_web/test/explorer_web/features/viewing_transactions_test.exs

@ -583,8 +583,21 @@ defmodule Explorer.Chain do
|> join_associations(necessity_by_association)
|> Repo.one()
|> case do
nil -> {:error, :not_found}
transaction -> {:ok, transaction}
nil ->
{:error, :not_found}
transaction = %Transaction{to_address: nil} ->
internal_transaction =
InternalTransaction
|> join(:inner, [internal_transaction], transaction in assoc(internal_transaction, :transaction))
|> where([_, transaction], transaction.hash == ^hash)
|> where([internal_transaction], internal_transaction.type == ^:create)
|> Repo.one!()
{:ok, %{transaction | created_contract_address_hash: internal_transaction.created_contract_address_hash}}
transaction ->
{:ok, transaction}
end
end

@ -28,6 +28,8 @@ defmodule Explorer.Chain.InternalTransaction do
"""
@type t :: %__MODULE__{
call_type: CallType.t() | nil,
created_contract_address: %Ecto.Association.NotLoaded{} | Address.t(),
created_contract_address_hash: Explorer.Chain.Hash.t(),
created_contract_code: Data.t() | nil,
error: String.t(),
from_address: %Ecto.Association.NotLoaded{} | Address.t(),

@ -154,6 +154,7 @@ defmodule Explorer.Chain.Transaction do
field(:status, Status)
field(:v, :integer)
field(:value, Wei)
field(:created_contract_address_hash, Hash.Truncated, virtual: true)
timestamps()

@ -73,15 +73,11 @@
<%= gettext "From" %>
</th>
<td>
<%= if @transaction.from_address do %>
<%= link(
@transaction.from_address,
class: "transaction__link",
to: address_path(@conn, :show, @conn.assigns.locale, @transaction.from_address)
) %>
<% else %>
<%= gettext "Pending" %>
<% end %>
<%= link(
@transaction.from_address,
class: "transaction__link",
to: address_path(@conn, :show, @conn.assigns.locale, @transaction.from_address)
) %>
</td>
</tr>
<tr>
@ -96,7 +92,12 @@
to: address_path(@conn, :show, @conn.assigns.locale, @transaction.to_address)
) %>
<% else %>
<%= gettext "Pending" %>
[Contract <%= link(
@transaction.created_contract_address_hash,
class: "transaction__link",
"data-test": "created_contract_address_hash",
to: address_path(@conn, :show, @conn.assigns.locale, @transaction.created_contract_address_hash)
) %> Created]
<% end %>
</td>
</tr>

@ -58,5 +58,14 @@ defmodule ExplorerWeb.TransactionInternalTransactionControllerTest do
assert %Token{} = conn.assigns.exchange_rate
end
test "with no to_address_hash overview contains contract create address", %{conn: conn} do
transaction = insert(:transaction, to_address_hash: nil)
insert(:internal_transaction_create, transaction_hash: transaction.hash, index: 0)
conn = get(conn, transaction_internal_transaction_path(ExplorerWeb.Endpoint, :index, :en, transaction.hash))
refute is_nil(conn.assigns.transaction.created_contract_address_hash)
end
end
end

@ -5,7 +5,7 @@ defmodule ExplorerWeb.TransactionPage do
import Wallaby.Query, only: [css: 1, css: 2]
alias Explorer.Chain.{Transaction, Hash}
alias Explorer.Chain.{InternalTransaction, Transaction, Hash}
def click_logs(session) do
click(session, css("[data-test='transaction_logs_link']"))
@ -15,6 +15,10 @@ defmodule ExplorerWeb.TransactionPage do
css("[data-test='transaction_detail_hash']", text: Hash.to_string(transaction_hash))
end
def contract_creation_address_hash(%InternalTransaction{created_contract_address_hash: hash}) do
css("[data-test='created_contract_address_hash']", text: Hash.to_string(hash))
end
def visit_page(session, %Transaction{hash: transaction_hash}) do
visit(session, "/en/transactions/#{transaction_hash}")
end

@ -106,6 +106,15 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
|> assert_has(TransactionPage.detail_hash(transaction))
end
test "can see a contract creation address in to_address", %{session: session} do
transaction = insert(:transaction, to_address_hash: nil)
internal_transaction = insert(:internal_transaction_create, transaction_hash: transaction.hash, index: 0)
session
|> TransactionPage.visit_page(transaction)
|> assert_has(TransactionPage.contract_creation_address_hash(internal_transaction))
end
test "can view a transaction's logs", %{session: session, transaction: transaction} do
session
|> TransactionPage.visit_page(transaction)

Loading…
Cancel
Save