Skip to content

Commit

Permalink
Merge pull request #30 from aurora-is-near/near-tx
Browse files Browse the repository at this point in the history
Show near metada for aurora tx
  • Loading branch information
spilin authored Jul 4, 2023
2 parents 53c1294 + e8b8110 commit 2caa9d3
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<% hash = @hash %>
<% near_network = @near_network %>

<%= cond do %>
<% near_network == "mainnet" -> %>
<%= link hash, to: "https://explorer.near.org/transactions/#{hash}", target: "_blank", rel: "nofollow noopener noreferrer", class: assigns[:class] %>

<% near_network == "testnet" -> %>
<%= link hash, to: "https://explorer.testnet.near.org/transactions/#{hash}", target: "_blank", rel: "nofollow noopener noreferrer", class: assigns[:class] %>

<% true -> %>
<%= hash %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<% base_fee_per_gas = if block, do: block.base_fee_per_gas, else: nil %>
<% max_priority_fee_per_gas = @transaction.max_priority_fee_per_gas %>
<% max_fee_per_gas = @transaction.max_fee_per_gas %>
<% burned_fee =
<% burned_fee =
if !is_nil(max_fee_per_gas) and !is_nil(@transaction.gas_used) and !is_nil(base_fee_per_gas) do
if Decimal.compare(max_fee_per_gas.value, 0) == :eq do
%Wei{value: Decimal.new(0)}
Expand All @@ -27,6 +27,10 @@
<% {:ok, created_from_address} = if to_address_hash, do: Chain.hash_to_address(to_address_hash), else: {:ok, nil} %>
<% created_from_address_hash_str = if from_address_hash(created_from_address), do: "0x" <> Base.encode16(from_address_hash(created_from_address).bytes, case: :lower), else: nil %>
<%= render BlockScoutWeb.Advertisement.TextAdView, "index.html", conn: @conn %>
<% near_receipt_hash = @transaction.near_receipt_hash %>
<% near_transaction_hash = @transaction.near_transaction_hash %>
<% near_network = System.get_env("NEAR_NETWORK") || nil %>

<section class="fs-14" data-page="transaction-details" data-page-transaction-hash="<%= @transaction %>">
<div class="row">
<div class="col-md-12">
Expand Down Expand Up @@ -122,7 +126,7 @@
<% true -> %>
<%= render BlockScoutWeb.FormView, "_tag.html", text: formatted_status, additional_classes: ["success", "large"] %></span>
<% end %>

<%= if confirmations > 0 do %>
<span class="bs-label large ml-2 confirmations-label"><%= gettext "Confirmed by " %><span data-selector="block-confirmations"><%= confirmations %></span><%= " " <> confirmations_ds_name(confirmations) %></span>
<% end %>
Expand Down Expand Up @@ -390,6 +394,42 @@
<dd class="col-sm-9 col-lg-10"> <%= type %> </dd>
</dl>
<% end %>
<!-- Near receipt -->
<%= if !is_nil(near_receipt_hash) do %>
<dl class="row">
<dt class="col-sm-3 col-lg-2 text-muted">
<%= gettext "Near Receipt" %>
</dt>
<dd class="col-sm-9 col-lg-10" style="word-break: break-all;">
<span>
<%= near_receipt_hash %>
</span>
<%= render BlockScoutWeb.CommonComponentsView, "_btn_copy.html",
additional_classes: ["btn-copy-icon-small", "btn-copy-icon-custom", "btn-copy-icon-no-borders"],
clipboard_text: near_receipt_hash,
aria_label: gettext("Copy Near Receipt"),
title: gettext("Copy Near Receipt") %>
</dd>
</dl>
<% end %>
<!-- Near transaction -->
<%= if !is_nil(near_transaction_hash) do %>
<dl class="row">
<dt class="col-sm-3 col-lg-2 text-muted">
<%= gettext "Near Transaction" %>
</dt>
<dd class="col-sm-9 col-lg-10" style="word-break: break-all;">
<span>
<%= render BlockScoutWeb.AddressView, "_near_tx.html", hash: near_transaction_hash, near_network: near_network %>
</span>
<%= render BlockScoutWeb.CommonComponentsView, "_btn_copy.html",
additional_classes: ["btn-copy-icon-small", "btn-copy-icon-custom", "btn-copy-icon-no-borders"],
clipboard_text: near_transaction_hash,
aria_label: gettext("Copy Near Transaction"),
title: gettext("Copy Near Transaction") %>
</dd>
</dl>
<% end %>
<hr>
<!-- Gas Limit -->
<dl class="row">
Expand Down Expand Up @@ -429,7 +469,7 @@
</dt>
<dd class="col-sm-9 col-lg-10"> <%= format_wei_value(priority_fee, :ether) %> </dd>
</dl>
<% end %>
<% end %>
<%= if !is_nil(burned_fee) do %>
<dl class="row">
<dt class="col-sm-3 col-lg-2 text-muted">
Expand Down
15 changes: 12 additions & 3 deletions apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/receipt.ex
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,19 @@ defmodule EthereumJSONRPC.Receipt do
created_contract_address_hash: String.t() | nil,
status: status(),
transaction_hash: String.t(),
transaction_index: non_neg_integer()
transaction_index: non_neg_integer(),
near_receipt_hash: String.t() | nil,
near_transaction_hash: String.t() | nil
}
def elixir_to_params(
%{
"cumulativeGasUsed" => cumulative_gas_used,
"gasUsed" => gas_used,
"contractAddress" => created_contract_address_hash,
"transactionHash" => transaction_hash,
"transactionIndex" => transaction_index
"transactionIndex" => transaction_index,
"nearReceiptHash" => near_receipt_hash,
"nearTransactionHash" => near_transaction_hash
} = elixir
) do
status = elixir_to_status(elixir)
Expand All @@ -136,7 +140,9 @@ defmodule EthereumJSONRPC.Receipt do
created_contract_address_hash: created_contract_address_hash,
status: status,
transaction_hash: transaction_hash,
transaction_index: transaction_index
transaction_index: transaction_index,
near_receipt_hash: near_receipt_hash,
near_transaction_hash: near_transaction_hash
}
end

