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

45 lines
1.2 KiB

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
field :gas, :decimal
field :gas_price, :decimal
field :input, :string
field :nonce, :integer
field :public_key, :string
field :r, :string
field :s, :string
field :standard_v, :string
field :transaction_index, :string
field :v, :string
timestamps()
belongs_to :block, Explorer.Block
many_to_many :to_address, Explorer.Address, join_through: "to_addresses", unique: true
end
@required_attrs ~w(hash value gas gas_price input nonce public_key r s
standard_v transaction_index v)a
@optional_attrs ~w()a
@doc false
7 years ago
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