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

25 lines
503 B

defmodule Explorer.BlockForm do
import Ecto.Query
alias Explorer.Transaction
alias Explorer.Repo
@moduledoc false
def build(block) do
block |> Map.merge(%{
transactions_count: block |> get_transactions_count,
age: block |> calculate_age,
})
end
def get_transactions_count(block) do
Transaction
|> where([t], t.block_id == ^block.id)
|> Repo.all
|> Enum.count
end
def calculate_age(block) do
block.timestamp |> Timex.from_now
end
end