hive_sql 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8cc58e527a62f06dd3c1965553ce95b385170373f32f49cfd3d08dab53e9541c
4
- data.tar.gz: 953234f4a4548da4b3ab4c3d46ef7e3e49c2346fa6c3858e6618d57648a2dadb
3
+ metadata.gz: 6a69a495f4ca59bbda3187a5e67811b164d545001e45aa48559fd3c71dc7a9b5
4
+ data.tar.gz: b94bed8fdba6e7ffb967ef8fa2cb0c4c39f13d3c9ae9559456c3dd34b7dd5d7d
5
5
  SHA512:
6
- metadata.gz: 91e0adc7e812497c1ce7335eac25d8df66c72e4fe1c0c43216397d132971dbb52824c38284f9d89624a63a803c5561aa7379dd9875c365bfe95c71eababf6944
7
- data.tar.gz: 73f2d1539ffec1fe0fdb1d13dba4445a13d53d273ccbbc7d986daf1ee253f4461d354b8dfb29d1f41903158857a52da81f41c1eaab917568522e07c52a4fe390
6
+ metadata.gz: b49ed0517155beb3a03374d94587b457a1e2c8a55a80856a7e2d707410b80fd147ef1de13a5dd4f361fa092e818310f477915b2302b3ec8666abb22c9157b6fa
7
+ data.tar.gz: b60eace66ec04cbfd0502e001de0223ef6c5650775f727e0d96a9e92216ed42c61db3586a14892727fa25d58934638cb190ee271cff5adcc8ae5eb32648a03c0
data/Rakefile CHANGED
@@ -78,6 +78,46 @@ namespace :created do
78
78
  end
79
79
  end
80
80
 
81
+ namespace :deleted do
82
+ desc 'Lists comments deleted grouped by author and date.'
83
+ task :comments, [:author, :days_ago, :minimum_deletes] do |t, args|
84
+ now = Time.now.utc
85
+ author = args[:author]
86
+ after_timestamp = now - ((args[:days_ago] || '7').to_i * 86400)
87
+ minimum_deletes = (args[:minimum_deletes] || '1').to_i
88
+
89
+ delete_comments = HiveSQL::Tx::DeleteComment.all
90
+
91
+ if !!author || author == '%'
92
+ unless author == '%'
93
+ delete_comments = delete_comments.where(author: author)
94
+ end
95
+ elsif author =~ /.*%.*/
96
+ delete_comments = delete_comments.where('author LIKE ?', author)
97
+ end
98
+
99
+ delete_comments = delete_comments.where('timestamp > ?', after_timestamp)
100
+ rewards = HiveSQL::Vo::AuthorReward.where(author: delete_comments.select(:author), permlink: delete_comments.select(:permlink))
101
+ delete_comments = delete_comments.group('CAST(timestamp AS DATE)', :author)
102
+ delete_comments = delete_comments.order('cast_timestamp_as_date ASC')
103
+
104
+ delete_comments = delete_comments.count
105
+
106
+ if minimum_deletes > 1
107
+ delete_comments = delete_comments.select{|k, v| v >= minimum_deletes}
108
+ end
109
+
110
+ puts "# Daily deleted comment count by #{author.nil? ? 'all account authors' : author} since #{after_timestamp} ..."
111
+ ap delete_comments
112
+ puts "# Total deleted comments: #{delete_comments.values.sum}"
113
+
114
+ puts "# Author reward impact:"
115
+ puts "# HBD: #{rewards.sum(:hbd_payout)}"
116
+ puts "# HIVE: #{rewards.sum(:hive_payout)}"
117
+ puts "# VESTS: #{rewards.sum(:vesting_payout)}"
118
+ end
119
+ end
120
+
81
121
  desc 'Lists sum of transfers grouped by date, from, and to.'
82
122
  task :transfers, [:minimum_amount, :symbol, :days_ago] do |t, args|
83
123
  now = Time.now.utc
@@ -231,7 +271,7 @@ namespace :crosscheck do
231
271
  task :transfers, [:account] do |t, args|
232
272
  exchanges = %w(bittrex poloniex openledger blocktrades deepcrypto8 gopax
233
273
  binanceexchange teambitwala changelly hitbtc-exchange korbit roomofsatoshi
234
- shapeshiftio)
274
+ shapeshiftio huobi-withdrawal bithumbrecv2 user.dunamu hot.dunamu)
235
275
  account = args[:account]
236
276
 
237
277
  if account.nil? || account == ''
@@ -408,7 +448,14 @@ namespace :rewards do
408
448
  when 'VESTS' then rewards.sum(:vesting_payout)
409
449
  when 'MVESTS'
410
450
  rewards.sum('vesting_payout / 1000000')
411
- else; puts "Unknown symbol: #{symbol}. Symbols supported: HBD, HIVE, VESTS, MVESTS"
451
+ when 'HP'
452
+ properties = HiveSQL::DynamicGlobalProperties.first
453
+ total_vesting_fund_hive = properties.total_vesting_fund_hive.to_f
454
+ total_vesting_shares_mvest = properties.total_vesting_shares.to_f / 1e6
455
+ base_per_mvest = total_vesting_fund_hive / total_vesting_shares_mvest
456
+
457
+ rewards.sum("(vesting_payout / 1000000) * #{base_per_mvest}")
458
+ else; puts "Unknown symbol: #{symbol}. Symbols supported: HBD, HIVE, VESTS, MVESTS, HP"
412
459
  end
