Blockchain explorer for Ethereum based network and a tool for inspecting and analyzing EVM based blockchains.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
blockscout/lib/explorer_web/controllers/transaction_controller.ex

52 lines
1.8 KiB

defmodule ExplorerWeb.TransactionController do
use ExplorerWeb, :controller
import Ecto.Query
alias Explorer.Repo.NewRelic, as: Repo
alias Explorer.Transaction
alias Explorer.TransactionForm
def index(conn, params) do
query = from transaction in Transaction,
inner_join: receipt in assoc(transaction, :receipt),
inner_join: block in assoc(transaction, :block),
inner_join: to_address in assoc(transaction, :to_address),
inner_join: from_address in assoc(transaction, :from_address),
preload: [
block: block, receipt: receipt,
to_address: to_address, from_address: from_address],
order_by: [desc: block.timestamp]
total_query = from transaction in Transaction,
select: fragment("count(?)", transaction.id),
inner_join: receipt in assoc(transaction, :receipt),
inner_join: block in assoc(transaction, :block)
transactions = Repo.paginate(
query,
params
|> Map.put(:total_entries, Repo.one(total_query))
|> Map.put(:page_size, 25)
)
render(conn, "index.html", transactions: transactions)
end
def show(conn, params) do
hash = String.downcase(params["id"])
query = from transaction in Transaction,
left_join: receipt in assoc(transaction, :receipt),
left_join: block in assoc(transaction, :block),
inner_join: to_address in assoc(transaction, :to_address),
inner_join: from_address in assoc(transaction, :from_address),
preload: [
block: block, receipt: receipt,
to_address: to_address, from_address: from_address],
where: fragment("lower(?)", transaction.hash) == ^hash,
limit: 1
transaction = query |> Repo.one() |> TransactionForm.build()
render(conn, "show.html", transaction: transaction)
end
end