|
|
@ -1,9 +1,12 @@ |
|
|
|
defmodule ExplorerWeb.TransactionLogController do |
|
|
|
defmodule ExplorerWeb.TransactionLogController do |
|
|
|
use ExplorerWeb, :controller |
|
|
|
use ExplorerWeb, :controller |
|
|
|
|
|
|
|
|
|
|
|
alias Explorer.{Chain, Market} |
|
|
|
alias Explorer.{Chain, Market, PagingOptions} |
|
|
|
alias Explorer.ExchangeRates.Token |
|
|
|
alias Explorer.ExchangeRates.Token |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@page_size 50 |
|
|
|
|
|
|
|
@default_paging_options %PagingOptions{page_size: @page_size + 1} |
|
|
|
|
|
|
|
|
|
|
|
def index(conn, %{"transaction_id" => transaction_hash_string} = params) do |
|
|
|
def index(conn, %{"transaction_id" => transaction_hash_string} = params) do |
|
|
|
with {:ok, transaction_hash} <- Chain.string_to_transaction_hash(transaction_hash_string), |
|
|
|
with {:ok, transaction_hash} <- Chain.string_to_transaction_hash(transaction_hash_string), |
|
|
|
{:ok, transaction} <- |
|
|
|
{:ok, transaction} <- |
|
|
@ -15,18 +18,26 @@ defmodule ExplorerWeb.TransactionLogController do |
|
|
|
to_address: :required |
|
|
|
to_address: :required |
|
|
|
} |
|
|
|
} |
|
|
|
) do |
|
|
|
) do |
|
|
|
logs = |
|
|
|
full_options = |
|
|
|
Chain.transaction_to_logs( |
|
|
|
Keyword.merge( |
|
|
|
transaction, |
|
|
|
[ |
|
|
|
necessity_by_association: %{address: :optional}, |
|
|
|
necessity_by_association: %{ |
|
|
|
pagination: params |
|
|
|
address: :optional |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
paging_options(params) |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logs_plus_one = Chain.transaction_to_logs(transaction, full_options) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{logs, next_page} = Enum.split(logs_plus_one, @page_size) |
|
|
|
|
|
|
|
|
|
|
|
render( |
|
|
|
render( |
|
|
|
conn, |
|
|
|
conn, |
|
|
|
"index.html", |
|
|
|
"index.html", |
|
|
|
logs: logs, |
|
|
|
logs: logs, |
|
|
|
max_block_number: max_block_number(), |
|
|
|
max_block_number: max_block_number(), |
|
|
|
|
|
|
|
next_page_params: next_page_params(next_page, logs), |
|
|
|
transaction: transaction, |
|
|
|
transaction: transaction, |
|
|
|
exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null() |
|
|
|
exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null() |
|
|
|
) |
|
|
|
) |
|
|
@ -45,4 +56,21 @@ defmodule ExplorerWeb.TransactionLogController do |
|
|
|
{:error, :not_found} -> 0 |
|
|
|
{:error, :not_found} -> 0 |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defp next_page_params([], _logs), do: nil |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defp next_page_params(_, logs) do |
|
|
|
|
|
|
|
last = List.last(logs) |
|
|
|
|
|
|
|
%{index: last.index} |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defp paging_options(params) do |
|
|
|
|
|
|
|
with %{"index" => index_string} <- params, |
|
|
|
|
|
|
|
{index, ""} <- Integer.parse(index_string) do |
|
|
|
|
|
|
|
[paging_options: %{@default_paging_options | key: {index}}] |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
_ -> |
|
|
|
|
|
|
|
[paging_options: @default_paging_options] |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|