413
460
 
414
461
  ap rewards
@@ -440,13 +487,24 @@ namespace :rewards do
440
487
  puts "Daily curation reward #{symbol} sum grouped by date since #{after_timestamp} ..."
441
488
  end
442
489
 
443
- case symbol
490
+ rewards = case symbol
444
491
  when 'VESTS'
445
- ap rewards.sum("TRY_PARSE(REPLACE(reward, ' VESTS', '') AS float)")
492
+ rewards.sum("TRY_PARSE(REPLACE(reward, ' VESTS', '') AS float)")
446
493
  when 'MVESTS'
447
- ap rewards.sum("TRY_PARSE(REPLACE(reward, ' VESTS', '') AS float) / 1000000")
448
- else; puts "Unknown symbol: #{symbol}. Symbols supported: VESTS, MVESTS"
494
+ rewards.sum("TRY_PARSE(REPLACE(reward, ' VESTS', '') AS float) / 1000000")
495
+ when 'HP'
496
+ properties = HiveSQL::DynamicGlobalProperties.first
497
+ total_vesting_fund_hive = properties.total_vesting_fund_hive.to_f
498
+ total_vesting_shares_mvest = properties.total_vesting_shares.to_f / 1e6
499
+ base_per_mvest = total_vesting_fund_hive / total_vesting_shares_mvest
500
+
501
+ rewards.sum("(TRY_PARSE(REPLACE(reward, ' VESTS', '') AS float) / 1000000) * #{base_per_mvest}")
502
+ else; puts "Unknown symbol: #{symbol}. Symbols supported: VESTS, MVESTS, HP"
449
503
  end
504
+
505
+ ap rewards
506
+ sum = rewards.values.sum
507
+ puts "# Total rewards: %.3f %s (average: %.3f per day)" % [sum, symbol, (sum / rewards.size)]
450
508
  end
451
509
  end
452
510
 
@@ -524,7 +582,7 @@ end
524
582
 
525
583
  desc <<~EOF
526
584
  Top comments by what ...
527
- Allowed \"what\" options: upvoted downvoted
585
+ Allowed \"what\" options: voter upvoted downvoted
528
586
  EOF
529
587
  task :top, [:what, :limit] do |t, args|
530
588
  what = args[:what].to_s.downcase.to_sym
@@ -532,6 +590,13 @@ task :top, [:what, :limit] do |t, args|
532
590
  since = 1.week.ago
533
591
 
534
592
  case what
593
+ when :voter
594
+ votes = HiveSQL::Tx::Vote.after(since)
595
+ votes = votes.group(:voter)
596
+ votes = votes.order('count_all DESC')
597
+ votes = votes.limit(limit)
598
+
599
+ ap votes.count
535
600
  when :upvoted, :downvoted
536
601
  comments = HiveSQL::Comment.after(since)
537
602
  comments = if what == :upvoted
@@ -553,6 +618,8 @@ task :top, [:what, :limit] do |t, args|
553
618
 
554
619
  puts "#{v}; #{created.round(2)} days ago: #{url}"
555
620
  end
621
+ else
622
+ exec 'rake -D top | head -3'
556
623
  end
557
624
  end
558
625
 
@@ -602,20 +669,124 @@ task :proposal_pay, [:minimum_payment, :days_ago] do |t, args|
602
669
  puts "Average daily payments: #{'%.3f' % average_daily_payments} #{symbol}"
603
670
  end
604
671
 
672
+ desc 'Lists sum of HBD interest grouped by date, from, and to.'
673
+ task :interest, [:minimum_payment, :days_ago] do |t, args|
674
+ now = Time.now.utc
675
+ minimum_payment = (args[:minimum_payment] || '0.001').to_f
676
+ days_ago = (args[:days_ago] || '30').to_i
677
+ after_timestamp = now - days_ago * 86400
678
+
679
+ payments = HiveSQL::Vo::Interest.all
680
+ payments = payments.where('Interest > ?', minimum_payment)
681
+ payments = payments.where('timestamp > ?', after_timestamp)
682
+ duration = payments.minimum(:timestamp)
683
+
684
+ payments = payments.group('CAST(timestamp AS DATE)')
685
+ payments = payments.order('cast_timestamp_as_date ASC')
686
+
687
+ puts "# Daily interest payment sum #{'%.3f HBD' % minimum_payment} and over, since #{after_timestamp} ..."
688
+ ap payments.sum(:Interest)
689
+
690
+ actual_days = ((((Time.now - duration)) / 60) / 60) / 24
691
+ interst_sum = payments.sum(:Interest).values.sum
692
+ average_daily_payments = interst_sum / actual_days
693
+ puts "Total interest paid for period #{'%.3f HBD' % interst_sum}; average daily payments: #{'%.3f HBD' % average_daily_payments} (days: #{actual_days})"
694
+ end
695
+
605
696
  # Doesn't look like this table exists.
