|
|
@ -3,11 +3,12 @@ defmodule BlockScoutWeb.TransactionTokenTransferController do |
|
|
|
|
|
|
|
|
|
|
|
import BlockScoutWeb.Chain, only: [paging_options: 1, next_page_params: 3, split_list_by_page: 1] |
|
|
|
import BlockScoutWeb.Chain, only: [paging_options: 1, next_page_params: 3, split_list_by_page: 1] |
|
|
|
|
|
|
|
|
|
|
|
alias BlockScoutWeb.TransactionView |
|
|
|
alias BlockScoutWeb.{TransactionTokenTransferView, TransactionView} |
|
|
|
alias Explorer.{Chain, Market} |
|
|
|
alias Explorer.{Chain, Market} |
|
|
|
alias Explorer.ExchangeRates.Token |
|
|
|
alias Explorer.ExchangeRates.Token |
|
|
|
|
|
|
|
alias Phoenix.View |
|
|
|
|
|
|
|
|
|
|
|
def index(conn, %{"transaction_id" => hash_string} = 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( |
|
|
@ -37,13 +38,68 @@ defmodule BlockScoutWeb.TransactionTokenTransferController do |
|
|
|
|
|
|
|
|
|
|
|
{token_transfers, next_page} = split_list_by_page(token_transfers_plus_one) |
|
|
|
{token_transfers, next_page} = split_list_by_page(token_transfers_plus_one) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
next_page_url = |
|
|
|
|
|
|
|
case next_page_params(next_page, token_transfers, params) do |
|
|
|
|
|
|
|
nil -> |
|
|
|
|
|
|
|
nil |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
next_page_params -> |
|
|
|
|
|
|
|
transaction_token_transfer_path(conn, :index, transaction, Map.delete(next_page_params, "type")) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
items = |
|
|
|
|
|
|
|
token_transfers |
|
|
|
|
|
|
|
|> Enum.map(fn transfer -> |
|
|
|
|
|
|
|
View.render_to_string( |
|
|
|
|
|
|
|
TransactionTokenTransferView, |
|
|
|
|
|
|
|
"_token_transfer.html", |
|
|
|
|
|
|
|
token_transfer: transfer, |
|
|
|
|
|
|
|
conn: conn |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
end) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
json( |
|
|
|
|
|
|
|
conn, |
|
|
|
|
|
|
|
%{ |
|
|
|
|
|
|
|
items: items, |
|
|
|
|
|
|
|
next_page_path: next_page_url |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
:error -> |
|
|
|
|
|
|
|
conn |
|
|
|
|
|
|
|
|> put_status(422) |
|
|
|
|
|
|
|
|> put_view(TransactionView) |
|
|
|
|
|
|
|
|> render("invalid.html", transaction_hash: hash_string) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{:error, :not_found} -> |
|
|
|
|
|
|
|
conn |
|
|
|
|
|
|
|
|> put_status(404) |
|
|
|
|
|
|
|
|> put_view(TransactionView) |
|
|
|
|
|
|
|
|> render("not_found.html", transaction_hash: hash_string) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def index(conn, %{"transaction_id" => hash_string}) do |
|
|
|
|
|
|
|
with {:ok, hash} <- Chain.string_to_transaction_hash(hash_string), |
|
|
|
|
|
|
|
{:ok, transaction} <- |
|
|
|
|
|
|
|
Chain.hash_to_transaction( |
|
|
|
|
|
|
|
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 |
|
|
|
render( |
|
|
|
render( |
|
|
|
conn, |
|
|
|
conn, |
|
|
|
"index.html", |
|
|
|
"index.html", |
|
|
|
exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(), |
|
|
|
exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(), |
|
|
|
block_height: Chain.block_height(), |
|
|
|
block_height: Chain.block_height(), |
|
|
|
next_page_params: next_page_params(next_page, token_transfers, params), |
|
|
|
current_path: current_path(conn), |
|
|
|
token_transfers: token_transfers, |
|
|
|
|
|
|
|
show_token_transfers: true, |
|
|
|
show_token_transfers: true, |
|
|
|
transaction: transaction |
|
|
|
transaction: transaction |
|
|
|
) |
|
|
|
) |
|
|
|