Expand Down Expand Up @@ -268,6 +274,9 @@ defmodule EthereumJSONRPC.Receipt do
{:ok, {key, result}}
end

defp entry_to_elixir({"nearReceiptHash" = key, value}), do: {:ok, {key, value}}
defp entry_to_elixir({"nearTransactionHash" = key, value}), do: {:ok, {key, value}}

defp entry_to_elixir({"logs" = key, logs}) do
{:ok, {key, Logs.to_elixir(logs)}}
end
Expand Down
15 changes: 13 additions & 2 deletions apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/receipts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,11 @@ defmodule EthereumJSONRPC.Receipts do
defp response_to_receipt(%{id: id, result: receipt}, id_to_transaction_params) do
%{gas: gas} = Map.fetch!(id_to_transaction_params, id)

# gas from the transaction is needed for pre-Byzantium derived status
{:ok, Map.put(receipt, "gas", gas)}
receipt
|> Map.put("gas", gas)
|> convert_hash("nearReceiptHash")
|> convert_hash("nearTransactionHash")
|> (&{:ok, &1}).()
end

defp response_to_receipt(%{id: id, error: reason}, id_to_transaction_params) do
Expand All @@ -237,6 +240,14 @@ defmodule EthereumJSONRPC.Receipts do
{:error, annotated_reason}
end

defp convert_hash(receipt, key) do
hash_hex = receipt[key] |> String.slice(2..-1)
hash_bin = Base.decode16!(hash_hex, case: :lower)
hash_base58 = Base58.encode(hash_bin)

Map.put(receipt, key, hash_base58)
end

defp reduce_responses(responses, id_to_transaction_params)
when is_list(responses) and is_map(id_to_transaction_params) do
responses
Expand Down
5 changes: 3 additions & 2 deletions apps/ethereum_jsonrpc/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defmodule EthereumJsonrpc.MixProject do
def application do
[
mod: {EthereumJSONRPC.Application, []},
extra_applications: [:logger]
extra_applications: [:logger, :b58]
]
end

Expand Down Expand Up @@ -85,7 +85,8 @@ defmodule EthereumJsonrpc.MixProject do
{:decimal, "~> 2.0"},
{:decorator, "~> 1.4"},
{:hackney, "~> 1.18"},
{:poolboy, "~> 1.5.2"}
{:poolboy, "~> 1.5.2"},
{:b58, "~> 1.0.2"}
]
end
end
8 changes: 6 additions & 2 deletions apps/explorer/lib/explorer/chain/transaction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ defmodule Explorer.Chain.Transaction do
alias Explorer.SmartContract.SigProviderInterface

