cosgrove 0.0.4.0 → 0.0.4.1
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.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/README.md +42 -10
- data/cosgrove.gemspec +7 -7
- data/example-authorize-hive-sql.sh +5 -0
- data/lib/cosgrove.rb +2 -2
- data/lib/cosgrove/account.rb +27 -14
- data/lib/cosgrove/bot.rb +8 -8
- data/lib/cosgrove/comment_job.rb +4 -4
- data/lib/cosgrove/config.rb +28 -0
- data/lib/cosgrove/find_communities_job.rb +47 -0
- data/lib/cosgrove/market.rb +637 -90
- data/lib/cosgrove/support.rb +97 -24
- data/lib/cosgrove/upvote_job.rb +12 -8
- data/lib/cosgrove/utils.rb +186 -24
- data/lib/cosgrove/version.rb +1 -1
- metadata +55 -61
- data/example-authorize-steem-sql.sh +0 -5
data/lib/cosgrove/support.rb
CHANGED
@@ -4,9 +4,32 @@ module Cosgrove
|
|
4
4
|
include ActionView::Helpers::TextHelper
|
5
5
|
include ActionView::Helpers::DateHelper
|
6
6
|
|
7
|
-
|
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 =
|
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
|
-
|
41
|
+
start_typing event
|
19
42
|
guess = suggest_account_name(account_name)
|
20
43
|
|
21
44
|
help << ", did you mean: #{guess}?" if !!guess
|
@@ -35,6 +58,9 @@ 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
|
@@ -42,26 +68,22 @@ module Cosgrove
|
|
42
68
|
|
43
69
|
return unless !!author_name && !!permlink
|
44
70
|
|
45
|
-
if slug =~ /steemit.com/
|
46
|
-
chain = :steem
|
47
|
-
else
|
48
|
-
return # silntlly ignore this slug
|
49
|
-
end
|
50
|
-
|
51
71
|
if !!event
|
52
72
|
begin
|
53
|
-
message = event.respond "Looking up
|
73
|
+
message = event.respond "Looking up `#{author_name}/#{permlink}` ..."
|
54
74
|
rescue Discordrb::Errors::NoPermission => _
|
55
75
|
puts "Unable to append link details on #{event.channel.server.name} in #{event.channel.name}"
|
76
|
+
skip_channel event.channel.id
|
56
77
|
return nil
|
57
78
|
end
|
58
79
|
end
|
59
80
|
|
60
81
|
posts = case chain
|
61
|
-
when :steem then SteemApi::Comment.where(author: author_name, permlink: permlink)
|
82
|
+
# when :steem then SteemApi::Comment.where(author: author_name, permlink: permlink)
|
83
|
+
when :hive then HiveSQL::Comment.where(author: author_name, permlink: permlink)
|
62
84
|
end
|
63
85
|
|
64
|
-
posts.select(:ID, :created, :cashout_time, :author, :permlink, :active_votes, :children)
|
86
|
+
posts.select(:ID, :created, :cashout_time, :author, :permlink, :active_votes, :children, :category)
|
65
87
|
|
66
88
|
post = posts.last
|
67
89
|
|
@@ -69,6 +91,7 @@ module Cosgrove
|
|
69
91
|
# Fall back to RPC
|
70
92
|
api(chain).get_content(author_name, permlink) do |content, errors|
|
71
93
|
unless content.author.empty?
|
94
|
+
post = content
|
72
95
|
created = Time.parse(content.created + 'Z')
|
73
96
|
cashout_time = Time.parse(content.cashout_time + 'Z')
|
74
97
|
end
|
@@ -76,7 +99,26 @@ module Cosgrove
|
|
76
99
|
end
|
77
100
|
|
78
101
|
if post.nil?
|
79
|
-
|
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
|
80
122
|
|
81
123
|
return
|
82
124
|
end
|
@@ -95,9 +137,17 @@ module Cosgrove
|
|
95
137
|
end
|
96
138
|
message = message.edit details.join('; ') if !!message
|
97
139
|
|
98
|
-
|
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
|
99
144
|
|
100
|
-
|
145
|
+
active_votes = case post.active_votes
|
146
|
+
when String then JSON[post.active_votes] rescue []
|
147
|
+
else; active_votes
|
148
|
+
end
|
149
|
+
|
150
|
+
if active_votes.respond_to?(:any?) && active_votes.any?
|
101
151
|
upvotes = active_votes.map{ |v| v if v['weight'].to_i > 0 }.compact.count
|
102
152
|
downvotes = active_votes.map{ |v| v if v['weight'].to_i < 0 }.compact.count
|
103
153
|
netvotes = upvotes - downvotes
|
@@ -107,7 +157,8 @@ module Cosgrove
|
|
107
157
|
# Only append this detail of the post less than an hour old.
|
108
158
|
if created > 1.hour.ago
|
109
159
|
votes = case chain
|
110
|
-
when :steem then SteemApi::Tx::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)
|
111
162
|
end
|
112
163
|
total_votes = votes.distinct("concat(author, permlink)").count
|
113
164
|
total_voters = votes.distinct(:voter).count
|
@@ -130,14 +181,19 @@ module Cosgrove
|
|
130
181
|
details.join('; ') if event.nil?
|
131
182
|
end
|
132
183
|
|
133
|
-
def find_account(key, event = nil, chain = :
|
184
|
+
def find_account(key, event = nil, chain = :hive)
|
134
185
|
key = key.to_s.downcase
|
135
|
-
chain
|
186
|
+
chain ||= :hive
|
187
|
+
chain = chain.to_s.downcase.to_sym
|
136
188
|
|
137
|
-
raise "Required argument: chain" if chain.nil?
|
138
189
|
|
139
|
-
|
140
|
-
|
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?
|
141
197
|
accounts.first
|
142
198
|
end
|
143
199
|
end
|
@@ -150,7 +206,9 @@ module Cosgrove
|
|
150
206
|
|
151
207
|
if account.nil?
|
152
208
|
account = if !!key
|
153
|
-
if chain == :steem && (accounts = SteemApi::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?
|
154
212
|
accounts.first
|
155
213
|
else
|
156
214
|
# Fall back to RPC
|
@@ -205,7 +263,9 @@ module Cosgrove
|
|
205
263
|
end
|
206
264
|
end
|
207
265
|
|
208
|
-
def last_irreversible_block(chain = :
|
266
|
+
def last_irreversible_block(chain = :hive)
|
267
|
+
chain ||= :hive
|
268
|
+
chain = chain.to_s.downcase.to_sym
|
209
269
|
seconds_ago = (head_block_number(chain) - last_irreversible_block_num(chain)) * 3
|
210
270
|
|
211
271
|
"Last Irreversible Block was #{time_ago_in_words(seconds_ago.seconds.ago)} ago."
|
@@ -224,7 +284,8 @@ module Cosgrove
|
|
224
284
|
def muted(options = {})
|
225
285
|
[] if options.empty?
|
226
286
|
by = [options[:by]].flatten
|
227
|
-
chain = options[:chain]
|
287
|
+
chain = options[:chain] || :hive
|
288
|
+
chain = chain.to_s.downcase.to_sym
|
228
289
|
muted = []
|
229
290
|
|
230
291
|
by.each do |a|
|
@@ -244,5 +305,17 @@ module Cosgrove
|
|
244
305
|
|
245
306
|
muted.uniq
|
246
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
|
247
320
|
end
|
248
321
|
end
|
data/lib/cosgrove/upvote_job.rb
CHANGED
@@ -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 <<
|
23
|
+
muters << hive_account
|
23
24
|
muted = muted by: muters, chain: :steem
|
24
25
|
|
25
|
-
post = find_comment(chain:
|
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 =
|
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?(
|
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:
|
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(
|
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(
|
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
|
data/lib/cosgrove/utils.rb
CHANGED
@@ -7,8 +7,8 @@ module Cosgrove
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def reset_api
|
10
|
-
@steem_api = @test_api = nil
|
11
|
-
@
|
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,6 +28,12 @@ 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 :hive
|
32
|
+
{
|
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
|
+
}
|
31
37
|
when :test
|
32
38
|
{
|
33
39
|
chain: :test,
|
@@ -44,6 +50,7 @@ module Cosgrove
|
|
44
50
|
|
45
51
|
case chain
|
46
52
|
when :steem then @steem_api ||= Radiator::Api.new(chain_options(chain))
|
53
|
+
when :hive then @hive_api ||= Radiator::Api.new(chain_options(chain))
|
47
54
|
when :test then @test_api ||= Radiator::Api.new(chain_options(chain))
|
48
55
|
end
|
49
56
|
end
|
@@ -55,17 +62,118 @@ module Cosgrove
|
|
55
62
|
|
56
63
|
case chain
|
57
64
|
when :steem then @steem_follow_api ||= Radiator::FollowApi.new(chain_options(chain))
|
65
|
+
when :hive then @hive_follow_api ||= Radiator::FollowApi.new(chain_options(chain))
|
58
66
|
when :test then @test_follow_api ||= Radiator::FollowApi.new(chain_options(chain))
|
59
67
|
end
|
60
68
|
end
|
61
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
|
+
|
62
170
|
def cycle_stream_at
|
63
171
|
@cycle_stream_at if defined? @cycle_stream_at
|
64
172
|
end
|
65
173
|
|
66
174
|
def reset_stream
|
67
|
-
@steem_stream = @test_stream = nil
|
68
|
-
@
|
175
|
+
@steem_stream = @hive_stream = @test_stream = nil
|
176
|
+
@steem_follow_stream = @hive_follow_stream = @test_follow_stream = nil
|
69
177
|
@cycle_stream_at = nil
|
70
178
|
end
|
71
179
|
|
@@ -76,6 +184,7 @@ module Cosgrove
|
|
76
184
|
|
77
185
|
case chain
|
78
186
|
when :steem then @steem_stream ||= Radiator::Stream.new(chain_options(chain))
|
187
|
+
when :hive then @hive_stream ||= Radiator::Stream.new(chain_options(chain))
|
79
188
|
when :test then @test_stream ||= Radiator::Stream.new(chain_options(chain))
|
80
189
|
end
|
81
190
|
end
|
@@ -88,13 +197,14 @@ module Cosgrove
|
|
88
197
|
properties(chain)['head_block_number']
|
89
198
|
end
|
90
199
|
|
91
|
-
def last_irreversible_block_num(chain = :
|
200
|
+
def last_irreversible_block_num(chain = :hive)
|
92
201
|
properties(chain)['last_irreversible_block_num']
|
93
202
|
end
|
94
203
|
|
95
204
|
def new_tx(chain)
|
96
205
|
case chain
|
97
206
|
when :steem then Radiator::Transaction.new(chain_options(chain).merge(wif: steem_posting_wif))
|
207
|
+
when :hive then Radiator::Transaction.new(chain_options(chain).merge(wif: hive_posting_wif))
|
98
208
|
when :test then Radiator::Transaction.new(chain_options(chain).merge(wif: test_posting_wif))
|
99
209
|
end
|
100
210
|
end
|
@@ -124,17 +234,24 @@ module Cosgrove
|
|
124
234
|
end
|
125
235
|
end
|
126
236
|
|
127
|
-
def find_author_name_permlink(slug)
|
237
|
+
def find_author_name_permlink(slug, chain = :hive)
|
238
|
+
chain = chain.to_s.downcase.to_sym
|
128
239
|
op, author_name = slug.split(':')
|
129
240
|
author_name, offset = author_name.split(/[\+-]/)
|
130
|
-
author = find_account(author_name)
|
241
|
+
author = find_account(author_name, nil, chain)
|
131
242
|
|
132
243
|
offset = offset.to_i
|
133
244
|
|
134
245
|
posts = if op == 'latest'
|
135
|
-
|
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
|
136
250
|
elsif op == 'first'
|
137
|
-
|
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
|
138
255
|
else
|
139
256
|
[]
|
140
257
|
end
|
@@ -146,19 +263,28 @@ module Cosgrove
|
|
146
263
|
[]
|
147
264
|
end
|
148
265
|
|
149
|
-
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
|
150
269
|
author_name, permlink = parse_slug slug
|
151
|
-
find_comment(chain:
|
270
|
+
find_comment(chain: chain, author_name: author_name, permlink: permlink)
|
152
271
|
end
|
153
272
|
|
154
273
|
def find_comment(options)
|
155
274
|
chain = options[:chain] || :steem
|
275
|
+
chain = chain.to_s.downcase.to_sym
|
156
276
|
author_name = options[:author_name]
|
157
277
|
permlink = options[:permlink]
|
158
278
|
parent_permlink = options[:parent_permlink]
|
159
279
|
|
160
|
-
post = if chain == :
|
161
|
-
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)
|
162
288
|
posts = posts.where(permlink: permlink) if !!permlink
|
163
289
|
posts = posts.where(parent_permlink: parent_permlink) if !!parent_permlink
|
164
290
|
|
@@ -168,7 +294,13 @@ module Cosgrove
|
|
168
294
|
if post.nil?
|
169
295
|
post = case chain
|
170
296
|
when :steem
|
171
|
-
posts = SteemApi::Comment.where(author: author_name)
|
297
|
+
# posts = SteemApi::Comment.where(author: author_name)
|
298
|
+
posts = posts.where(permlink: permlink) if !!permlink
|
299
|
+
posts = posts.where(parent_permlink: parent_permlink) if !!parent_permlink
|
300
|
+
|
301
|
+
posts.first
|
302
|
+
when :hive
|
303
|
+
posts = HiveSQL::Comment.where(author: author_name)
|
172
304
|
posts = posts.where(permlink: permlink) if !!permlink
|
173
305
|
posts = posts.where(parent_permlink: parent_permlink) if !!parent_permlink
|
174
306
|
|
@@ -189,10 +321,14 @@ module Cosgrove
|
|
189
321
|
end
|
190
322
|
|
191
323
|
def find_author(options)
|
192
|
-
chain = options[:chain]
|
324
|
+
chain = options[:chain] || :steem
|
325
|
+
chain = chain.to_s.downcase.to_sym
|
193
326
|
author_name = options[:author_name]
|
194
327
|
|
195
|
-
author =
|
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
|
196
332
|
|
197
333
|
if author.nil?
|
198
334
|
author = api(chain).get_accounts([author_name]) do |accounts, errors|
|
@@ -210,15 +346,28 @@ module Cosgrove
|
|
210
346
|
memo_key = options[:memo].to_s.strip
|
211
347
|
|
212
348
|
op = case chain
|
213
|
-
when :steem
|
214
|
-
|
215
|
-
|
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).
|
216
365
|
where("memo LIKE ?", "%#{memo_key}%")
|
217
366
|
|
218
367
|
if transfers.any?
|
219
368
|
transfers.last
|
220
369
|
else
|
221
|
-
|
370
|
+
HiveSQL::Tx::Transfer.
|
222
371
|
where(from: from).
|
223
372
|
where(to: to).
|
224
373
|
where("memo LIKE ?", "%#{memo_key}%").last
|
@@ -229,7 +378,7 @@ module Cosgrove
|
|
229
378
|
# Fall back to RPC. The transaction is so new, SteemApi hasn't seen it
|
230
379
|
# yet, SteemApi is behind, or there is no such transfer.
|
231
380
|
|
232
|
-
api(chain).get_account_history(
|
381
|
+
api(chain).get_account_history(hive_account, -1, 10000) do |history, error|
|
233
382
|
if !!error
|
234
383
|
ap error
|
235
384
|
return "Try again later."
|
@@ -241,7 +390,7 @@ module Cosgrove
|
|
241
390
|
next unless type == 'transfer'
|
242
391
|
o = e.last
|
243
392
|
next unless o.from == from
|
244
|
-
next unless o.to ==
|
393
|
+
next unless o.to == hive_account
|
245
394
|
next unless o.memo =~ /.*#{memo_key}.*/
|
246
395
|
|
247
396
|
o
|
@@ -252,18 +401,31 @@ module Cosgrove
|
|
252
401
|
op
|
253
402
|
end
|
254
403
|
|
255
|
-
def core_asset(chain = :
|
404
|
+
def core_asset(chain = :hive)
|
405
|
+
chain ||= :hive
|
406
|
+
chain = chain.to_s.downcase.to_sym
|
407
|
+
|
256
408
|
case chain
|
257
409
|
when :steem then 'STEEM'
|
410
|
+
when :hive then 'HIVE'
|
258
411
|
else; 'TESTS'
|
259
412
|
end
|
260
413
|
end
|
261
414
|
|
262
|
-
def debt_asset(chain = :
|
415
|
+
def debt_asset(chain = :hive)
|
416
|
+
chain ||= :hive
|
417
|
+
chain = chain.to_s.downcase.to_sym
|
418
|
+
|
263
419
|
case chain
|
264
420
|
when :steem then 'SBD'
|
421
|
+
when :hive then 'HBD'
|
265
422
|
else; 'TBD'
|
266
423
|
end
|
267
424
|
end
|
425
|
+
private
|
426
|
+
def rpc_id
|
427
|
+
@rpc_id ||= 0
|
428
|
+
@rpc_id += 1
|
429
|
+
end
|
268
430
|
end
|
269
431
|
end
|