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

41 lines
1.0 KiB

defmodule Explorer.Receipt do
@moduledoc "Captures a Web3 Transaction Receipt."
use Ecto.Schema
import Ecto.Changeset
alias Explorer.Transaction
alias Explorer.Log
alias Explorer.Receipt
@timestamps_opts [type: Timex.Ecto.DateTime,
autogenerate: {Timex.Ecto.DateTime, :autogenerate, []}]
@required_attrs ~w(cumulative_gas_used gas_used status index)a
@optional_attrs ~w(transaction_id)a
schema "receipts" do
belongs_to :transaction, Transaction
has_many :logs, Log
field :cumulative_gas_used, :decimal
field :gas_used, :decimal
field :status, :integer
field :index, :integer
timestamps()
end
def changeset(%Receipt{} = transaction_receipt, attrs \\ %{}) do
transaction_receipt
|> cast(attrs, @required_attrs)
|> cast(attrs, @optional_attrs)
|> cast_assoc(:transaction)
|> cast_assoc(:logs)
|> validate_required(@required_attrs)
|> foreign_key_constraint(:transaction_id)
|> unique_constraint(:transaction_id)
end
def null, do: %Receipt{}
end