@optional_attrs ~w(max_priority_fee_per_gas max_fee_per_gas block_hash block_number created_contract_address_hash cumulative_gas_used earliest_processing_start
error gas_used index created_contract_code_indexed_at status to_address_hash revert_reason type has_error_in_internal_txs)a
error gas_used index created_contract_code_indexed_at status to_address_hash revert_reason type has_error_in_internal_txs near_receipt_hash near_transaction_hash)a

@required_attrs ~w(from_address_hash gas gas_price hash input nonce r s v value)a

Expand Down Expand Up @@ -174,7 +174,9 @@ defmodule Explorer.Chain.Transaction do
max_priority_fee_per_gas: wei_per_gas | nil,
max_fee_per_gas: wei_per_gas | nil,
type: non_neg_integer() | nil,
has_error_in_internal_txs: boolean()
has_error_in_internal_txs: boolean(),
near_receipt_hash: String.t() | nil,
near_transaction_hash: String.t() | nil
}

@derive {Poison.Encoder,
Expand Down Expand Up @@ -241,6 +243,8 @@ defmodule Explorer.Chain.Transaction do
field(:type, :integer)
field(:has_error_in_internal_txs, :boolean)
field(:has_token_transfers, :boolean, virtual: true)
field(:near_receipt_hash, :string)
field(:near_transaction_hash, :string)

# A transient field for deriving old block hash during transaction upserts.
# Used to force refetch of a block in case a transaction is re-collated
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
defmodule Explorer.Repo.Migrations.AddNearData do
use Ecto.Migration

def change do
alter table(:transactions) do
add(:near_receipt_hash, :string, null: true)
add(:near_transaction_hash, :string, null: true)
end
end
end
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"absinthe_plug": {:git, "https://github.com/blockscout/absinthe_plug.git", "c435d43f316769e1beee1dbe500b623124c96785", [tag: "1.5.3"]},
"absinthe_relay": {:hex, :absinthe_relay, "1.5.2", "cfb8aed70f4e4c7718d3f1c212332d2ea728f17c7fc0f68f1e461f0f5f0c4b9a", [:mix], [{:absinthe, "~> 1.5.0 or ~> 1.6.0 or ~> 1.7.0", [hex: :absinthe, repo: "hexpm", optional: false]}, {:ecto, "~> 2.0 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm", "0587ee913afa31512e1457a5064ee88427f8fe7bcfbeeecd41c71d9cff0b62b6"},
"accept": {:hex, :accept, "0.3.5", "b33b127abca7cc948bbe6caa4c263369abf1347cfa9d8e699c6d214660f10cd1", [:rebar3], [], "hexpm", "11b18c220bcc2eab63b5470c038ef10eb6783bcb1fcdb11aa4137defa5ac1bb8"},
"b58": {:hex, :b58, "1.0.3", "d300d6ae5a3de956a54b9e8220e924e4fee1a349de983df2340fe61e0e464202", [:mix], [], "hexpm", "af62a98a8661fd89978cf3a3a4b5b2ebe82209de6ac6164f0b112e36af72fc59"},
"bamboo": {:hex, :bamboo, "2.3.0", "d2392a2cabe91edf488553d3c70638b532e8db7b76b84b0a39e3dfe492ffd6fc", [:mix], [{:hackney, ">= 1.15.2", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mime, "~> 1.4 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "dd0037e68e108fd04d0e8773921512c940e35d981e097b5793543e3b2f9cd3f6"},
"bcrypt_elixir": {:hex, :bcrypt_elixir, "3.0.1", "9be815469e6bfefec40fa74658ecbbe6897acfb57614df1416eeccd4903f602c", [:make, :mix], [{:comeonin, "~> 5.3", [hex: :comeonin, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "486bb95efb645d1efc6794c1ddd776a186a9a713abf06f45708a6ce324fb96cf"},
"benchee": {:hex, :benchee, "1.1.0", "f3a43817209a92a1fade36ef36b86e1052627fd8934a8b937ac9ab3a76c43062", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}, {:statistex, "~> 1.0", [hex: :statistex, repo: "hexpm", optional: false]}], "hexpm", "7da57d545003165a012b587077f6ba90b89210fd88074ce3c60ce239eb5e6d93"},
Expand Down

0 comments on commit 2caa9d3

Please sign in to comment.