cosgrove 0.0.4.0pre1 → 0.0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,9 +4,32 @@ module Cosgrove
4
4
  include ActionView::Helpers::TextHelper
5
5
  include ActionView::Helpers::DateHelper
6
6
 
7
- def suggest_account_name(account_name)
7
+ # Reduce RL bucket depletion
8
+ def start_typing(event)
9
+ return if event.nil?
10
+ return unless event.respond_to? :channel
11
+ return unless event.channel.respond_to? :start_typing
12
+
13
+ @channels_typing ||= {}
14
+
15
+ if !!@channels_typing[event.channel.id] && (Time.now - @channels_typing[event.channel.id]) < 15
16
+ return
17
+ end
18
+
19
+ @channels_typing[event.channel.id] = Time.now
20
+
21
+ event.channel.start_typing
22
+ end
23
+
24
+ def suggest_account_name(account_name, chain = :hive)
25
+ chain = chain.to_s.downcase.to_sym
8
26
  pattern = account_name.chars.each.map{ |c| c }.join('%')
9
- guesses = SteemApi::Account.where("name LIKE '%#{pattern}%'").pluck(:name)
27
+ guesses = case chain
28
+ # when :steem then SteemApi::Account.where("name LIKE '%#{pattern}%'").pluck(:name)
29
+ when :hive then HiveSQL::Account.where("name LIKE '%#{pattern}%'").pluck(:name)
30
+ else
31
+ []
32
+ end
10
33
 
11
34
  if guesses.any?
12
35
  guesses.sample
@@ -15,7 +38,7 @@ module Cosgrove
15
38
 
16
39
  def unknown_account(account_name, event = nil)
17
40
  help = ["Unknown account: *#{account_name}*"]
18
- event.channel.start_typing if !!event
41
+ start_typing event
19
42
  guess = suggest_account_name(account_name)
20
43
 
21
44
  help << ", did you mean: #{guess}?" if !!guess
@@ -35,36 +58,70 @@ module Cosgrove
35
58
  end
36
59
 
37
60
  def append_link_details(event, slug)
61
+ return if skipped_channel? event.channel.id
62
+
63
+ chain = :hive
38
64
  author_name, permlink = parse_slug slug
39
65
  created = nil
40
66
  cashout_time = nil
67
+ message = nil
41
68
 
42
- if slug =~ /steemit.com/
43
- chain = :steem
44
- elsif slug =~ /golos.io/
45
- chain = :golos
46
- elsif slug =~ /golos.blog/
47
- chain = :golos
48
- else
49
- return # silntlly ignore this slug
69
+ return unless !!author_name && !!permlink
70
+
71
+ if !!event
72
+ begin
73
+ message = event.respond "Looking up `#{author_name}/#{permlink}` ..."
74
+ rescue Discordrb::Errors::NoPermission => _
75
+ puts "Unable to append link details on #{event.channel.server.name} in #{event.channel.name}"
76
+ skip_channel event.channel.id
77
+ return nil
78
+ end
50
79
  end
51
80
 
52
- post = case chain
53
- when :steem then SteemApi::Comment.where(author: author_name, permlink: permlink).last
54
- when :golos then GolosCloud::Comment.where(author: author_name, permlink: permlink).last
81
+ posts = case chain
82
+ # when :steem then SteemApi::Comment.where(author: author_name, permlink: permlink)
83
+ when :hive then HiveSQL::Comment.where(author: author_name, permlink: permlink)
55
84
  end
56
85
 
86
+ posts.select(:ID, :created, :cashout_time, :author, :permlink, :active_votes, :children, :category)
87
+
88
+ post = posts.last
89
+
57
90
  if post.nil?
58
91
  # Fall back to RPC
59
92
  api(chain).get_content(author_name, permlink) do |content, errors|
60
93
  unless content.author.empty?
94
+ post = content
61
95
  created = Time.parse(content.created + 'Z')
62
96
  cashout_time = Time.parse(content.cashout_time + 'Z')
63
97
  end
64
98
  end
65
99
  end
66
100
 
