De-duplicate Schema configuration and consolidate files.

pull/42/head
CJ Bryan and Desmond Bowe 7 years ago
parent 2977740e3d
commit e12b13bc5b
  1. 10
      lib/explorer/schemas/address.ex
  2. 10
      lib/explorer/schemas/block.ex
  3. 10
      lib/explorer/schemas/block_transaction.ex
  4. 0
      lib/explorer/schemas/chain.ex
  5. 7
      lib/explorer/schemas/credit.ex
  6. 7
      lib/explorer/schemas/debit.ex
  7. 10
      lib/explorer/schemas/from_address.ex
  8. 9
      lib/explorer/schemas/internal_transaction.ex
  9. 9
      lib/explorer/schemas/log.ex
  10. 9
      lib/explorer/schemas/receipt.ex
  11. 15
      lib/explorer/schemas/schema.ex
  12. 7
      lib/explorer/schemas/to_address.ex
  13. 9
      lib/explorer/schemas/transaction.ex

@ -3,21 +3,13 @@ defmodule Explorer.Address do
A stored representation of a web3 address.
"""
use Ecto.Schema
import Ecto.Changeset
import Ecto.Query
use Explorer.Schema
alias Explorer.Address
alias Explorer.Credit
alias Explorer.Debit
alias Explorer.Repo.NewRelic, as: Repo
@timestamps_opts [
type: Timex.Ecto.DateTime,
autogenerate: {Timex.Ecto.DateTime, :autogenerate, []}
]
schema "addresses" do
has_one(:credit, Credit)
has_one(:debit, Debit)

@ -3,20 +3,12 @@ defmodule Explorer.Block do
Stores a web3 block.
"""
use Ecto.Schema
import Ecto.Changeset
import Ecto.Query
use Explorer.Schema
alias Explorer.Block
alias Explorer.BlockTransaction
alias Explorer.Transaction
@timestamps_opts [
type: Timex.Ecto.DateTime,
autogenerate: {Timex.Ecto.DateTime, :autogenerate, []}
]
schema "blocks" do
has_many(:block_transactions, BlockTransaction)
many_to_many(:transactions, Transaction, join_through: "block_transactions")

@ -1,13 +1,9 @@
defmodule Explorer.BlockTransaction do
@moduledoc false
@moduledoc "Connects a Block to a Transaction"
alias Explorer.BlockTransaction
import Ecto.Changeset
use Ecto.Schema
@timestamps_opts [
type: Timex.Ecto.DateTime,
autogenerate: {Timex.Ecto.DateTime, :autogenerate, []}
]
use Explorer.Schema
@primary_key false
schema "block_transactions" do

@ -3,17 +3,12 @@ defmodule Explorer.Credit do
A materialized view representing the credits to an address.
"""
use Ecto.Schema
use Explorer.Schema
alias Ecto.Adapters.SQL
alias Explorer.Address
alias Explorer.Repo
@timestamps_opts [
type: Timex.Ecto.DateTime,
autogenerate: {Timex.Ecto.DateTime, :autogenerate, []}
]
@primary_key false
schema "credits" do
belongs_to(:address, Address, primary_key: true)

@ -3,17 +3,12 @@ defmodule Explorer.Debit do
A materialized view representing the debits from an address.
"""
use Ecto.Schema
use Explorer.Schema
alias Ecto.Adapters.SQL
alias Explorer.Address
alias Explorer.Repo
@timestamps_opts [
type: Timex.Ecto.DateTime,
autogenerate: {Timex.Ecto.DateTime, :autogenerate, []}
]
@primary_key false
schema "debits" do
belongs_to(:address, Address, primary_key: true)

@ -1,13 +1,9 @@
defmodule Explorer.FromAddress do
@moduledoc false
alias Explorer.FromAddress
import Ecto.Changeset
use Ecto.Schema
@timestamps_opts [
type: Timex.Ecto.DateTime,
autogenerate: {Timex.Ecto.DateTime, :autogenerate, []}
]
use Explorer.Schema
alias Explorer.FromAddress
@primary_key false
schema "from_addresses" do

@ -1,19 +1,12 @@
defmodule Explorer.InternalTransaction do
@moduledoc "Models internal transactions."
use Ecto.Schema
import Ecto.Changeset
use Explorer.Schema
alias Explorer.InternalTransaction
alias Explorer.Transaction
alias Explorer.Address
@timestamps_opts [
type: Timex.Ecto.DateTime,
autogenerate: {Timex.Ecto.DateTime, :autogenerate, []}
]
schema "internal_transactions" do
belongs_to(:transaction, Transaction)
belongs_to(:from_address, Address)

@ -1,19 +1,12 @@
defmodule Explorer.Log do
@moduledoc "Captures a Web3 log entry generated by a transaction"
use Ecto.Schema
import Ecto.Changeset
use Explorer.Schema
alias Explorer.Address
alias Explorer.Log
alias Explorer.Receipt
@timestamps_opts [
type: Timex.Ecto.DateTime,
autogenerate: {Timex.Ecto.DateTime, :autogenerate, []}
]
@required_attrs ~w(index data type)a
@optional_attrs ~w(
first_topic second_topic third_topic fourth_topic address_id

@ -1,19 +1,12 @@
defmodule Explorer.Receipt do
@moduledoc "Captures a Web3 Transaction Receipt."
use Ecto.Schema
import Ecto.Changeset
use Explorer.Schema
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

@ -0,0 +1,15 @@
defmodule Explorer.Schema do
defmacro __using__(_opts) do
quote do
use Ecto.Schema
import Ecto.Changeset
import Ecto.Query
@timestamps_opts [
type: Timex.Ecto.DateTime,
autogenerate: {Timex.Ecto.DateTime, :autogenerate, []}
]
end
end
end

@ -1,13 +1,8 @@
defmodule Explorer.ToAddress do
@moduledoc false
alias Explorer.ToAddress
import Ecto.Changeset
use Ecto.Schema
@timestamps_opts [
type: Timex.Ecto.DateTime,
autogenerate: {Timex.Ecto.DateTime, :autogenerate, []}
]
use Explorer.Schema
@primary_key false
schema "to_addresses" do

@ -1,9 +1,7 @@
defmodule Explorer.Transaction do
@moduledoc "Models a Web3 transaction."
use Ecto.Schema
import Ecto.Changeset
use Explorer.Schema
alias Explorer.Address
alias Explorer.BlockTransaction
@ -11,11 +9,6 @@ defmodule Explorer.Transaction do
alias Explorer.Receipt
alias Explorer.Transaction
@timestamps_opts [
type: Timex.Ecto.DateTime,
autogenerate: {Timex.Ecto.DateTime, :autogenerate, []}
]
schema "transactions" do
has_one(:receipt, Receipt)
has_one(:block_transaction, BlockTransaction)
Loading…
Cancel
Save