|
|
@ -11,8 +11,8 @@ 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( |
|
|
|
[ |
|
|
|
[ |
|
|
@ -61,7 +61,7 @@ defmodule BlockScoutWeb.BlockTransactionController do |
|
|
|
next_page_path: next_page_path |
|
|
|
next_page_path: next_page_path |
|
|
|
} |
|
|
|
} |
|
|
|
) |
|
|
|
) |
|
|
|
else |
|
|
|
|
|
|
|
{:error, {:invalid, :hash}} -> |
|
|
|
{:error, {:invalid, :hash}} -> |
|
|
|
not_found(conn) |
|
|
|
not_found(conn) |
|
|
|
|
|
|
|
|
|
|
@ -80,8 +80,7 @@ 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, |
|
|
@ -89,6 +88,7 @@ defmodule BlockScoutWeb.BlockTransactionController do |
|
|
|
: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( |
|
|
@ -98,7 +98,7 @@ defmodule BlockScoutWeb.BlockTransactionController do |
|
|
|
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 |
|
|
|
|
|
|
|
{:ok, hash} -> |
|
|
|
hash_to_block(hash, options) |
|
|
|
hash_to_block(hash, options) |
|
|
|
else |
|
|
|
|
|
|
|
: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 |
|
|
|
|
|
|
|
{:ok, number} -> |
|
|
|
number_to_block(number, options) |
|
|
|
number_to_block(number, options) |
|
|
|
else |
|
|
|
|
|
|
|
{:error, :invalid} -> {:error, {:invalid, :number}} |
|
|
|
{:error, :invalid} -> |
|
|
|
|
|
|
|
{:error, {:invalid, :number}} |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|