67
- return if post.nil?
101
+ if post.nil?
102
+ if !!message
103
+ message = message.edit 'Looking for content on Hive ...'
104
+ end
105
+
106
+ # Fall back to Hive RPC
107
+ api(:hive).get_content(author_name, permlink) do |content, errors|
108
+ unless content.author.empty?
109
+ post = content
110
+ created = Time.parse(content.created + 'Z')
111
+ cashout_time = Time.parse(content.cashout_time + 'Z')
112
+ end
113
+ end
114
+ end
115
+
116
+ if post.nil?
117
+ if !!message
118
+ message = message.edit 'Unable to locate.'
119
+ sleep 5
120
+ message.delete
121
+ end
122
+
123
+ return
124
+ end
68
125
 
69
126
  created ||= post.created
70
127
  cashout_time ||= post.cashout_time
@@ -73,57 +130,70 @@ module Cosgrove
73
130
  age = time_ago_in_words(created)
74
131
  age = age.slice(0, 1).capitalize + age.slice(1..-1)
75
132
 
76
- details << if created < 30.minutes.ago
133
+ details << if created < 15.minutes.ago
77
134
  "#{age} old"
78
135
  else
79
136
  "**#{age}** old"
80
137
  end
138
+ message = message.edit details.join('; ') if !!message
139
+
140
+ if !!post.category && !!post.category.starts_with?('hive-') && (communities = Cosgrove::FindCommunitiesJob.new.perform(nil, [post.category]), 1).any?
141
+ details << "in #{communities.first.payload['props']['title']}" rescue nil
142
+ message = message.edit details.join('; ') if !!message
143
+ end
81
144
 
82
- active_votes = SteemApi::Tx::Vote.where(author: post.author, permlink: post.permlink)
145
+ active_votes = case post.active_votes
146
+ when String then JSON[post.active_votes] rescue []
147
+ else; active_votes
148
+ end
83
149
 
84
- if active_votes.any?
85
- upvotes = active_votes.map{ |v| v if v.weight > 0 }.compact.count
86
- downvotes = active_votes.map{ |v| v if v.weight < 0 }.compact.count
150
+ if active_votes.respond_to?(:any?) && active_votes.any?
151
+ upvotes = active_votes.map{ |v| v if v['weight'].to_i > 0 }.compact.count
152
+ downvotes = active_votes.map{ |v| v if v['weight'].to_i < 0 }.compact.count
87
153
  netvotes = upvotes - downvotes
88
154
  details << "Net votes: #{netvotes}"
155
+ message = message.edit details.join('; ') if !!message
89
156
 
90
157
  # Only append this detail of the post less than an hour old.
91
158
  if created > 1.hour.ago
92
159
  votes = case chain
93
- when :steem then SteemApi::Tx::Vote.where('timestamp > ?', post.created)
94
- when :golos then GolosCloud::Vote.where('timestamp > ?', post.created)
160
+ # when :steem then SteemApi::Tx::Vote.where('timestamp > ?', post.created)
161
+ when :hive then HiveSQL::Tx::Vote.where('timestamp > ?', post.created)
95
162
  end
96
- total_votes = votes.count
97
- total_voters = votes.distinct(:voter).size
163
+ total_votes = votes.distinct("concat(author, permlink)").count
164
+ total_voters = votes.distinct(:voter).count
98
165
 
99
166
  if total_votes > 0 && total_voters > 0
100
167
  details << "Out of #{pluralize(total_votes - netvotes, 'vote')} cast by #{pluralize(total_voters, 'voter')}"
168
+ message = message.edit details.join('; ') if !!message
101
169
  end
102
170
  end
103
171
  end
104
172
 
105
173
  details << "Comments: #{post.children.to_i}"
174
+ message = message.edit details.join('; ') if !!message
106
175
 
176
+ # Page View counter is no longer supported by steemit.com.
107
177
  # page_views = page_views("/#{post.parent_permlink}/@#{post.author}/#{post.permlink}")
108
178
  # details << "Views: #{page_views}" if !!page_views
179
+ # message = message.edit details.join('; ') if !!message
109
180
 
110
- begin
111
- event.respond details.join('; ')
112
- rescue Discordrb::Errors::NoPermission => _
113
- puts "Unable to append link details on #{event.channel.server.name} in #{event.channel.name}"
114
- end
115
-
116
- return nil
181
+ details.join('; ') if event.nil?
117
182
  end
118
183
 
119
- def find_account(key, event = nil, chain = :steem)
184
+ def find_account(key, event = nil, chain = :hive)
120
185
  key = key.to_s.downcase