606
- # desc 'List conversion HBD conversion request sums grouped by day.'
607
- # task :convert, [:days_ago] do |t, args|
608
- # now = Time.now.utc
609
- # after_timestamp = now - ((args[:days_ago] || '3.5').to_f * 86400)
610
- #
611
- # converts = HiveSQL::Vo::FillConvertRequest
612
- # converts = converts.where('timestamp > ?', after_timestamp)
613
- # converts = converts.group('CAST(timestamp AS DATE)')
614
- # converts = converts.order('cast_timestamp_as_date ASC')
615
- #
616
- # puts "Daily conversion requests failled sum grouped by date since #{after_timestamp} ..."
617
- # ap converts.sum(:amount)
618
- # end
697
+ desc 'List conversion HBD conversion request sums grouped by day.'
698
+ task :convert, [:days_ago] do |t, args|
699
+ now = Time.now.utc
700
+ after_timestamp = now - ((args[:days_ago] || '3.5').to_f * 86400)
701
+
702
+ converts = HiveSQL::Vo::FillConvertRequest
703
+ converts = converts.where('timestamp > ?', after_timestamp)
704
+ converts = converts.group('CAST(timestamp AS DATE)')
705
+ converts = converts.order('cast_timestamp_as_date ASC')
706
+
707
+ puts "# Daily HBD conversion requests sum grouped by date since #{after_timestamp} ..."
708
+ ap converts.sum(:amount_in)
709
+ end
710
+
711
+ # Doesn't look like this table exists.
712
+ desc 'List daily activity of account, for specified days (default 90)'
713
+ task :activity, [:account_name, :days_ago] do |t, args|
714
+ now = Time.now.utc
715
+ after_timestamp = now - ((args[:days_ago] || '90').to_f * 86400)
716
+ account_name = args[:account_name]
717
+
718
+ trx = HiveSQL::Transaction.by(account_name)
719
+ trx = trx.joins(:block).where('timestamp > ?', after_timestamp)
720
+ trx = trx.group('type')
721
+ trx = trx.order('count_type ASC')
722
+
723
+ puts "# Daily transactions by #{account_name} for type count grouped by type since #{after_timestamp} ..."
724
+ ap trx.count(:type)
725
+ end
726
+
727
+ namespace :witnesses do
728
+ desc 'Count witnesses that have signed blocks, group by day.'
729
+ task :count, [:days_ago] do |t, args|
730
+ now = Time.now.utc
731
+ days_ago = (args[:days_ago] || '3.5').to_f
732
+ after_timestamp = now - (days_ago * 86400)
733
+
734
+ blocks = HiveSQL::Block
735
+ blocks = blocks.where('timestamp > ?', after_timestamp)
736
+ duration = blocks.minimum(:timestamp)
737
+ total_witness_count = blocks.distinct.count(:witness)
738
+ blocks = blocks.group('CAST(timestamp AS DATE)')
739
+ blocks = blocks.order('cast_timestamp_as_date ASC')
740
+
741
+ actual_days = ((((Time.now - duration)) / 60) / 60) / 24
742
+
743
+ puts "Witness count that signed blocks grouped by date since #{after_timestamp} ..."
744
+ ap blocks.distinct.count(:witness)
745
+ puts "# Total unique witnesses: %d (average: %.1f per day)" % [total_witness_count, (blocks.distinct.count(:witness).values.sum) / actual_days]
746
+ end
747
+
748
+ desc 'Witness accounts that have signed blocks, group by day.'
749
+ task :accounts, [:days_ago] do |t, args|
750
+ now = Time.now.utc
751
+ days_ago = (args[:days_ago] || '3.5').to_f
752
+ after_timestamp = now - (days_ago * 86400)
753
+
754
+ blocks = HiveSQL::Block
755
+ blocks = blocks.where('timestamp > ?', after_timestamp)
756
+ duration = blocks.minimum(:timestamp)
757
+ total_witness_count = blocks.distinct.count(:witness)
758
+ blocks = blocks.group(:witness)
759
+ blocks = blocks.order('1 ASC')
760
+
761
+ actual_days = ((((Time.now - duration)) / 60) / 60) / 24
762
+
763
+ puts "Witness count that signed blocks grouped by date since #{after_timestamp} ..."
764
+ ap blocks.distinct.count(:all)
765
+ puts "# Total unique witnesses: %d" % [total_witness_count]
766
+ end
767
+
768
+ desc 'New witness accounts that have signed blocks, group by day.'
769
+ task :new_accounts, [:days_ago] do |t, args|
770
+ now = Time.now.utc
771
+ days_ago = (args[:days_ago] || '3.5').to_f
772
+ after_timestamp = now - (days_ago * 86400)
773
+
774
+ blocks = HiveSQL::Block
775
+ previous_blocks = blocks.where('timestamp <= ?', after_timestamp).limit(9600) # about one day of blocks
776
+ previous_blocks = previous_blocks.order(block_num: :desc)
777
+ blocks = blocks.where('timestamp > ?', after_timestamp).where.not(witness: previous_blocks.select(:witness))
778
+ duration = blocks.minimum(:timestamp)
779
+ total_witness_count = blocks.distinct.count(:witness)
780
+ blocks = blocks.group(:witness)
781
+ blocks = blocks.order('1 ASC')
782
+
783
+ actual_days = ((((Time.now - duration)) / 60) / 60) / 24
784
+
785
+ puts "New witness count that signed blocks grouped by date since #{after_timestamp} ..."
786
+ ap blocks.distinct.count(:all)
787
+ puts "# Total unique witnesses: %d" % [total_witness_count]
788
+ end
789
+ end
619
790
 
620
791
  desc 'Build a new version of the hive_sql gem.'
621
792
  task :build do
