forked from blockscout/blockscout
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95f50ce
commit 8683b66
Showing
16 changed files
with
507 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
apps/block_scout_web/assets/js/view_specific/raw_trace/code_highlighting.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import $ from 'jquery' | ||
import hljs from 'highlight.js' | ||
|
||
// only activate highlighting on pages with this selector | ||
if ($('[data-activate-highlight]').length > 0) { | ||
hljs.initHighlightingOnLoad() | ||
} |
55 changes: 55 additions & 0 deletions
55
apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
defmodule BlockScoutWeb.TransactionRawTraceController do | ||
use BlockScoutWeb, :controller | ||
|
||
alias BlockScoutWeb.TransactionView | ||
alias Explorer.{Chain, Market} | ||
alias Explorer.ExchangeRates.Token | ||
|
||
def index(conn, %{"transaction_id" => hash_string}) do | ||
with {:ok, hash} <- Chain.string_to_transaction_hash(hash_string), | ||
{:ok, transaction} <- | ||
Chain.hash_to_transaction( | ||
hash, | ||
necessity_by_association: %{ | ||
:block => :optional, | ||
[created_contract_address: :names] => :optional, | ||
[from_address: :names] => :optional, | ||
[to_address: :names] => :optional, | ||
[to_address: :smart_contract] => :optional, | ||
:token_transfers => :optional | ||
} | ||
) do | ||
options = [ | ||
necessity_by_association: %{ | ||
[created_contract_address: :names] => :optional, | ||
[from_address: :names] => :optional, | ||
[to_address: :names] => :optional | ||
} | ||
] | ||
|
||
internal_transactions = Chain.transaction_to_internal_transactions(transaction, options) | ||
|
||
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 | ||
) | ||
else | ||
:error -> | ||
conn | ||
|> put_status(422) | ||
|> put_view(TransactionView) | ||
|> render("invalid.html", transaction_hash: hash_string) | ||
|
||
{:error, :not_found} -> | ||
conn | ||
|> put_status(404) | ||
|> put_view(TransactionView) | ||
|> render("not_found.html", transaction_hash: hash_string) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
apps/block_scout_web/lib/block_scout_web/templates/transaction_raw_trace/_metatags.html.eex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= render BlockScoutWeb.TransactionView, "_metatags.html", conn: @conn, transaction: @transaction %> |
18 changes: 18 additions & 0 deletions
18
apps/block_scout_web/lib/block_scout_web/templates/transaction_raw_trace/index.html.eex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<section class="container"> | ||
<%= render BlockScoutWeb.TransactionView, "overview.html", assigns %> | ||
|
||
<div class="card"> | ||
<div class="card-header"> | ||
<%= render BlockScoutWeb.TransactionView, "_tabs.html", assigns %> | ||
</div> | ||
|
||
<div class="card-body"> | ||
<h2 class="card-title"><%= gettext "Raw Trace" %></h2> | ||
<%= if Enum.count(@internal_transactions) > 0 do %> | ||
<pre class="pre-scrollable line-numbers" data-activate-highlight><code class="json "><%= for {line, number} <- raw_traces_with_lines(@internal_transactions) do %><div data-line-number="<%= number %>"><%= line %></div><% end %></code></pre> | ||
<% else %> | ||
No trace entries found. | ||
<% end %> | ||
</div> | ||
</div> | ||
</section> |
18 changes: 18 additions & 0 deletions
18
apps/block_scout_web/lib/block_scout_web/views/transaction_raw_trace_view.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
defmodule BlockScoutWeb.TransactionRawTraceView do | ||
use BlockScoutWeb, :view | ||
@dialyzer :no_match | ||
|
||
alias Explorer.Chain.InternalTransaction | ||
|
||
def render("scripts.html", %{conn: conn}) do | ||
render_scripts(conn, "raw_trace/code_highlighting.js") | ||
end | ||
|
||
def raw_traces_with_lines(internal_transactions) do | ||
internal_transactions | ||
|> InternalTransaction.internal_transactions_to_raw() | ||
|> Jason.encode!(pretty: true) | ||
|> String.split("\n") | ||
|> Enum.with_index() | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
apps/explorer/lib/explorer/chain/internal_transaction/action.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
defmodule Explorer.Chain.InternalTransaction.Action do | ||
@moduledoc """ | ||
The action that was performed in a `t:EthereumJSONRPC.Parity.Trace.t/0` | ||
""" | ||
|
||
import EthereumJSONRPC, only: [integer_to_quantity: 1] | ||
alias Explorer.Chain.{Data, Hash, Wei} | ||
|
||
def to_raw(action) when is_map(action) do | ||
Enum.into(action, %{}, &entry_to_raw/1) | ||
end | ||
|
||
defp entry_to_raw({key, %Data{} = data}) when key in ~w(init input) do | ||
{key, Data.to_string(data)} | ||
end | ||
|
||
defp entry_to_raw({key, %Hash{} = address}) when key in ~w(address from refundAddress to) do | ||
{key, to_string(address)} | ||
end | ||
|
||
defp entry_to_raw({"callType", type}) do | ||
{"callType", Atom.to_string(type)} | ||
end | ||
|
||
defp entry_to_raw({"gas" = key, %Decimal{} = decimal}) do | ||
value = | ||
decimal | ||
|> Decimal.round() | ||
|> Decimal.to_integer() | ||
|
||
{key, integer_to_quantity(value)} | ||
end | ||
|
||
defp entry_to_raw({key, %Wei{value: value}}) when key in ~w(balance value) do | ||
rounded = | ||
value | ||
|> Decimal.round() | ||
|> Decimal.to_integer() | ||
|
||
{key, integer_to_quantity(rounded)} | ||
end | ||
end |
32 changes: 32 additions & 0 deletions
32
apps/explorer/lib/explorer/chain/internal_transaction/result.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
defmodule Explorer.Chain.InternalTransaction.Result do | ||
@moduledoc """ | ||
The result of performing the `t:EthereumJSONRPC.Parity.Action.t/0` in a `t:EthereumJSONRPC.Parity.Trace.t/0`. | ||
""" | ||
|
||
import EthereumJSONRPC, only: [integer_to_quantity: 1] | ||
|
||
alias Explorer.Chain.{Data, Hash} | ||
|
||
def to_raw(result) when is_map(result) do | ||
Enum.into(result, %{}, &entry_to_raw/1) | ||
end | ||
|
||
defp entry_to_raw({"output" = key, %Data{} = data}) do | ||
{key, Data.to_string(data)} | ||
end | ||
|
||
defp entry_to_raw({"address" = key, %Hash{} = hash}) do | ||
{key, to_string(hash)} | ||
end | ||
|
||
defp entry_to_raw({"code", _} = entry), do: entry | ||
|
||
defp entry_to_raw({key, decimal}) when key in ~w(gasUsed) do | ||
integer = | ||
decimal | ||
|> Decimal.round() | ||
|> Decimal.to_integer() | ||
|
||
{key, integer_to_quantity(integer)} | ||
end | ||
end |
Oops, something went wrong.