121
- chain = chain.to_sym
186
+ chain ||= :hive
187
+ chain = chain.to_s.downcase.to_sym
122
188
 
123
- raise "Required argument: chain" if chain.nil?
124
189
 
125
- if chain == :steem
126
- account = if (accounts = SteemApi::Account.where(name: key)).any?
190
+ case chain
191
+ # when :steem
192
+ # account = if (accounts = SteemApi::Account.where(name: key)).any?
193
+ # accounts.first
194
+ # end
195
+ when :hive
196
+ account = if (accounts = HiveSQL::Account.where(name: key)).any?
127
197
  accounts.first
128
198
  end
129
199
  end
@@ -136,9 +206,9 @@ module Cosgrove
136
206
 
137
207
  if account.nil?
138
208
  account = if !!key
139
- if chain == :steem && (accounts = SteemApi::Account.where(name: key)).any?
140
- accounts.first
141
- elsif chain == :golos && (accounts = GolosCloud::Account.where(name: key)).any?
209
+ # if chain == :steem && (accounts = SteemApi::Account.where(name: key)).any?
210
+ # accounts.first
211
+ if chain == :hive && (accounts = HiveSQL::Account.where(name: key)).any?
142
212
  accounts.first
143
213
  else
144
214
  # Fall back to RPC
@@ -193,7 +263,9 @@ module Cosgrove
193
263
  end
194
264
  end
195
265
 
196
- def last_irreversible_block(chain = :steem)
266
+ def last_irreversible_block(chain = :hive)
267
+ chain ||= :hive
268
+ chain = chain.to_s.downcase.to_sym
197
269
  seconds_ago = (head_block_number(chain) - last_irreversible_block_num(chain)) * 3
198
270
 
199
271
  "Last Irreversible Block was #{time_ago_in_words(seconds_ago.seconds.ago)} ago."
@@ -212,7 +284,8 @@ module Cosgrove
212
284
  def muted(options = {})
213
285
  [] if options.empty?
214
286
  by = [options[:by]].flatten
215
- chain = options[:chain]
287
+ chain = options[:chain] || :hive
288
+ chain = chain.to_s.downcase.to_sym
216
289
  muted = []
217
290
 
218
291
  by.each do |a|
@@ -232,5 +305,17 @@ module Cosgrove
232
305
 
233
306
  muted.uniq
234
307
  end
308
+
309
+ def skipped_channels
310
+ @@skipped_channels ||= []
311
+ end
312
+
313
+ def skipped_channel?(id)
314
+ skipped_channels.include? id
315
+ end
316
+
317
+ def skip_channel(id)
318
+ skipped_channels << id
319
+ end
235
320
  end
236
321
  end
@@ -8,28 +8,32 @@ module Cosgrove
8
8
  @on_success = options[:on_success]
9
9
  end
10
10
 
11
- def perform(event, slug)
11
+ def perform(event, slug, chain = :hive)
12
12
  if slug.nil? || slug.empty?
13
13
  event.respond 'Sorry, I wasn\'t paying attention.'
14
14
  return
15
15
  end
16
16
 
17
+ chain = chain.to_s.downcase.to_sym
17
18
  author_name, permlink = parse_slug slug
18
19
  discord_id = event.author.id
19
20
  cb_account = Cosgrove::Account.find_by_discord_id(discord_id)
20
21
  registered = !!cb_account
21
22
  muters = cosgrove_operators
22
- muters << steem_account
23
+ muters << hive_account
23
24
  muted = muted by: muters, chain: :steem
24
25
 
25
- post = find_comment(chain: :steem, author_name: author_name, permlink: permlink)
26
+ post = find_comment(chain: chain, author_name: author_name, permlink: permlink)
26
27
 
27
28
  if post.nil?
28
29
  cannot_find_input(event)
29
30
  return
30
31
  end
31
32
 
32
- votes_today = SteemApi::Tx::Vote.where(voter: steem_account).today
33
+ votes_today = case chain
34
+ # when :steem then SteemApi::Tx::Vote.where(voter: steem_account).today
35
+ when :hive then HiveSQL::Tx::Vote.where(voter: hive_account).today
36
+ end
33
37
  today_count = votes_today.count
34
38
  author_count = votes_today.where(author: author_name).count
35
39
  vote_ratio = if today_count == 0
@@ -83,7 +87,7 @@ module Cosgrove
83
87
  'Unable to vote. Your account has been resticted.'
