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/services/transaction.ex

34 lines
1007 B

defmodule Explorer.Transaction.Service do
@moduledoc "Service module for interacting with Transactions"
alias Explorer.InternalTransaction
alias Explorer.Repo.NewRelic, as: Repo
alias Explorer.Transaction.Service.Query
def internal_transactions(hash) do
InternalTransaction
|> Query.for_transaction(hash)
|> Query.join_from_and_to_addresses()
|> Repo.all()
end
defmodule Query do
@moduledoc "Helper module to hold Transaction-related query fragments"
import Ecto.Query, only: [from: 2]
def for_transaction(query, hash) do
from(child in query,
inner_join: transaction in assoc(child, :transaction),
where: fragment("lower(?)", transaction.hash) == ^String.downcase(hash)
)
end
def join_from_and_to_addresses(query) do
from(q in query,
inner_join: to_address in assoc(q, :to_address),
inner_join: from_address in assoc(q, :from_address),
preload: [:to_address, :from_address])
end
end
end