make block transaction async

pull/2012/head
Ayrat Badykov 6 years ago
parent a31229d1bc
commit 454067f8f5
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 80
      apps/block_scout_web/lib/block_scout_web/controllers/block_transaction_controller.ex
  2. 12
      apps/block_scout_web/lib/block_scout_web/controllers/transaction_log_controller.ex
  3. 12
      apps/block_scout_web/lib/block_scout_web/controllers/transaction_token_transfer_controller.ex
  4. 40
      apps/block_scout_web/lib/block_scout_web/templates/block_transaction/index.html.eex

@ -5,20 +5,14 @@ defmodule BlockScoutWeb.BlockTransactionController do
only: [paging_options: 1, next_page_params: 3, split_list_by_page: 1] only: [paging_options: 1, next_page_params: 3, split_list_by_page: 1]
import Explorer.Chain, only: [hash_to_block: 2, number_to_block: 2, string_to_block_hash: 1] import Explorer.Chain, only: [hash_to_block: 2, number_to_block: 2, string_to_block_hash: 1]
alias BlockScoutWeb.TransactionView
alias Explorer.Chain alias Explorer.Chain
alias Phoenix.View
def index(conn, %{"block_hash_or_number" => formatted_block_hash_or_number} = params) do def index(conn, %{"block_hash_or_number" => formatted_block_hash_or_number, "type" => "JSON"} = params) do
with {:ok, block} <- with {:ok, block} <-
param_block_hash_or_number_to_block(formatted_block_hash_or_number, param_block_hash_or_number_to_block(formatted_block_hash_or_number, []) do
necessity_by_association: %{
[miner: :names] => :required,
:uncles => :optional,
:nephews => :optional,
:rewards => :optional
}
) do
block_transaction_count = Chain.block_to_transaction_count(block)
full_options = full_options =
Keyword.merge( Keyword.merge(
[ [
@ -36,13 +30,73 @@ defmodule BlockScoutWeb.BlockTransactionController do
{transactions, next_page} = split_list_by_page(transactions_plus_one) {transactions, next_page} = split_list_by_page(transactions_plus_one)
next_page_path =
case next_page_params(next_page, transactions, params) do
nil ->
nil
next_page_params ->
block_transaction_path(
conn,
:index,
block,
Map.delete(next_page_params, "type")
)
end
items =
transactions
|> Enum.map(fn transaction ->
View.render_to_string(
TransactionView,
"_tile.html",
transaction: transaction
)
end)
json(
conn,
%{
items: items,
next_page_path: next_page_path
}
)
else
{:error, {:invalid, :hash}} ->
not_found(conn)
{:error, {:invalid, :number}} ->
not_found(conn)
{:error, :not_found} ->
conn
|> put_status(:not_found)
|> render(
"404.html",
block: nil,
block_above_tip: block_above_tip(formatted_block_hash_or_number)
)
end
end
def index(conn, %{"block_hash_or_number" => formatted_block_hash_or_number}) do
with {:ok, block} <-
param_block_hash_or_number_to_block(formatted_block_hash_or_number,
necessity_by_association: %{
[miner: :names] => :required,
:uncles => :optional,
:nephews => :optional,
:rewards => :optional
}
) do
block_transaction_count = Chain.block_to_transaction_count(block)
render( render(
conn, conn,
"index.html", "index.html",
block: block, block: block,
block_transaction_count: block_transaction_count, block_transaction_count: block_transaction_count,
next_page_params: next_page_params(next_page, transactions, params), current_path: current_path(conn)
transactions: transactions
) )
else else
{:error, {:invalid, :hash}} -> {:error, {:invalid, :hash}} ->

@ -11,17 +11,7 @@ defmodule BlockScoutWeb.TransactionLogController do
def index(conn, %{"transaction_id" => transaction_hash_string, "type" => "JSON"} = 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), with {:ok, transaction_hash} <- Chain.string_to_transaction_hash(transaction_hash_string),
{:ok, transaction} <- {:ok, transaction} <-
Chain.hash_to_transaction( Chain.hash_to_transaction(transaction_hash) do
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
full_options = full_options =
Keyword.merge( Keyword.merge(
[ [

@ -11,17 +11,7 @@ defmodule BlockScoutWeb.TransactionTokenTransferController do
def index(conn, %{"transaction_id" => hash_string, "type" => "JSON"} = params) do def index(conn, %{"transaction_id" => hash_string, "type" => "JSON"} = params) do
with {:ok, hash} <- Chain.string_to_transaction_hash(hash_string), with {:ok, hash} <- Chain.string_to_transaction_hash(hash_string),
{:ok, transaction} <- {:ok, transaction} <-
Chain.hash_to_transaction( Chain.hash_to_transaction(hash) do
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
full_options = full_options =
Keyword.merge( Keyword.merge(
[ [

@ -13,38 +13,26 @@
) )
%> %>
</div> </div>
<div class="card-body">
<div class="card-body" data-async-load data-async-listing="<%= @current_path %>">
<h2 class="card-title"><%= gettext "Transactions" %></h2> <h2 class="card-title"><%= gettext "Transactions" %></h2>
<%= if @next_page_params do %> <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %>
<%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", cur_page_number: "1", show_pagination_limit: true, next_page_path: transaction_path(@conn, :index, @next_page_params) %>
<% end %> <button data-error-message class="alert alert-danger col-12 text-left" style="display: none;">
<span href="#" class="alert-link"><%= gettext("Something went wrong, click to reload.") %></span>
<%= if !@next_page_params do %> </button>
<%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", cur_page_number: "1", show_pagination_limit: true %>
<% end %> <div data-empty-response-message style="display: none;">
<div class="tile tile-muted text-center" data-selector="empty-transactions-list">
<%= if Enum.count(@transactions) > 0 do %> <%= gettext "There are no transactions for this block." %>
<span data-selector="transactions-list"> </div>
<%= for transaction <- @transactions do %>
<%= render BlockScoutWeb.TransactionView, "_tile.html", transaction: transaction %>
<% end %>
</span>
<% else %>
<div class="tile tile-muted text-center">
<span data-selector="empty-transactions-list"><%= gettext "There are no transactions for this block." %></span>
</div> </div>
<% end %>
<%= if @next_page_params do %> <div data-items></div>
<%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "bottom", cur_page_number: "1", show_pagination_limit: true, next_page_path: transaction_path(@conn, :index, @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, data_next_page_button: true, data_prev_page_button: true %>
<%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "bottom", cur_page_number: "1", show_pagination_limit: true %>
<% end %>
</div> </div>
</div>
</section> </section>
</section> </section>

Loading…
Cancel
Save