84
88
  elsif today_count > 10 && vote_ratio > 0.1
85
89
  "Maybe later. It seems like I've been voting for #{author_name} quite a bit lately."
86
- elsif active_votes.map{ |v| v['voter'] }.include?(steem_account)
90
+ elsif active_votes.map{ |v| v['voter'] }.include?(hive_account)
87
91
  title = post.title
88
92
  title = post.permlink if title.empty?
89
93
  "I already voted on #{title} by #{post.author}."
@@ -96,7 +100,7 @@ module Cosgrove
96
100
 
97
101
  vote = {
98
102
  type: :vote,
99
- voter: steem_account,
103
+ voter: hive_account,
100
104
  author: post.author,
101
105
  permlink: post.permlink,
102
106
  weight: upvote_weight(event.channel.id)
@@ -180,13 +184,13 @@ module Cosgrove
180
184
 
181
185
  case upvote_weight
182
186
  when 'dynamic'
183
- bot_account = find_account(steem_account)
187
+ bot_account = find_account(hive_account)
184
188
  upvote_weight = bot_account.voting_power.to_i
185
189
  when 'upvote_rules'
186
190
  upvote_weight = channel_upvote_weight(channel_id)
187
191
 
188
192
  if upvote_weight == 'dynamic'
189
- bot_account = find_account(steem_account)
193
+ bot_account = find_account(hive_account)
190
194
  upvote_weight = bot_account.voting_power.to_i
191
195
  else
192
196
  upvote_weight = (((upvote_weight || '0.00 %').to_f) * 100).to_i
@@ -7,8 +7,8 @@ module Cosgrove
7
7
  end
8
8
 
9
9
  def reset_api
10
- @steem_api = @golos_api = @test_api = nil
11
- @steem_folow_api = @golos_follow_api = @test_folow_api = nil
10
+ @steem_api = @hive_api = @test_api = nil
11
+ @steem_follow_api = @hive_follow_api = @test_follow_api = nil
12
12
  @cycle_api_at = nil
13
13
  end
14
14
 
@@ -28,11 +28,11 @@ module Cosgrove
28
28
  url: steem_api_url,
29
29
  failover_urls: steem_api_failover_urls.any? ? steem_api_failover_urls : nil
30
30
  }
31
- when :golos
31
+ when :hive
32
32
  {
33
- chain: :golos,
34
- url: golos_api_url,
35
- failover_urls: golos_api_failover_urls.any? ? golos_api_failover_urls : nil
33
+ chain: :steem, # TODO switch to :hive when supported by radiator
34
+ url: hive_api_url,
35
+ failover_urls: hive_api_failover_urls.any? ? hive_api_failover_urls : nil
36
36
  }
37
37
  when :test
