add pagination

pull/1727/head
Ayrat Badykov 6 years ago
parent f5216038aa
commit 1e11630777
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 16
      apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/transaction_controller.ex

@ -1,14 +1,24 @@
defmodule BlockScoutWeb.API.RPC.TransactionController do
use BlockScoutWeb, :controller
import BlockScoutWeb.Chain, only: [paging_options: 1, next_page_params: 3, split_list_by_page: 1]
alias Explorer.Chain
def gettxinfo(conn, params) do
with {:txhash_param, {:ok, txhash_param}} <- fetch_txhash(params),
{:format, {:ok, transaction_hash}} <- to_transaction_hash(txhash_param),
{:transaction, {:ok, transaction}} <- transaction_from_hash(transaction_hash) do
logs = Chain.transaction_to_logs(transaction)
render(conn, :gettxinfo, %{transaction: transaction, block_height: Chain.block_height(), logs: logs})
{:transaction, {:ok, transaction}} <- transaction_from_hash(transaction_hash),
paging_options <- paging_options(params) do
logs = Chain.transaction_to_logs(transaction, paging_options: paging_options)
{logs, next_page} = split_list_by_page(logs)
render(conn, :gettxinfo, %{
transaction: transaction,
block_height: Chain.block_height(),
logs: logs,
next_page_params: next_page_params(next_page, logs, params)
})
else
{:transaction, :error} ->
render(conn, :error, error: "Transaction not found")

Loading…
Cancel
Save