|
|
@ -11,57 +11,57 @@ defmodule BlockScoutWeb.BlockTransactionController do |
|
|
|
alias Phoenix.View |
|
|
|
alias Phoenix.View |
|
|
|
|
|
|
|
|
|
|
|
def index(conn, %{"block_hash_or_number" => formatted_block_hash_or_number, "type" => "JSON"} = params) do |
|
|
|
def index(conn, %{"block_hash_or_number" => formatted_block_hash_or_number, "type" => "JSON"} = params) do |
|
|
|
with {:ok, block} <- |
|
|
|
case param_block_hash_or_number_to_block(formatted_block_hash_or_number, []) do |
|
|
|
param_block_hash_or_number_to_block(formatted_block_hash_or_number, []) do |
|
|
|
{:ok, block} -> |
|
|
|
full_options = |
|
|
|
full_options = |
|
|
|
Keyword.merge( |
|
|
|
Keyword.merge( |
|
|
|
[ |
|
|
|
[ |
|
|
|
necessity_by_association: %{ |
|
|
|
necessity_by_association: %{ |
|
|
|
:block => :optional, |
|
|
|
:block => :optional, |
|
|
|
[created_contract_address: :names] => :optional, |
|
|
|
[created_contract_address: :names] => :optional, |
|
|
|
[from_address: :names] => :required, |
|
|
|
[from_address: :names] => :required, |
|
|
|
[to_address: :names] => :optional |
|
|
|
[to_address: :names] => :optional |
|
|
|
} |
|
|
|
} |
|
|
|
], |
|
|
|
], |
|
|
|
paging_options(params) |
|
|
|
paging_options(params) |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
transactions_plus_one = Chain.block_to_transactions(block.hash, full_options) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{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 -> |
|
|
|
transactions_plus_one = Chain.block_to_transactions(block.hash, full_options) |
|
|
|
block_transaction_path( |
|
|
|
|
|
|
|
conn, |
|
|
|
{transactions, next_page} = split_list_by_page(transactions_plus_one) |
|
|
|
:index, |
|
|
|
|
|
|
|
block, |
|
|
|
next_page_path = |
|
|
|
Map.delete(next_page_params, "type") |
|
|
|
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 |
|
|
|
end) |
|
|
|
|
|
|
|
|
|
|
|
items = |
|
|
|
json( |
|
|
|
transactions |
|
|
|
conn, |
|
|
|
|> Enum.map(fn transaction -> |
|
|
|
%{ |
|
|
|
View.render_to_string( |
|
|
|
items: items, |
|
|
|
TransactionView, |
|
|
|
next_page_path: next_page_path |
|
|
|
"_tile.html", |
|
|
|
} |
|
|
|
transaction: transaction |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
end) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
json( |
|
|
|
|
|
|
|
conn, |
|
|
|
|
|
|
|
%{ |
|
|
|
|
|
|
|
items: items, |
|
|
|
|
|
|
|
next_page_path: next_page_path |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{:error, {:invalid, :hash}} -> |
|
|
|
{:error, {:invalid, :hash}} -> |
|
|
|
not_found(conn) |
|
|
|
not_found(conn) |
|
|
|
|
|
|
|
|
|
|
@ -80,25 +80,25 @@ defmodule BlockScoutWeb.BlockTransactionController do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def index(conn, %{"block_hash_or_number" => formatted_block_hash_or_number}) do |
|
|
|
def index(conn, %{"block_hash_or_number" => formatted_block_hash_or_number}) do |
|
|
|
with {:ok, block} <- |
|
|
|
case param_block_hash_or_number_to_block(formatted_block_hash_or_number, |
|
|
|
param_block_hash_or_number_to_block(formatted_block_hash_or_number, |
|
|
|
necessity_by_association: %{ |
|
|
|
necessity_by_association: %{ |
|
|
|
[miner: :names] => :required, |
|
|
|
[miner: :names] => :required, |
|
|
|
:uncles => :optional, |
|
|
|
:uncles => :optional, |
|
|
|
:nephews => :optional, |
|
|
|
:nephews => :optional, |
|
|
|
:rewards => :optional |
|
|
|
:rewards => :optional |
|
|
|
} |
|
|
|
} |
|
|
|
) do |
|
|
|
) do |
|
|
|
{:ok, block} -> |
|
|
|
block_transaction_count = Chain.block_to_transaction_count(block.hash) |
|
|
|
block_transaction_count = Chain.block_to_transaction_count(block.hash) |
|
|
|
|
|
|
|
|
|
|
|
render( |
|
|
|
render( |
|
|
|
conn, |
|
|
|
conn, |
|
|
|
"index.html", |
|
|
|
"index.html", |
|
|
|
block: block, |
|
|
|
block: block, |
|
|
|
block_transaction_count: block_transaction_count, |
|
|
|
block_transaction_count: block_transaction_count, |
|
|
|
current_path: current_path(conn) |
|
|
|
current_path: current_path(conn) |
|
|
|
) |
|
|
|
) |
|
|
|
else |
|
|
|
|
|
|
|
{:error, {:invalid, :hash}} -> |
|
|
|
{:error, {:invalid, :hash}} -> |
|
|
|
not_found(conn) |
|
|
|
not_found(conn) |
|
|
|
|
|
|
|
|
|
|
@ -117,19 +117,23 @@ defmodule BlockScoutWeb.BlockTransactionController do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp param_block_hash_or_number_to_block("0x" <> _ = param, options) do |
|
|
|
defp param_block_hash_or_number_to_block("0x" <> _ = param, options) do |
|
|
|
with {:ok, hash} <- string_to_block_hash(param) do |
|
|
|
case string_to_block_hash(param) do |
|
|
|
hash_to_block(hash, options) |
|
|
|
{:ok, hash} -> |
|
|
|
else |
|
|
|
hash_to_block(hash, options) |
|
|
|
:error -> {:error, {:invalid, :hash}} |
|
|
|
|
|
|
|
|
|
|
|
:error -> |
|
|
|
|
|
|
|
{:error, {:invalid, :hash}} |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp param_block_hash_or_number_to_block(number_string, options) |
|
|
|
defp param_block_hash_or_number_to_block(number_string, options) |
|
|
|
when is_binary(number_string) do |
|
|
|
when is_binary(number_string) do |
|
|
|
with {:ok, number} <- BlockScoutWeb.Chain.param_to_block_number(number_string) do |
|
|
|
case BlockScoutWeb.Chain.param_to_block_number(number_string) do |
|
|
|
number_to_block(number, options) |
|
|
|
{:ok, number} -> |
|
|
|
else |
|
|
|
number_to_block(number, options) |
|
|
|
{:error, :invalid} -> {:error, {:invalid, :number}} |
|
|
|
|
|
|
|
|
|
|
|
{:error, :invalid} -> |
|
|
|
|
|
|
|
{:error, {:invalid, :number}} |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|