Skip to content

Commit

Permalink
feat: add udt model
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojunda committed Feb 26, 2020
1 parent 9bede41 commit 74fbcf7
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 1 deletion.
31 changes: 31 additions & 0 deletions app/models/udt.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class Udt < ApplicationRecord
enum udt_type: { sudt: 0 }

validates_presence_of :full_name, :symbol, :decimal, :total_amount
validates_length_of :symbol, minimum: 1, maximum: 16
validates_length_of :full_name, minimum: 1, maximum: 32
validates :decimal, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 39 }
validates :total_amount, numericality: { greater_than_or_equal_to: 0 }
end

# == Schema Information
#
# Table name: udts
#
# id :bigint not null, primary key
# code_hash :binary
# hash_type :string
# args :string
# full_name :string
# symbol :string
# decimal :integer
# description :string
# icon_file :string
# operator_website :string
# addresses_count :decimal(30, )
# total_amount :decimal(40, )
# udt_type :integer
# published :boolean default(FALSE)
# created_at :datetime not null
# updated_at :datetime not null
#
1 change: 1 addition & 0 deletions app/models/udt_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class UdtAccount < ApplicationRecord
# symbol :string
# decimal :integer
# amount :decimal(40, )
# published :boolean default(FALSE)
# address_id :bigint
# created_at :datetime not null
# updated_at :datetime not null
Expand Down
1 change: 1 addition & 0 deletions db/migrate/20200226063458_create_udt_accounts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def change
t.string :symbol
t.integer :decimal
t.decimal :amount, precision: 40
t.boolean :published, default: false
t.references :address

t.timestamps
Expand Down
21 changes: 21 additions & 0 deletions db/migrate/20200226072529_create_udts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class CreateUdts < ActiveRecord::Migration[6.0]
def change
create_table :udts do |t|
t.binary :code_hash
t.string :hash_type
t.string :args
t.string :full_name
t.string :symbol
t.integer :decimal
t.string :description
t.string :icon_file
t.string :operator_website
t.decimal :addresses_count, precision: 30
t.decimal :total_amount, precision: 40
t.integer :udt_type
t.boolean :published, default: false

t.timestamps
end
end
end
21 changes: 20 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_02_26_063458) do
ActiveRecord::Schema.define(version: 2020_02_26_072529) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -306,12 +306,31 @@
t.string "symbol"
t.integer "decimal"
t.decimal "amount", precision: 40
t.boolean "published", default: false
t.bigint "address_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["address_id"], name: "index_udt_accounts_on_address_id"
end

create_table "udts", force: :cascade do |t|
t.binary "code_hash"
t.string "hash_type"
t.string "args"
t.string "full_name"
t.string "symbol"
t.integer "decimal"
t.string "description"
t.string "icon_file"
t.string "operator_website"
t.decimal "addresses_count", precision: 30
t.decimal "total_amount", precision: 40
t.integer "udt_type"
t.boolean "published", default: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table "uncle_blocks", force: :cascade do |t|
t.binary "block_hash"
t.decimal "number", precision: 30
Expand Down
7 changes: 7 additions & 0 deletions test/models/udt_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class UdtTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit 74fbcf7

Please sign in to comment.