@@ -29,6 +29,11 @@ module HiveSQL
29
29
  has_many :subscriptions, foreign_key: :subscriber, class_name: 'HiveSQL::CommunitySubscriber', primary_key: :name
30
30
  has_many :subscribed_communities, through: :subscriptions, source: :community_record
31
31
 
32
+ has_many :proposals, foreign_key: :creator, class_name: 'HiveSQL::Proposal', primary_key: :name
33
+
34
+ has_many :proposal_votes, foreign_key: :voter, class_name: 'HiveSQL::ProposalApproval', primary_key: :name
35
+ has_many :approved_proposals, through: :proposal_votes, source: :proposal
36
+
32
37
  scope :before, lambda { |before, field = 'created'| where("#{field} < ?", before) }
33
38
  scope :after, lambda { |after, field = 'created'| where("#{field} > ?", after) }
34
39
  scope :today, -> { after(1.day.ago) }
@@ -1,3 +1,5 @@
1
+ require 'open-uri'
2
+
1
3
  module HiveSQL
2
4
  class Block < HiveSQL::SqlBase
3
5
 
@@ -5,7 +7,17 @@ module HiveSQL
5
7
  self.primary_key = :block_num
6
8
 
7
9
  has_many :transactions, foreign_key: :block_num
8
-
10
+
11
+ # You have the actual trx_id that the blockchain knows about and you would
12
+ # like to get this corresponding block. Well, HiveSQL doesn't store that,
13
+ # so we have to do an RPC lookup.
14
+ scope :trx_id, lambda { |trx_id|
15
+ block_num = JSON[open("http://anyx.io/v1/account_history_api/get_transaction?id=#{trx_id}").read].tap do |tx|
16
+ tx['block_num']
17
+ end
18
+
19
+ where(block_num: block_num)
20
+ }
9
21
  end
10
22
  end
11
23
 
@@ -25,8 +25,11 @@ module HiveSQL
25
25
 
26
26
  scope :normalized_json, -> { where("json_metadata LIKE '{%}' AND ISJSON(json_metadata) > 0") }
27
27
 
