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/block.ex

41 lines
1.1 KiB

defmodule Explorer.Block do
@moduledoc false
use Ecto.Schema
import Ecto.Changeset
alias Explorer.Block
@timestamps_opts [type: Timex.Ecto.DateTime,
autogenerate: {Timex.Ecto.DateTime, :autogenerate, []}]
schema "blocks" do
field :number, :integer
field :hash, :string
field :parent_hash, :string
field :nonce, :string
field :miner, :string
field :difficulty, :decimal
field :total_difficulty, :decimal
field :size, :integer
field :gas_limit, :integer
field :gas_used, :integer
field :timestamp, Timex.Ecto.DateTime
timestamps()
has_many :transactions, Explorer.Transaction
end
@required_attrs ~w(number hash parent_hash nonce miner difficulty
total_difficulty size gas_limit gas_used timestamp)a
@optional_attrs ~w()a
@doc false
def changeset(%Block{} = block, attrs) do
block
|> cast(attrs, @required_attrs, @optional_attrs)
|> validate_required(@required_attrs)
|> update_change(:hash, &String.downcase/1)
|> unique_constraint(:hash)
end
end