Skip to content

Commit

Permalink
Merge pull request #10 from cryptape/develop
Browse files Browse the repository at this point in the history
proposals get validators from MetaData
  • Loading branch information
classicalliu authored Aug 16, 2018
2 parents 251a76c + 339b821 commit 0686cc0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
5 changes: 1 addition & 4 deletions app/controllers/api/statistics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ def index
# }
# ]
def proposals
blocks = Block.select("header->>'proposer' as proposer")
proposers = blocks.distinct("proposers").map(&:proposer)

result = proposers.map do |proposer|
result = MetaData.last&.validators&.map do |proposer|
count = Block.where("header->>'proposer' = ?", proposer).count
{
"validator": proposer,
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20180816073015_add_index_to_blocks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddIndexToBlocks < ActiveRecord::Migration[5.2]
def change
add_index :blocks, :header, using: :gin
add_index :blocks, :body, using: :gin
end
end
4 changes: 3 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: 2018_08_07_073702) do
ActiveRecord::Schema.define(version: 2018_08_16_073015) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -41,7 +41,9 @@
t.datetime "updated_at", null: false
t.integer "transaction_count"
t.index ["block_number"], name: "index_blocks_on_block_number", unique: true
t.index ["body"], name: "index_blocks_on_body", using: :gin
t.index ["cita_hash"], name: "index_blocks_on_cita_hash", unique: true
t.index ["header"], name: "index_blocks_on_header", using: :gin
end

create_table "meta_data", force: :cascade do |t|
Expand Down
2 changes: 2 additions & 0 deletions spec/controllers/api/statistics_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
10.times.each do |i|
create :block_one, header: block_one_header.merge(timestamp: block_zero_header[:timestamp] + (20 + i) * 1000), cita_hash: "0x#{SecureRandom.hex(32)}", block_number: (20 + i)
end

create :meta_data, validators: [block_zero_proposer, block_one_proposer], block: Block.last
end


Expand Down

0 comments on commit 0686cc0

Please sign in to comment.