28
- scope :app, lambda { |app|
29
- normalized_json.where("JSON_VALUE(json_metadata, '$.app') LIKE ?", "#{app}/%")
28
+ scope :app, lambda { |app, forward = true|
29
+ r = normalized_json.where("JSON_VALUE(json_metadata, '$.app') LIKE ?", "#{app}/%")
30
+ r = where.not(id: r.select(:id)) unless forward
31
+
32
+ r
30
33
  }
31
34
 
32
35
  scope :app_version, lambda { |version|
@@ -37,12 +40,15 @@ module HiveSQL
37
40
  scope :author, lambda {|author| joins(:author_record).where(author: author)}
38
41
 
39
42
  scope :tagged, lambda { |tag, options = {exclude_category: false}|
43
+ tag = [tag].flatten
40
44
  exclude_category = !!options[:exclude_category]
45
+ tagged_posts = HiveSQL::Tag.where(tag: tag).select(:comment_ID)
46
+ tagged_posts = tagged_posts.where("comment_ID > ?", minimum(:ID))
41
47
 
42
48
  if exclude_category
43
- where(id: HiveSQL::Tag.where(tag: tag).select(:comment_ID))
49
+ where(id: tagged_posts.select(:comment_ID))
44
50
  else
45
- where("ID IN(?) OR category = ?", HiveSQL::Tag.where(tag: tag).select(:comment_ID), tag)
51
+ where("ID IN(?) OR category = ?", tagged_posts.select(:comment_ID), tag.first)
46
52
  end
47
53
  }
48
54
 
@@ -66,6 +72,32 @@ module HiveSQL
66
72
  where("JSON_VALUE(beneficiaries, '$.account') IN(?)", [account].flatten)
67
73
  }
68
74
 
75
+ scope :query, lambda { |query, forward = true|
76
+ query = [query].flatten.map{|q| "%#{q}%"}
77
+ condition = []
78
+ sub_conditions = []
79
+
80
+ sub_conditions << "LOWER(author) LIKE ?"
81
+ sub_conditions << "LOWER(permlink) LIKE ?"
82
+ sub_conditions << "LOWER(category) LIKE ?"
83
+ sub_conditions << "LOWER(parent_author) LIKE ?"
84
+ sub_conditions << "LOWER(parent_permlink) LIKE ?"
85
+ sub_conditions << "LOWER(title) LIKE ?"
86
+ sub_conditions << "LOWER(body) LIKE ?"
87
+ sub_conditions << "LOWER(json_metadata) LIKE ?"
88
+ sub_conditions << "LOWER(beneficiaries) LIKE ?"
89
+ sub_conditions << "LOWER(root_title) LIKE ?"
90
+
91
+ query.each do |q|
92
+ condition += sub_conditions
93
+ end
94
+
95
+ r = where(condition.join(' OR '), *(query * sub_conditions.size))
96
+ r = where.not(id: r.select(:id)) unless forward
97
+
98
+ r
99
+ }
100
+
69
101
  def self.find_by_author(author)
70
102
  where(author: author).first
71
103
  end
@@ -85,6 +117,10 @@ module HiveSQL
85
117
  def tag_names
86
118
  tags.pluck(:tag)
87
119
  end
120
+
121
+ def hydrated_json_metadata
122
+ JSON[json_metadata] rescue {}
123
+ end
88
124
  end
89
125
  end
90
126
 
@@ -18,17 +18,23 @@ end
18
18
  # num_pow_witnesses: integer,
19
19
  # virtual_supply: money,
20
20
  # current_supply: money,
21
+ # current_supply_symbol: varchar,
21
22
  # confidential_supply: money,
23
+ # confidential_supply_symbol: varchar,
22
24
  # current_hbd_supply: money,
25
+ # current_hbd_supply_symbol: varchar,
23
26
  # confidential_hbd_supply: money,
24
27
  # total_vesting_fund_hive: money,
25
28
  # total_vesting_fund_hive_symbol: varchar,
26
29
  # total_vesting_shares: money,
27
30
  # total_vesting_shares_symbol: varchar,
28
31
  # total_reward_fund_hive: money,
32
+ # total_reward_fund_hive_symbol: varchar,
29
33
  # total_reward_shares2: varchar,
30
34
  # pending_rewarded_vesting_shares: varchar,
35
+ # pending_rewarded_vesting_shares_symbol: varchar,
31
36
  # pending_rewarded_vesting_hive: varchar,
37
+ # pending_rewarded_vesting_hive_symbol: varchar,
32
38
  # hbd_interest_rate: integer,
33
39
  # hbd_print_rate: integer,
34
40
  # average_block_size: integer,
@@ -41,5 +47,24 @@ end
41
47
  # vote_power_reserve_rate: integer,
42
48
  # current_reserve_ratio: integer,
43
49
  # vote_regeneration_per_day: integer,
44
- # hive_per_vest: money
50
+ # hive_per_vest: money,
51
+ # required_actions_partition_percent: integer,
52
+ # target_votes_per_period: integer,
53
+ # delegation_return_period: integer,
54
+ # reverse_auction_seconds: integer,
55
+ # available_account_subsidies: integer,
56
+ # hbd_stop_percent: integer,
57
+ # hbd_start_percent: integer,
58
+ # next_maintenance_time: timestamp,
59
+ # last_budget_time: timestamp,
60
+ # content_reward_percent: integer,
61
+ # vesting_reward_percent: integer,
62
+ # sps_fund_percent: integer,
63
+ # sps_interval_ledger: integer,
64
+ # sps_interval_ledger_symbol: varchar,
65
+ # downvote_pool_percent: integer,
66
+ # smt_creation_fee: money,
67
+ # smt_creation_fee_symbol: varchar,
68
+ # price_hive_usd: money,
69
+ # price_hbd_usd: money
45
70
  # )
@@ -0,0 +1,26 @@
1
+ module HiveSQL
2
+ class Proposal < HiveSQL::SqlBase
3
+ self.table_name = :Proposals
4
+
5
+ belongs_to :creator_record, foreign_key: :creator, class_name: 'HiveSQL::Account', primary_key: :name
6
+ belongs_to :receiver_record, foreign_key: :receiver, class_name: 'HiveSQL::Account', primary_key: :name
7
+ has_many :approvals, foreign_key: :proposal_id, class_name: 'HiveSQL::ProposalApproval', primary_key: :id
8
+ has_many :voters, through: :approvals, source: :voter
9
+ end
10
+ end
11
+
12
+ # Structure
13
+ #
14
+ # HiveSQL::Follower(
15
+ # id integer,
16
+ # creator varchar,
17
+ # receiver varchar,
18
+ # start_date timestamp,
19
+ # end_date timestamp,
20
+ # daily_pay money,
21
+ # daily_pay_symbol varchar(3),
22
+ # subject varchar,
23
+ # permlink varchar,
24
+ # total_votes integer,
25
+ # deleted boolean
26
+ # )
@@ -0,0 +1,15 @@
1
+ module HiveSQL
2
+ class ProposalApproval < HiveSQL::SqlBase
3
+ self.table_name = :ProposalsApprovals
4
+
5
+ belongs_to :proposal, foreign_key: :proposal_id, class_name: 'Proposal', primary_key: :id
6
+ belongs_to :voter_record, foreign_key: :voter, class_name: 'Account', primary_key: :name
7
+ end
8
+ end
9
+
10
+ # Structure
11
+ #
12
+ # HiveSQL::Follower(
13
+ # proposal_id integer,
14
+ # voter varchar
15
+ # )
@@ -3,8 +3,8 @@ module HiveSQL
3
3
 
4
4
  self.table_name = :Reblogs
5
5
 
6
- belongs_to :account, foreign_key: :account, class_name: 'Account', primary_key: :name
7
- belongs_to :author_account, foreign_key: :author, class_name: 'Account', primary_key: :name
6
+ belongs_to :account_record, foreign_key: :account, class_name: 'Account', primary_key: :name
7
+ belongs_to :author_record, foreign_key: :author, class_name: 'Account', primary_key: :name
8
8
 
9
9
  def comment; Comment::find_by(author: author, permlink: permlink); end
10
10
  end
@@ -14,6 +14,20 @@ module HiveSQL
14
14
 
15
15
  scope :type, lambda { |type| where(type: type) }
16
16
 
17
+ scope :by, lambda {|account_name|
18
+ account_name = [account_name].flatten
19
+ sub_selects = []
20
+ sub_selects << 'tx_id IN (SELECT tx_id FROM TxAccountCreates WHERE creator IN (?))'
21
+ sub_selects << 'tx_id IN (SELECT tx_id FROM TxAccountRecovers WHERE recovery_account IN (?))'
22
+ sub_selects << 'tx_id IN (SELECT tx_id FROM TxAccountUpdates WHERE account IN (?))'
23
+ sub_selects << 'tx_id IN (SELECT tx_id FROM TxAccountWitnessProxies WHERE account IN (?))'
24
+ sub_selects << 'tx_id IN (SELECT tx_id FROM TxAccountWitnessVotes WHERE account IN (?))'
25
+ sub_selects << 'tx_id IN (SELECT tx_id FROM TxClaimRewardBalances WHERE account IN (?))'
26
+ sub_selects << 'tx_id IN (SELECT tx_id FROM TxComments WHERE author IN (?))'
27
+
28
+ where(sub_selects.join(' OR '), *([account_name] * sub_selects.size))
29
+ }
30
+
17
31
  # So you have a Transaction#tx_id and you want to know what the operation was
18
32
  # that lead to it. Well, that's tricky because all of the ops are in their
19
33
  # own tables. This method will (slowly) try to find the appropriate table.
@@ -10,7 +10,7 @@ module HiveSQL
10
10
 
11
11
  ids = active.map do |p|
12
12
  p.id unless AccountWitnessProxy.where(account: p.account).
13
- where.not(proxy: p.Proxy).
13
+ where.not(proxy: p.proxy).
14
14
  where('timestamp > ?', p.timestamp).exists?
15
15
  end
16
16
 
@@ -26,6 +26,6 @@ end
26
26
  # ID: integer,
27
27
  # tx_id: integer,
28
28
  # account: varchar,
29
- # Proxy: varchar,
29
+ # proxy: varchar,
30
30
  # timestamp: datetime
31
31
  # )
@@ -10,6 +10,7 @@ module HiveSQL
10
10
  scope :any_required_posting_auths, lambda { |required_posting_auth|
11
11
  where("? IN(JSON_VALUE(required_posting_auths, '$'))", required_posting_auth)
12
12
  }
13
+ scope :normalized_json, -> { where("ISJSON(json_metadata) > 0") }
13
14
  end
14
15
  end
15
16
  end
@@ -0,0 +1,35 @@
1
+ module HiveSQL
2
+ module Tx
3
+ class ProposalCreate < HiveSQL::SqlBase
4
+ belongs_to :voter_record, foreign_key: :account, primary_key: :voter, class_name: 'HiveSQL::Account'
5
+
6
+ self.table_name = :TxProposalCreates
7
+
8
+ scope :proposal, lambda { |id, invert = false|
9
+ if !!invert
10
+ where("? NOT IN (SELECT value FROM OPENJSON(proposal_ids,'$'))", id)
11
+ else
12
+ where("? IN (SELECT value FROM OPENJSON(proposal_ids,'$'))", id)
13
+ end
14
+ }
15
+
16
+ scope :approve, lambda {|approve = true| where(approve: approve)}
17
+ end
18
+ end
19
+ end
20
+
21
+ # Structure
22
+ #
23
+ # HiveSQL::Tx::ProposalCreate(
24
+ # ID: integer,
25
+ # tx_id: integer,
26
+ # creator: varchar,
27
+ # receiver: varchar,
28
+ # start_date: datetime
29
+ # end_date: datetime
30
+ # daily_pay: money,
31
+ # daily_pay_symbol: boolean,
32
+ # subject: varchar,
33
+ # permlink: varchar,
34
+ # timestamp: datetime
35
+ # )
@@ -1,9 +1,9 @@
1
1
  module HiveSQL
2
2
  module Tx
3
- class UpdateProposalVote < HiveSQL::SqlBase
3
+ class ProposalVoteUpdate < HiveSQL::SqlBase
4
4
  belongs_to :voter_record, foreign_key: :account, primary_key: :voter, class_name: 'HiveSQL::Account'
5
5
 
6
- self.table_name = :TxUpdateProposalVotes
6
+ self.table_name = :TxProposalVoteUpdates
7
7
 
8
8
  scope :proposal, lambda { |id, invert = false|
9
9
  if !!invert
@@ -20,7 +20,7 @@ end
20
20
 
21
21
  # Structure
22
22
  #
23
- # HiveSQL::Tx::Vote(
23
+ # HiveSQL::Tx::ProposalVoteUpdate(
24
24
  # ID: integer,
25
25
  # tx_id: integer,
26
26
  # voter: varchar,
@@ -0,0 +1,23 @@
1
+ module HiveSQL
2
+ module Vo
3
+ class AccountCreated < HiveSQL::SqlBase
4
+
5
+ self.table_name = :VOAccountCreateds
6
+
7
+ end
8
+ end
9
+ end
10
+
11
+ # Structure
12
+ #
13
+ # HiveSQL::Vo::AccountCreated(
14
+ # ID: integer,
15
+ # block_num: integer,
16
+ # timestamp: datetime,
17
+ # new_account_name: varchar,
18
+ # creator: varchar,
19
+ # initial_vesting_shares: money,
20
+ # initial_vesting_shares_symbol: varchar,
21
+ # initial_delegation: money,
22
+ # initial_delegation_symbol: varchar
23
+ # )
@@ -0,0 +1,20 @@
1
+ module HiveSQL
2
+ module Vo
3
+ class ChangedRecoveryAccount < HiveSQL::SqlBase
4
+
5
+ self.table_name = :VOChangedRecoveryAccounts
6
+
7
+ end
8
+ end
9
+ end
10
+
11
+ # Structure
12
+ #
13
+ # HiveSQL::Vo::ChangedRecoveryAccount(
14
+ # ID: integer,
15
+ # block_num: integer,
16
+ # timestamp: datetime,
17
+ # account: varchar,
18
+ # old_recovery_account: varchar,
19
+ # new_recovery_account: varchar
20
+ # )
@@ -0,0 +1,21 @@
1
+ module HiveSQL
2
+ module Vo
3
+ class ClearNullAccountBalance < HiveSQL::SqlBase
4
+
5
+ self.table_name = :VOClearNullAccountBalances
6
+
7
+ def hydrated_total_cleared
8
+ JSON[total_cleared]
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ # Structure
15
+ #
16
+ # HiveSQL::Vo::ClearNullAccountBalance(
17
+ # ID: integer,
18
+ # block_num: integer,
19
+ # timestamp: datetime,
20
+ # total_cleared: json
21
+ # )
@@ -0,0 +1,25 @@
1
+ module HiveSQL
2
+ module Vo
3
+ class CommentsVote < HiveSQL::SqlBase
4
+
5
+ self.table_name = :VOCommentsVotes
6
+
7
+ end
8
+ end
9
+ end
10
+
11
+ # Structure
12
+ #
13
+ # HiveSQL::Vo::CommentsVote(
14
+ # ID: integer,
15
+ # block_num: integer,
16
+ # timestamp: datetime,
17
+ # voter: varchar,
18
+ # author: varchar,
19
+ # permlink: varchar
20
+ # weight: integer,
21
+ # rshares: integer,
22
+ # total_vote_weight: integer,
23
+ # pending_payout: money
24
+ # pending_payout_symbol: varchar
25
+ # )
@@ -14,5 +14,7 @@ end
14
14
  # ID: integer,
15
15
  # block_num: integer,
16
16
  # timestamp: datetime,
17
- # additional_funds: money
17
+ # receiver: varchar
18
+ # payment: money
19
+ # payment_symbol: varchar
18
20
  # )
@@ -1,3 +1,3 @@
1
1
  module HiveSQL
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
data/lib/hive_sql.rb CHANGED
@@ -14,6 +14,8 @@ require "hive_sql/models/community_role"
14
14
  require "hive_sql/models/delegation"
15
15
  require "hive_sql/models/dynamic_global_properties"
16
16
  require "hive_sql/models/follower"
17
+ require "hive_sql/models/proposal"
18
+ require "hive_sql/models/proposal_approval"
17
19
  require "hive_sql/models/reblog"
18
20
  require "hive_sql/models/tag"
19
21
  require "hive_sql/models/token"
@@ -41,7 +43,8 @@ require "hive_sql/models/tx/feed"
41
43
  require "hive_sql/models/tx/limit_order"
42
44
  require "hive_sql/models/tx/pow"
43
45
  require "hive_sql/models/tx/transfer"
44
- require "hive_sql/models/tx/update_proposal_vote"
46
+ require "hive_sql/models/tx/proposal_create"
47
+ require "hive_sql/models/tx/proposal_vote_update"
45
48
  require "hive_sql/models/tx/vote"
46
49
  require "hive_sql/models/tx/withdraw"
47
50
  require "hive_sql/models/tx/withdraw_vesting_route"
@@ -52,10 +55,14 @@ require "hive_sql/models/tx/custom/witness"
52
55
  require "hive_sql/models/tx/custom/reblog"
53
56
  require "hive_sql/models/tx/custom/community"
54
57
 
58
+ require "hive_sql/models/vo/account_created"
55
59
  require "hive_sql/models/vo/author_reward"
60
+ require "hive_sql/models/vo/changed_recovery_account"
61
+ require "hive_sql/models/vo/clear_null_account_balance"
56
62
  require "hive_sql/models/vo/comment_benefactor_reward"
57
63
  require "hive_sql/models/vo/comment_payout_update"
58
64
  require "hive_sql/models/vo/comment_reward"
65
+ require "hive_sql/models/vo/comments_vote"
59
66
  require "hive_sql/models/vo/curation_reward"
60
67
  require "hive_sql/models/vo/fill_convert_request"
61
68
  require "hive_sql/models/vo/fill_order"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hive_sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Martin (inertia)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-28 00:00:00.000000000 Z
11
+ date: 2022-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -34,42 +34,42 @@ dependencies:
34
34
  name: rake
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: 12.1.0
40
37
  - - "~>"
41
38
  - !ruby/object:Gem::Version
42
- version: '12.1'
39
+ version: '13.0'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 13.0.6
43
43
  type: :development
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: 12.1.0
50
47
  - - "~>"
51
48
  - !ruby/object:Gem::Version
52
- version: '12.1'
49
+ version: '13.0'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 13.0.6
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: minitest-proveit
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- version: 1.0.0
60
57
  - - "~>"
61
58
  - !ruby/object:Gem::Version
62
59
  version: '1.0'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 1.0.0
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: 1.0.0
70
67
  - - "~>"
71
68
  - !ruby/object:Gem::Version
72
69
  version: '1.0'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 1.0.0
73
73
  - !ruby/object:Gem::Dependency
74
74
  name: minitest
75
75
  requirement: !ruby/object:Gem::Requirement
@@ -174,22 +174,22 @@ dependencies:
174
174
  name: irb
175
175
  requirement: !ruby/object:Gem::Requirement
176
176
  requirements:
177
- - - ">="
178
- - !ruby/object:Gem::Version
179
- version: 1.0.0
180
177
  - - "~>"
181
178
  - !ruby/object:Gem::Version
182
179
  version: '1.0'
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: 1.0.0
183
183
  type: :development
184
184
  prerelease: false
185
185
  version_requirements: !ruby/object:Gem::Requirement
186
186
  requirements:
187
- - - ">="
188
- - !ruby/object:Gem::Version
189
- version: 1.0.0
190
187
  - - "~>"
191
188
  - !ruby/object:Gem::Version
192
189
  version: '1.0'
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ version: 1.0.0
193
193
  - !ruby/object:Gem::Dependency
194
194
  name: nokogiri
195
195
  requirement: !ruby/object:Gem::Requirement
@@ -267,6 +267,9 @@ dependencies:
267
267
  - - ">="
268
268
  - !ruby/object:Gem::Version
269
269
  version: '4'
270
+ - - "<"
271
+ - !ruby/object:Gem::Version
272
+ version: 7.0.3
270
273
  type: :runtime
271
274
  prerelease: false
272
275
  version_requirements: !ruby/object:Gem::Requirement
@@ -274,26 +277,29 @@ dependencies:
274
277
  - - ">="
275
278
  - !ruby/object:Gem::Version
276
279
  version: '4'
280
+ - - "<"
281
+ - !ruby/object:Gem::Version
282
+ version: 7.0.3
277
283
  - !ruby/object:Gem::Dependency
278
284
  name: awesome_print
279
285
  requirement: !ruby/object:Gem::Requirement
280
286
  requirements:
281
- - - ">="
282
- - !ruby/object:Gem::Version
283
- version: 1.7.0
284
287
  - - "~>"
285
288
  - !ruby/object:Gem::Version
286
289
  version: '1.7'
290
+ - - ">="
291
+ - !ruby/object:Gem::Version
292
+ version: 1.7.0
287
293
  type: :runtime
288
294
  prerelease: false
289
295
  version_requirements: !ruby/object:Gem::Requirement
290
296
  requirements:
291
- - - ">="
292
- - !ruby/object:Gem::Version
293
- version: 1.7.0
294
297
  - - "~>"
295
298
  - !ruby/object:Gem::Version
296
299
  version: '1.7'
300
+ - - ">="
301
+ - !ruby/object:Gem::Version
302
+ version: 1.7.0
297
303
  description: Rails compatible gem that provides full DB connection and models to HiveSQL.io
298
304
  email:
299
305
  - hive_sql@martin-studio.com
@@ -317,6 +323,8 @@ files:
317
323
  - lib/hive_sql/models/delegation.rb
318
324
  - lib/hive_sql/models/dynamic_global_properties.rb
319
325
  - lib/hive_sql/models/follower.rb
326
+ - lib/hive_sql/models/proposal.rb
327
+ - lib/hive_sql/models/proposal_approval.rb
320
328
  - lib/hive_sql/models/reblog.rb
321
329
  - lib/hive_sql/models/sql_base.rb
322
330
  - lib/hive_sql/models/tag.rb
@@ -345,16 +353,21 @@ files:
345
353
  - lib/hive_sql/models/tx/feed.rb
346
354
  - lib/hive_sql/models/tx/limit_order.rb
347
355
  - lib/hive_sql/models/tx/pow.rb
356
+ - lib/hive_sql/models/tx/proposal_create.rb
357
+ - lib/hive_sql/models/tx/proposal_vote_update.rb
348
358
  - lib/hive_sql/models/tx/transfer.rb
349
- - lib/hive_sql/models/tx/update_proposal_vote.rb
350
359
  - lib/hive_sql/models/tx/vote.rb
351
360
  - lib/hive_sql/models/tx/withdraw.rb
352
361
  - lib/hive_sql/models/tx/withdraw_vesting_route.rb
353
362
  - lib/hive_sql/models/tx/witness_update.rb
363
+ - lib/hive_sql/models/vo/account_created.rb
354
364
  - lib/hive_sql/models/vo/author_reward.rb
365
+ - lib/hive_sql/models/vo/changed_recovery_account.rb
366
+ - lib/hive_sql/models/vo/clear_null_account_balance.rb
355
367
  - lib/hive_sql/models/vo/comment_benefactor_reward.rb
356
368
  - lib/hive_sql/models/vo/comment_payout_update.rb
357
369
  - lib/hive_sql/models/vo/comment_reward.rb
370
+ - lib/hive_sql/models/vo/comments_vote.rb
358
371
  - lib/hive_sql/models/vo/curation_reward.rb
359
372
  - lib/hive_sql/models/vo/fill_convert_request.rb
360
373
  - lib/hive_sql/models/vo/fill_order.rb
@@ -388,7 +401,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
388
401
  - !ruby/object:Gem::Version
389
402
  version: '0'
390
403
  requirements: []
391
- rubygems_version: 3.0.8
404
+ rubygems_version: 3.1.6
392
405
  signing_key:
393
406
  specification_version: 4
394
407
  summary: Ruby/Rails wrapper for HiveSQL.io