38
38
  {
@@ -50,7 +50,7 @@ module Cosgrove
50
50
 
51
51
  case chain
52
52
  when :steem then @steem_api ||= Radiator::Api.new(chain_options(chain))
53
- when :golos then @golos_api ||= Radiator::Api.new(chain_options(chain))
53
+ when :hive then @hive_api ||= Radiator::Api.new(chain_options(chain))
54
54
  when :test then @test_api ||= Radiator::Api.new(chain_options(chain))
55
55
  end
56
56
  end
@@ -62,18 +62,118 @@ module Cosgrove
62
62
 
63
63
  case chain
64
64
  when :steem then @steem_follow_api ||= Radiator::FollowApi.new(chain_options(chain))
65
- when :golos then @golos_follow_api ||= Radiator::FollowApi.new(chain_options(chain))
65
+ when :hive then @hive_follow_api ||= Radiator::FollowApi.new(chain_options(chain))
66
66
  when :test then @test_follow_api ||= Radiator::FollowApi.new(chain_options(chain))
67
67
  end
68
68
  end
69
69
 
70
+ def steem_engine_shutdown
71
+ problem = false
72
+
73
+ begin
74
+ @steem_engine_blockchain.shutdown if !!@steem_engine_blockchain
75
+ rescue => e
76
+ puts "Unable to shut down steem engine blockchain rpc: #{e}"
77
+ problem = true
78
+ end
79
+
80
+ begin
81
+ @steem_engine_contracts.shutdown if !!@steem_engine_contracts
82
+ rescue => e
83
+ puts "Unable to shut down steem engine contracts rpc: #{e}"
84
+ problem = true
85
+ end
86
+
87
+ !problem
88
+ end
89
+
90
+ def steem_engine(method, params = {}, rpc)
91
+ begin
92
+ if params.respond_to?(:empty?) && params.empty?
93
+ rpc.send(method)
94
+ else
95
+ rpc.send(method, params)
96
+ end
97
+ rescue => e
98
+ steem_engine_shutdown
99
+
100
+ raise e
101
+ end
102
+ end
103
+
104
+ def steem_engine_blockchain(method, params = {}, &block)
105
+ @steem_engine_blockchain ||= Radiator::SSC::Blockchain.new(root_url: steem_engine_api_url)
106
+ result = steem_engine(method, params, @steem_engine_blockchain)
107
+
108
+ yield result if !!block
109
+ return result
110
+ end
111
+
112
+ def steem_engine_contracts(method, params = {}, &block)
113
+ @steem_engine_contracts ||= Radiator::SSC::Contracts.new(root_url: steem_engine_api_url)
114
+ result = steem_engine(method, params, @steem_engine_contracts)
115
+
116
+ yield result if !!block
117
+ return result
118
+ end
119
+
120
+ def hive_engine_shutdown
121
+ problem = false
122
+
123
+ begin
124
+ @hive_engine_blockchain.shutdown if !!@hive_engine_blockchain
125
+ rescue => e
126
+ puts "Unable to shut down hive engine blockchain rpc: #{e}"
127
+ problem = true
128
+ end
129
+
130
+ begin
131
+ @hive_engine_contracts.shutdown if !!@hive_engine_contracts
132
+ rescue => e
133
+ puts "Unable to shut down hive engine contracts rpc: #{e}"
134
+ problem = true
135
+ end
136
+
137
+ !problem
138
+ end
139
+
140
+ def hive_engine(method, params = {}, rpc)
141
+ begin
142
+ if params.respond_to?(:empty?) && params.empty?
143
+ rpc.send(method)
144
+ else
145
+ rpc.send(method, params)
146
+ end
147
+ rescue => e
148
+ hive_engine_shutdown
149
+
150
+ raise e
151
+ end
152
+ end
153
+
154
+ def hive_engine_blockchain(method, params = {}, &block)
155
+ @hive_engine_blockchain ||= Radiator::SSC::Blockchain.new(root_url: hive_engine_api_url)
156
+ result = hive_engine(method, params, @hive_engine_blockchain)
157
+
158
+ yield result if !!block
159
+ return result
160
+ end
161
+
162
+ def hive_engine_contracts(method, params = {}, &block)
163
+ @hive_engine_contracts ||= Radiator::SSC::Contracts.new(root_url: hive_engine_api_url)
164
+ result = hive_engine(method, params, @hive_engine_contracts)
165
+
166
+ yield result if !!block
167
+ return result
168
+ end
169
+
70
170
  def cycle_stream_at
71
171
  @cycle_stream_at if defined? @cycle_stream_at
72
172
  end
73
173
 
74
174
  def reset_stream
75
- @steem_stream = @golos_stream = @test_stream = nil
76
- @steem_folow_stream = @golos_follow_stream = @test_folow_stream = nil
175
+ @steem_stream = @hive_stream = @test_stream = nil
176
+ @steem_follow_stream = @hive_follow_stream = @test_follow_stream = nil
77
177
  @cycle_stream_at = nil
78
178
  end
79
179
 
@@ -84,7 +184,7 @@ module Cosgrove
84
184
 
85
185
  case chain
86
186
  when :steem then @steem_stream ||= Radiator::Stream.new(chain_options(chain))
87
- when :golos then @golos_stream ||= Radiator::Stream.new(chain_options(chain))
187
+ when :hive then @hive_stream ||= Radiator::Stream.new(chain_options(chain))
88
188
  when :test then @test_stream ||= Radiator::Stream.new(chain_options(chain))
89
189
  end
90
190
  end
@@ -97,14 +197,14 @@ module Cosgrove
97
197
  properties(chain)['head_block_number']
98
198
  end
99
199
 
100
- def last_irreversible_block_num(chain = :steem)
200
+ def last_irreversible_block_num(chain = :hive)
101
201
  properties(chain)['last_irreversible_block_num']
102
202
  end
103
203
 
104
204
  def new_tx(chain)
105
205
  case chain
106
206
  when :steem then Radiator::Transaction.new(chain_options(chain).merge(wif: steem_posting_wif))
107
- when :golos then Radiator::Transaction.new(chain_options(chain).merge(wif: golos_posting_wif))
207
+ when :hive then Radiator::Transaction.new(chain_options(chain).merge(wif: hive_posting_wif))
108
208
  when :test then Radiator::Transaction.new(chain_options(chain).merge(wif: test_posting_wif))
109
209
  end
110
210
  end
@@ -128,22 +228,30 @@ module Cosgrove
128
228
  slug = slug.split('@').last
129
229
  author_name = slug.split('/')[0]
130
230
  permlink = slug.split('/')[1..-1].join('/')
231
+ permlink = permlink.split('#')[0]
131
232
 
132
233
  [author_name, permlink]
133
234
  end
134
235
  end
135
236
 
136
- def find_author_name_permlink(slug)
237
+ def find_author_name_permlink(slug, chain = :hive)
238
+ chain = chain.to_s.downcase.to_sym
137
239
  op, author_name = slug.split(':')
138
240
  author_name, offset = author_name.split(/[\+-]/)
139
- author = find_account(author_name)
241
+ author = find_account(author_name, nil, chain)
140
242
 
141
243
  offset = offset.to_i
142
244
 
143
245
  posts = if op == 'latest'
144
- SteemApi::Comment.where(depth: 0, author: author.name).order(created: :desc)
246
+ case chain
247
+ # when :steem then SteemApi::Comment.where(depth: 0, author: author.name).order(created: :desc)
248
+ when :hive then HiveSQL::Comment.where(depth: 0, author: author.name).order(created: :desc)
249
+ end
145
250
  elsif op == 'first'
146
- SteemApi::Comment.where(depth: 0, author: author.name).order(created: :asc)
251
+ case chain
252
+ # when :steem then SteemApi::Comment.where(depth: 0, author: author.name).order(created: :asc)
253
+ when :hive then HiveSQL::Comment.where(depth: 0, author: author.name).order(created: :asc)
254
+ end
147
255
  else
148
256
  []
149
257
  end
@@ -155,19 +263,28 @@ module Cosgrove
155
263
  []
156
264
  end
157
265
 
158
- def find_comment_by_slug(slug)
266
+ def find_comment_by_slug(slug, chain = :hive)
267
+ chain ||= :hive
268
+ chain = chain.to_s.downcase.to_sym
159
269
  author_name, permlink = parse_slug slug
160
- find_comment(chain: :steem, author_name: author_name, permlink: permlink)
270
+ find_comment(chain: chain, author_name: author_name, permlink: permlink)
161
271
  end
162
272
 
163
273
  def find_comment(options)
164
274
  chain = options[:chain] || :steem
275
+ chain = chain.to_s.downcase.to_sym
165
276
  author_name = options[:author_name]
166
277
  permlink = options[:permlink]
167
278
  parent_permlink = options[:parent_permlink]
168
279
 
169
- post = if chain == :steem
170
- posts = SteemApi::Comment.where(depth: 0, author: author_name)
280
+ post = if chain == :hive
281
+ # posts = SteemApi::Comment.where(depth: 0, author: author_name)
282
+ posts = posts.where(permlink: permlink) if !!permlink
283
+ posts = posts.where(parent_permlink: parent_permlink) if !!parent_permlink
284
+
285
+ posts.first
286
+ elsif chain == :hive
287
+ posts = HiveSQL::Comment.where(depth: 0, author: author_name)
171
288
  posts = posts.where(permlink: permlink) if !!permlink
172
289
  posts = posts.where(parent_permlink: parent_permlink) if !!parent_permlink
173
290
 
@@ -177,13 +294,13 @@ module Cosgrove
177
294
  if post.nil?
178
295
  post = case chain
179
296
  when :steem
180
- posts = SteemApi::Comment.where(author: author_name)
297
+ # posts = SteemApi::Comment.where(author: author_name)
181
298
  posts = posts.where(permlink: permlink) if !!permlink
182
299
  posts = posts.where(parent_permlink: parent_permlink) if !!parent_permlink
183
300
 
184
301
  posts.first
185
- when :golos
186
- posts = GolosCloud::Comment.where(author: author_name)
302
+ when :hive
303
+ posts = HiveSQL::Comment.where(author: author_name)
187
304
  posts = posts.where(permlink: permlink) if !!permlink
188
305
  posts = posts.where(parent_permlink: parent_permlink) if !!parent_permlink
189
306
 
@@ -204,10 +321,14 @@ module Cosgrove
204
321
  end
205
322
 
206
323
  def find_author(options)
207
- chain = options[:chain]
324
+ chain = options[:chain] || :steem
325
+ chain = chain.to_s.downcase.to_sym
208
326
  author_name = options[:author_name]
209
327
 
210
- author = SteemApi::Account.where(name: author_name).first
328
+ author = case chain
329
+ # when :steem then SteemApi::Account.where(name: author_name).first
330
+ when :hive then HiveSQL::Account.where(name: author_name).first
331
+ end
211
332
 
212
333
  if author.nil?
213
334
  author = api(chain).get_accounts([author_name]) do |accounts, errors|
@@ -225,31 +346,39 @@ module Cosgrove
225
346
  memo_key = options[:memo].to_s.strip
226
347
 
227
348
  op = case chain
228
- when :steem
229
- transfers = SteemApi::Tx::Transfer.
230
- where(from: from, to: steem_account).
349
+ # when :steem
350
+ # transfers = SteemApi::Tx::Transfer.
351
+ # where(from: from, to: steem_account).
352
+ # where("memo LIKE ?", "%#{memo_key}%")
353
+ #
354
+ # if transfers.any?
355
+ # transfers.last
356
+ # else
357
+ # SteemApi::Tx::Transfer.
358
+ # where(from: from).
359
+ # where(to: to).
360
+ # where("memo LIKE ?", "%#{memo_key}%").last
361
+ # end
362
+ when :hive
363
+ transfers = HiveSQL::Tx::Transfer.
364
+ where(from: from, to: hive_account).
231
365
  where("memo LIKE ?", "%#{memo_key}%")
232
366
 
233
367
  if transfers.any?
234
368
  transfers.last
235
369
  else
236
- SteemApi::Tx::Transfer.
370
+ HiveSQL::Tx::Transfer.
237
371
  where(from: from).
238
372
  where(to: to).
239
373
  where("memo LIKE ?", "%#{memo_key}%").last
240
374
  end
241
- when :golos
242
- GolosCloud::Tx::Transfer.
243
- where(from: from).
244
- where(to: to).
245
- where("memo LIKE ?", "%#{memo_key}%").last
246
375
  end
247
376
 
248
377
  if op.nil?
249
378
  # Fall back to RPC. The transaction is so new, SteemApi hasn't seen it
250
379
  # yet, SteemApi is behind, or there is no such transfer.
251
380
 
252
- api(chain).get_account_history(steem_account, -1, 10000) do |history, error|
381
+ api(chain).get_account_history(hive_account, -1, 10000) do |history, error|
253
382
  if !!error
254
383
  ap error
255
384
  return "Try again later."
@@ -261,7 +390,7 @@ module Cosgrove
261
390
  next unless type == 'transfer'
262
391
  o = e.last
263
392
  next unless o.from == from
264
- next unless o.to == steem_account
393
+ next unless o.to == hive_account
265
394
  next unless o.memo =~ /.*#{memo_key}.*/
266
395
 
267
396
  o
@@ -272,20 +401,31 @@ module Cosgrove
272
401
  op
273
402
  end
274
403
 
275
- def core_asset(chain = :steem)
404
+ def core_asset(chain = :hive)
405
+ chain ||= :hive
406
+ chain = chain.to_s.downcase.to_sym
407
+
276
408
  case chain
277
409
  when :steem then 'STEEM'
278
- when :golos then 'GOLOS'
410
+ when :hive then 'HIVE'
279
411
  else; 'TESTS'
280
412
  end
281
413
  end
282
414
 
283
- def debt_asset(chain = :steem)
415
+ def debt_asset(chain = :hive)
416
+ chain ||= :hive
417
+ chain = chain.to_s.downcase.to_sym
418
+
284
419
  case chain
285
420
  when :steem then 'SBD'
286
- when :golos then 'GBG'
421
+ when :hive then 'HBD'
287
422
  else; 'TBD'
288
423
  end
289
424
  end
425
+ private
426
+ def rpc_id
427
+ @rpc_id ||= 0
428
+ @rpc_id += 1
429
+ end
290
430
  end
291
431
  end