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/forms/block_form.ex

38 lines
878 B

defmodule Explorer.BlockForm do
@moduledoc false
alias Explorer.Block
alias Explorer.BlockTransaction
alias Explorer.Repo
import Ecto.Query
def build(block) do
block
|> Map.merge(%{
transactions_count: block |> get_transactions_count,
age: block |> calculate_age,
formatted_timestamp: block |> format_timestamp
})
end
def get_transactions_count(block) do
query =
from(
block_transaction in BlockTransaction,
join: block in Block,
where: block.id == block_transaction.block_id,
where: block.id == ^block.id,
select: count(block_transaction.block_id)
)
Repo.one(query)
end
def calculate_age(block) do
block.timestamp |> Timex.from_now()
end
def format_timestamp(block) do
block.timestamp |> Timex.format!("%b-%d-%Y %H:%M:%S %p %Z", :strftime)
end
end