|
|
@ -8,8 +8,10 @@ defmodule BlockScoutWeb.AddressTransactionController do |
|
|
|
import BlockScoutWeb.AddressController, only: [transaction_count: 1, validation_count: 1] |
|
|
|
import BlockScoutWeb.AddressController, only: [transaction_count: 1, validation_count: 1] |
|
|
|
import BlockScoutWeb.Chain, only: [current_filter: 1, paging_options: 1, next_page_params: 3, split_list_by_page: 1] |
|
|
|
import BlockScoutWeb.Chain, only: [current_filter: 1, paging_options: 1, next_page_params: 3, split_list_by_page: 1] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
alias BlockScoutWeb.TransactionView |
|
|
|
alias Explorer.{Chain, Market} |
|
|
|
alias Explorer.{Chain, Market} |
|
|
|
alias Explorer.ExchangeRates.Token |
|
|
|
alias Explorer.ExchangeRates.Token |
|
|
|
|
|
|
|
alias Phoenix.View |
|
|
|
|
|
|
|
|
|
|
|
@transaction_necessity_by_association [ |
|
|
|
@transaction_necessity_by_association [ |
|
|
|
necessity_by_association: %{ |
|
|
|
necessity_by_association: %{ |
|
|
@ -23,7 +25,7 @@ defmodule BlockScoutWeb.AddressTransactionController do |
|
|
|
} |
|
|
|
} |
|
|
|
] |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
def index(conn, %{"address_id" => address_hash_string} = params) do |
|
|
|
def index(conn, %{"address_id" => address_hash_string, "type" => "JSON"} = params) do |
|
|
|
with {:ok, address_hash} <- Chain.string_to_address_hash(address_hash_string), |
|
|
|
with {:ok, address_hash} <- Chain.string_to_address_hash(address_hash_string), |
|
|
|
{:ok, address} <- Chain.hash_to_address(address_hash) do |
|
|
|
{:ok, address} <- Chain.hash_to_address(address_hash) do |
|
|
|
options = |
|
|
|
options = |
|
|
@ -35,6 +37,43 @@ defmodule BlockScoutWeb.AddressTransactionController do |
|
|
|
transactions_plus_one = Chain.address_to_transactions(address, options) |
|
|
|
transactions_plus_one = Chain.address_to_transactions(address, options) |
|
|
|
{transactions, next_page} = split_list_by_page(transactions_plus_one) |
|
|
|
{transactions, next_page} = split_list_by_page(transactions_plus_one) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
next_page_url = |
|
|
|
|
|
|
|
case next_page_params(next_page, transactions, params) do |
|
|
|
|
|
|
|
nil -> |
|
|
|
|
|
|
|
nil |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
next_page_params -> |
|
|
|
|
|
|
|
address_transaction_path( |
|
|
|
|
|
|
|
conn, |
|
|
|
|
|
|
|
:index, |
|
|
|
|
|
|
|
address, |
|
|
|
|
|
|
|
Map.delete(next_page_params, "type") |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
transactions_json = |
|
|
|
|
|
|
|
Enum.map(transactions, fn transaction -> |
|
|
|
|
|
|
|
View.render_to_string( |
|
|
|
|
|
|
|
TransactionView, |
|
|
|
|
|
|
|
"_tile.html", |
|
|
|
|
|
|
|
current_address: address, |
|
|
|
|
|
|
|
transaction: transaction |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
end) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
json(conn, %{items: transactions_json, next_page_path: next_page_url}) |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
:error -> |
|
|
|
|
|
|
|
unprocessable_entity(conn) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{:error, :not_found} -> |
|
|
|
|
|
|
|
not_found(conn) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
render( |
|
|
|
render( |
|
|
|
conn, |
|
|
|
conn, |
|
|
|
"index.html", |
|
|
|
"index.html", |
|
|
@ -43,8 +82,7 @@ defmodule BlockScoutWeb.AddressTransactionController do |
|
|
|
filter: params["filter"], |
|
|
|
filter: params["filter"], |
|
|
|
transaction_count: transaction_count(address), |
|
|
|
transaction_count: transaction_count(address), |
|
|
|
validation_count: validation_count(address), |
|
|
|
validation_count: validation_count(address), |
|
|
|
transactions: transactions, |
|
|
|
current_path: current_path(conn) |
|
|
|
next_page_params: next_page_params(next_page, transactions, params) |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
else |
|
|
|
else |
|
|
|
:error -> |
|
|
|
:error -> |
|
|
|