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

31 lines
783 B

defmodule Explorer.Transaction do
@moduledoc false
use Ecto.Schema
import Ecto.Changeset
alias Explorer.Transaction
@timestamps_opts [type: Timex.Ecto.DateTime,
autogenerate: {Timex.Ecto.DateTime, :autogenerate, []}]
schema "transactions" do
field :hash, :string
field :value, :decimal
timestamps()
belongs_to :block, Explorer.Block
end
@required_attrs ~w(hash value)a
@optional_attrs ~w()a
@doc false
def changeset(%Transaction{} = transaction, attrs \\ %{}) do
transaction
|> cast(attrs, [:block_id | @required_attrs], @optional_attrs)
|> validate_required(@required_attrs)
|> foreign_key_constraint(:block_id)
|> update_change(:hash, &String.downcase/1)
|> unique_constraint(:hash)
end
end