Skip to content

Commit

Permalink
feat: add udt account model
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojunda committed Feb 26, 2020
1 parent 57dad85 commit 2b5c1f0
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 1 deletion.
29 changes: 29 additions & 0 deletions app/models/udt_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class UdtAccount < ApplicationRecord
enum udt_type: { sudt: 0 }

belongs_to :address

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

# == Schema Information
#
# Table name: udt_accounts
#
# id :bigint not null, primary key
# udt_type :integer
# full_name :string
# symbol :string
# decimal :integer
# amount :decimal(40, )
# address_id :bigint
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_udt_accounts_on_address_id (address_id)
#
14 changes: 14 additions & 0 deletions db/migrate/20200226063458_create_udt_accounts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateUdtAccounts < ActiveRecord::Migration[6.0]
def change
create_table :udt_accounts do |t|
t.integer :udt_type
t.string :full_name
t.string :symbol
t.integer :decimal
t.decimal :amount, precision: 40
t.references :address

t.timestamps
end
end
end
14 changes: 13 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_01_22_060907) do
ActiveRecord::Schema.define(version: 2020_02_26_063458) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -300,6 +300,18 @@
t.index ["cell_output_id"], name: "index_type_scripts_on_cell_output_id"
end

create_table "udt_accounts", force: :cascade do |t|
t.integer "udt_type"
t.string "full_name"
t.string "symbol"
t.integer "decimal"
t.decimal "amount", precision: 40
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 "uncle_blocks", force: :cascade do |t|
t.binary "block_hash"
t.decimal "number", precision: 30
Expand Down
10 changes: 10 additions & 0 deletions test/factories/udt_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FactoryBot.define do
factory :udt_account do
address
udt_type { "sudt" }
full_name { "kingdom fat coin" }
symbol { "kfc" }
decimal { 6 }
amount { 100000000000 * 10**6 }
end
end
7 changes: 7 additions & 0 deletions test/models/udt_account_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

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

0 comments on commit 2b5c1f0

Please sign in to comment.