|
|
|
@ -13,43 +13,18 @@ defmodule ExplorerWeb.AddressInternalTransactionController do |
|
|
|
|
@page_size 50 |
|
|
|
|
@default_paging_options %PagingOptions{page_size: @page_size + 1} |
|
|
|
|
|
|
|
|
|
def index( |
|
|
|
|
conn, |
|
|
|
|
%{ |
|
|
|
|
"block_number" => block_number_string, |
|
|
|
|
"transaction_index" => transaction_index_string, |
|
|
|
|
"index" => index_string |
|
|
|
|
} = params |
|
|
|
|
) do |
|
|
|
|
with {block_number, ""} <- Integer.parse(block_number_string), |
|
|
|
|
{transaction_index, ""} <- Integer.parse(transaction_index_string), |
|
|
|
|
{index, ""} <- Integer.parse(index_string) do |
|
|
|
|
do_index( |
|
|
|
|
conn, |
|
|
|
|
Map.put(params, :paging_options, %{@default_paging_options | key: {block_number, transaction_index, index}}) |
|
|
|
|
) |
|
|
|
|
else |
|
|
|
|
_ -> |
|
|
|
|
unprocessable_entity(conn) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def index(conn, params), do: do_index(conn, params) |
|
|
|
|
|
|
|
|
|
def do_index(conn, %{"address_id" => address_hash_string} = params) do |
|
|
|
|
def index(conn, %{"address_id" => address_hash_string} = params) do |
|
|
|
|
with {:ok, address_hash} <- Chain.string_to_address_hash(address_hash_string), |
|
|
|
|
{:ok, address} <- Chain.hash_to_address(address_hash) do |
|
|
|
|
full_options = |
|
|
|
|
Keyword.merge( |
|
|
|
|
[ |
|
|
|
|
necessity_by_association: %{ |
|
|
|
|
from_address: :optional, |
|
|
|
|
to_address: :optional |
|
|
|
|
}, |
|
|
|
|
paging_options: @default_paging_options |
|
|
|
|
], |
|
|
|
|
current_filter(params) |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
|> Keyword.merge(paging_options(params)) |
|
|
|
|
|> Keyword.merge(current_filter(params)) |
|
|
|
|
|
|
|
|
|
internal_transactions_plus_one = Chain.address_to_internal_transactions(address, full_options) |
|
|
|
|
|
|
|
|
@ -101,4 +76,20 @@ defmodule ExplorerWeb.AddressInternalTransactionController do |
|
|
|
|
{:ok, last_transaction} = Chain.hash_to_transaction(last.transaction_hash) |
|
|
|
|
%{block_number: last_transaction.block_number, transaction_index: last_transaction.index, index: last.index} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp paging_options(params) do |
|
|
|
|
with %{ |
|
|
|
|
"block_number" => block_number_string, |
|
|
|
|
"transaction_index" => transaction_index_string, |
|
|
|
|
"index" => index_string |
|
|
|
|
} <- params, |
|
|
|
|
{block_number, ""} <- Integer.parse(block_number_string), |
|
|
|
|
{transaction_index, ""} <- Integer.parse(transaction_index_string), |
|
|
|
|
{index, ""} <- Integer.parse(index_string) do |
|
|
|
|
[paging_options: %{@default_paging_options | key: {block_number, transaction_index, index}}] |
|
|
|
|
else |
|
|
|
|
_ -> |
|
|
|
|
[paging_options: @default_paging_options] |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|