radiator 0.2.0a

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ module Radiator
2
+ class DatabaseApi < Api
3
+ end
4
+ end
@@ -0,0 +1,7 @@
1
+ module Radiator
2
+ class FollowApi < Api
3
+ def api_name
4
+ :follow_api
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ require 'logger'
2
+
3
+ module Radiator
4
+ # The logger that Radiator uses for reporting errors.
5
+ #
6
+ # @return [Logger]
7
+ def self.logger
8
+ @logger ||= Logger.new(STDOUT)
9
+ end
10
+
11
+ # Sets the logger that Radiator uses for reporting errors.
12
+ #
13
+ # @param logger [Logger] The logger to set as Radiator's logger.
14
+ # @return [void]
15
+ def self.logger=(logger)
16
+ @logger = logger
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ module Radiator
2
+ class MarketHistoryApi < Api
3
+ def method_names
4
+ @method_names ||= [
5
+ :get_market_history,
6
+ :get_market_history_buckets,
7
+ :get_order_book,
8
+ :get_recent_trades,
9
+ :get_ticker,
10
+ :get_trade_history,
11
+ :get_volume
12
+ ].freeze
13
+ end
14
+
15
+ def api_name
16
+ :market_history_api
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,488 @@
1
+ // Copied from:
2
+ // https://raw.githubusercontent.com/steemit/steem-js/master/src/api/methods.json
3
+
4
+ [
5
+ {
6
+ "api": "database_api",
7
+ "method": "set_subscribe_callback",
8
+ "params": ["callback", "clearFilter"]
9
+ },
10
+ {
11
+ "api": "database_api",
12
+ "method": "set_pending_transaction_callback",
13
+ "params": ["cb"]
14
+ },
15
+ {
16
+ "api": "database_api",
17
+ "method": "set_block_applied_callback",
18
+ "params": ["cb"]
19
+ },
20
+ {
21
+ "api": "database_api",
22
+ "method": "cancel_all_subscriptions"
23
+ },
24
+ {
25
+ "api": "database_api",
26
+ "method": "get_trending_tags",
27
+ "params": ["afterTag", "limit"]
28
+ },
29
+ {
30
+ "api": "database_api",
31
+ "method": "get_tags_used_by_author",
32
+ "params": ["author"]
33
+ },
34
+ {
35
+ "api": "database_api",
36
+ "method": "get_post_discussions_by_payout",
37
+ "params": ["query"]
38
+ },
39
+ {
40
+ "api": "database_api",
41
+ "method": "get_comment_discussions_by_payout",
42
+ "params": ["query"]
43
+ },
44
+ {
45
+ "api": "database_api",
46
+ "method": "get_discussions_by_trending",
47
+ "params": ["query"]
48
+ },
49
+ {
50
+ "api": "database_api",
51
+ "method": "get_discussions_by_trending30",
52
+ "params": ["query"]
53
+ },
54
+ {
55
+ "api": "database_api",
56
+ "method": "get_discussions_by_created",
57
+ "params": ["query"]
58
+ },
59
+ {
60
+ "api": "database_api",
61
+ "method": "get_discussions_by_active",
62
+ "params": ["query"]
63
+ },
64
+ {
65
+ "api": "database_api",
66
+ "method": "get_discussions_by_cashout",
67
+ "params": ["query"]
68
+ },
69
+ {
70
+ "api": "database_api",
71
+ "method": "get_discussions_by_payout",
72
+ "params": ["query"]
73
+ },
74
+ {
75
+ "api": "database_api",
76
+ "method": "get_discussions_by_votes",
77
+ "params": ["query"]
78
+ },
79
+ {
80
+ "api": "database_api",
81
+ "method": "get_discussions_by_children",
82
+ "params": ["query"]
83
+ },
84
+ {
85
+ "api": "database_api",
86
+ "method": "get_discussions_by_hot",
87
+ "params": ["query"]
88
+ },
89
+ {
90
+ "api": "database_api",
91
+ "method": "get_discussions_by_feed",
92
+ "params": ["query"]
93
+ },
94
+ {
95
+ "api": "database_api",
96
+ "method": "get_discussions_by_blog",
97
+ "params": ["query"]
98
+ },
99
+ {
100
+ "api": "database_api",
101
+ "method": "get_discussions_by_comments",
102
+ "params": ["query"]
103
+ },
104
+ {
105
+ "api": "database_api",
106
+ "method": "get_discussions_by_promoted",
107
+ "params": ["query"]
108
+ },
109
+ {
110
+ "api": "database_api",
111
+ "method": "get_block_header",
112
+ "params": ["blockNum"]
113
+ },
114
+ {
115
+ "api": "database_api",
116
+ "method": "get_block",
117
+ "params": ["blockNum"]
118
+ },
119
+ {
120
+ "api": "database_api",
121
+ "method": "get_ops_in_block",
122
+ "params": ["blockNum", "onlyVirtual"]
123
+ },
124
+ {
125
+ "api": "database_api",
126
+ "method": "get_state",
127
+ "params": ["path"]
128
+ },
129
+ {
130
+ "api": "database_api",
131
+ "method": "get_trending_categories",
132
+ "params": ["after", "limit"]
133
+ },
134
+ {
135
+ "api": "database_api",
136
+ "method": "get_best_categories",
137
+ "params": ["after", "limit"]
138
+ },
139
+ {
140
+ "api": "database_api",
141
+ "method": "get_active_categories",
142
+ "params": ["after", "limit"]
143
+ },
144
+ {
145
+ "api": "database_api",
146
+ "method": "get_recent_categories",
147
+ "params": ["after", "limit"]
148
+ },
149
+ {
150
+ "api": "database_api",
151
+ "method": "get_config"
152
+ },
153
+ {
154
+ "api": "database_api",
155
+ "method": "get_dynamic_global_properties"
156
+ },
157
+ {
158
+ "api": "database_api",
159
+ "method": "get_chain_properties"
160
+ },
161
+ {
162
+ "api": "database_api",
163
+ "method": "get_feed_history"
164
+ },
165
+ {
166
+ "api": "database_api",
167
+ "method": "get_current_median_history_price"
168
+ },
169
+ {
170
+ "api": "database_api",
171
+ "method": "get_witness_schedule"
172
+ },
173
+ {
174
+ "api": "database_api",
175
+ "method": "get_hardfork_version"
176
+ },
177
+ {
178
+ "api": "database_api",
179
+ "method": "get_next_scheduled_hardfork"
180
+ },
181
+ {
182
+ "api": "account_by_key_api",
183
+ "method": "get_key_references",
184
+ "params": ["key"]
185
+ },
186
+ {
187
+ "api": "database_api",
188
+ "method": "get_accounts",
189
+ "params": ["names"]
190
+ },
191
+ {
192
+ "api": "database_api",
193
+ "method": "get_account_references",
194
+ "params": ["accountId"]
195
+ },
196
+ {
197
+ "api": "database_api",
198
+ "method": "lookup_account_names",
199
+ "params": ["accountNames"]
200
+ },
201
+ {
202
+ "api": "database_api",
203
+ "method": "lookup_accounts",
204
+ "params": ["lowerBoundName", "limit"]
205
+ },
206
+ {
207
+ "api": "database_api",
208
+ "method": "get_account_count"
209
+ },
210
+ {
211
+ "api": "database_api",
212
+ "method": "get_conversion_requests",
213
+ "params": ["accountName"]
214
+ },
215
+ {
216
+ "api": "database_api",
217
+ "method": "get_account_history",
218
+ "params": ["account", "from", "limit"]
219
+ },
220
+ {
221
+ "api": "database_api",
222
+ "method": "get_owner_history",
223
+ "params": ["account"]
224
+ },
225
+ {
226
+ "api": "database_api",
227
+ "method": "get_recovery_request",
228
+ "params": ["account"]
229
+ },
230
+ {
231
+ "api": "database_api",
232
+ "method": "get_escrow",
233
+ "params": ["from", "escrowId"]
234
+ },
235
+ {
236
+ "api": "database_api",
237
+ "method": "get_withdraw_routes",
238
+ "params": ["account", "withdrawRouteType"]
239
+ },
240
+ {
241
+ "api": "database_api",
242
+ "method": "get_account_bandwidth",
243
+ "params": ["account", "bandwidthType"]
244
+ },
245
+ {
246
+ "api": "database_api",
247
+ "method": "get_savings_withdraw_from",
248
+ "params": ["account"]
249
+ },
250
+ {
251
+ "api": "database_api",
252
+ "method": "get_savings_withdraw_to",
253
+ "params": ["account"]
254
+ },
255
+ {
256
+ "api": "database_api",
257
+ "method": "get_order_book",
258
+ "params": ["limit"]
259
+ },
260
+ {
261
+ "api": "database_api",
262
+ "method": "get_open_orders",
263
+ "params": ["owner"]
264
+ },
265
+ {
266
+ "api": "database_api",
267
+ "method": "get_liquidity_queue",
268
+ "params": ["startAccount", "limit"]
269
+ },
270
+ {
271
+ "api": "database_api",
272
+ "method": "get_transaction_hex",
273
+ "params": ["trx"]
274
+ },
275
+ {
276
+ "api": "database_api",
277
+ "method": "get_transaction",
278
+ "params": ["trxId"]
279
+ },
280
+ {
281
+ "api": "database_api",
282
+ "method": "get_required_signatures",
283
+ "params": ["trx", "availableKeys"]
284
+ },
285
+ {
286
+ "api": "database_api",
287
+ "method": "get_potential_signatures",
288
+ "params": ["trx"]
289
+ },
290
+ {
291
+ "api": "database_api",
292
+ "method": "verify_authority",
293
+ "params": ["trx"]
294
+ },
295
+ {
296
+ "api": "database_api",
297
+ "method": "verify_account_authority",
298
+ "params": ["nameOrId", "signers"]
299
+ },
300
+ {
301
+ "api": "database_api",
302
+ "method": "get_active_votes",
303
+ "params": ["author", "permlink"]
304
+ },
305
+ {
306
+ "api": "database_api",
307
+ "method": "get_account_votes",
308
+ "params": ["voter"]
309
+ },
310
+ {
311
+ "api": "database_api",
312
+ "method": "get_content",
313
+ "params": ["author", "permlink"]
314
+ },
315
+ {
316
+ "api": "database_api",
317
+ "method": "get_content_replies",
318
+ "params": ["parent", "parentPermlink"]
319
+ },
320
+ {
321
+ "api": "database_api",
322
+ "method": "get_discussions_by_author_before_date",
323
+ "params": ["author", "startPermlink", "beforeDate", "limit"]
324
+ },
325
+ {
326
+ "api": "database_api",
327
+ "method": "get_replies_by_last_update",
328
+ "params": ["startAuthor", "startPermlink", "limit"]
329
+ },
330
+ {
331
+ "api": "database_api",
332
+ "method": "get_witnesses",
333
+ "params": ["witnessIds"]
334
+ },
335
+ {
336
+ "api": "database_api",
337
+ "method": "get_witness_by_account",
338
+ "params": ["accountName"]
339
+ },
340
+ {
341
+ "api": "database_api",
342
+ "method": "get_witnesses_by_vote",
343
+ "params": ["from", "limit"]
344
+ },
345
+ {
346
+ "api": "database_api",
347
+ "method": "lookup_witness_accounts",
348
+ "params": ["lowerBoundName", "limit"]
349
+ },
350
+ {
351
+ "api": "database_api",
352
+ "method": "get_witness_count"
353
+ },
354
+ {
355
+ "api": "database_api",
356
+ "method": "get_active_witnesses"
357
+ },
358
+ {
359
+ "api": "database_api",
360
+ "method": "get_miner_queue"
361
+ },
362
+ {
363
+ "api": "login_api",
364
+ "method": "login",
365
+ "params": ["username", "password"]
366
+ },
367
+ {
368
+ "api": "login_api",
369
+ "method": "get_api_by_name",
370
+ "params": ["apiName"]
371
+ },
372
+ {
373
+ "api": "login_api",
374
+ "method": "get_version"
375
+ },
376
+ {
377
+ "api": "follow_api",
378
+ "method": "get_followers",
379
+ "params": ["following", "startFollower", "followType", "limit"]
380
+ },
381
+ {
382
+ "api": "follow_api",
383
+ "method": "get_following",
384
+ "params": ["follower", "startFollowing", "followType", "limit"]
385
+ },
386
+ {
387
+ "api": "follow_api",
388
+ "method": "get_follow_count",
389
+ "params": ["account"]
390
+ },
391
+ {
392
+ "api": "follow_api",
393
+ "method": "get_feed_entries",
394
+ "params": ["account", "entryId", "limit"
395
+ ]
396
+ },
397
+ {
398
+ "api": "follow_api",
399
+ "method": "get_feed",
400
+ "params": ["account", "entryId", "limit"]
401
+ },
402
+ {
403
+ "api": "follow_api",
404
+ "method": "get_blog_entries",
405
+ "params": ["account", "entryId", "limit"]
406
+ },
407
+ {
408
+ "api": "follow_api",
409
+ "method": "get_blog",
410
+ "params": ["account", "entryId", "limit"]
411
+ },
412
+ {
413
+ "api": "follow_api",
414
+ "method": "get_account_reputations",
415
+ "params": ["lowerBoundName", "limit"]
416
+ },
417
+ {
418
+ "api": "follow_api",
419
+ "method": "get_reblogged_by",
420
+ "params": ["author", "permlink"]
421
+ },
422
+ {
423
+ "api": "follow_api",
424
+ "method": "get_blog_authors",
425
+ "params": ["blogAccount"]
426
+ },
427
+ {
428
+ "api": "network_broadcast_api",
429
+ "method": "broadcast_transaction",
430
+ "params": ["trx"]
431
+ },
432
+ {
433
+ "api": "network_broadcast_api",
434
+ "method": "broadcast_transaction_with_callback",
435
+ "params": ["confirmationCallback", "trx"]
436
+ },
437
+ {
438
+ "api": "network_broadcast_api",
439
+ "method": "broadcast_transaction_synchronous",
440
+ "params": ["trx"]
441
+ },
442
+ {
443
+ "api": "network_broadcast_api",
444
+ "method": "broadcast_block",
445
+ "params": ["b"]
446
+ },
447
+ {
448
+ "api": "network_broadcast_api",
449
+ "method": "set_max_block_age",
450
+ "params": ["maxBlockAge"]
451
+ },
452
+ {
453
+ "api": "market_history_api",
454
+ "method": "get_ticker",
455
+ "params": []
456
+ },
457
+ {
458
+ "api": "market_history_api",
459
+ "method": "get_volume",
460
+ "params": []
461
+ },
462
+ {
463
+ "api": "market_history_api",
464
+ "method": "get_order_book",
465
+ "method_name": "getMarketOrderBook",
466
+ "params": ["limit"]
467
+ },
468
+ {
469
+ "api": "market_history_api",
470
+ "method": "get_trade_history",
471
+ "params": ["start", "end", "limit"]
472
+ },
473
+ {
474
+ "api": "market_history_api",
475
+ "method": "get_recent_trades",
476
+ "params": ["limit"]
477
+ },
478
+ {
479
+ "api": "market_history_api",
480
+ "method": "get_market_history",
481
+ "params": ["bucket_seconds" , "start", "end"]
482
+ },
483
+ {
484
+ "api": "market_history_api",
485
+ "method": "get_market_history_buckets",
486
+ "params": []
487
+ }
488
+ ]
@@ -0,0 +1,7 @@
1
+ module Radiator
2
+ class NetworkBroadcastApi < Api
3
+ def api_name
4
+ :network_broadcast_api
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,75 @@
1
+ module Radiator
2
+ class Operation
3
+ include OperationIds
4
+ include OperationTypes
5
+ include Utils
6
+
7
+ def initialize(options = {})
8
+ options.each do |k, v|
9
+ instance_variable_set("@#{k}", v)
10
+ end
11
+
12
+ unless Operation::known_operation_names.include? @type
13
+ raise OperationError, "Unsupported operation type: #{@type}"
14
+ end
15
+ end
16
+
17
+ def to_bytes
18
+ bytes = [id(@type.to_sym)].pack('C')
19
+
20
+ Operation::param_names(@type.to_sym).each do |p|
21
+ next unless defined? p
22
+
23
+ v = instance_variable_get("@#{p}")
24
+ v = type(@type, p, v)
25
+
26
+ bytes += v.to_bytes and next if v.respond_to? :to_bytes
27
+
28
+ bytes += case v
29
+ when String then pakStr(v)
30
+ when Integer then paks(v)
31
+ when TrueClass then pakC(1)
32
+ when FalseClass then pakC(0)
33
+ when Array then pakArr(v)
34
+ when NilClass then next
35
+ else
36
+ raise OperationError, "Unsupported type: #{v.class}"
37
+ end
38
+ end
39
+
40
+ bytes
41
+ end
42
+
43
+ def payload
44
+ params = {}
45
+
46
+ Operation::param_names(@type.to_sym).each do |p|
47
+ next unless defined? p
48
+
49
+ params[p] = instance_variable_get("@#{p}")
50
+ end
51
+
52
+ [@type, params]
53
+ end
54
+ private
55
+ def self.broadcast_operations_json_path
56
+ @broadcast_operations_json_path ||= "#{File.dirname(__FILE__)}/broadcast_operations.json"
57
+ end
58
+
59
+ def self.broadcast_operations
60
+ @broadcast_operations ||= JSON[File.read broadcast_operations_json_path]
61
+ end
62
+
63
+ def self.known_operation_names
64
+ broadcast_operations.map { |op| op["operation"].to_sym }
65
+ end
66
+
67
+ def self.param_names(type)
68
+ broadcast_operations.each do |op|
69
+ if op['operation'].to_sym == type.to_sym
70
+ return op['params'].map(&:to_sym)
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,80 @@
1
+ module Radiator
2
+ module OperationIds
3
+ # These IDS are derrived from:
4
+ # https://github.com/steemit/steem/blob/b169ad4317653d46cb776bdc8ef4c25ff178743d/libraries/protocol/include/steemit/protocol/operations.hpp
5
+
6
+ IDS = [
7
+ :vote,
8
+ :comment,
9
+
10
+ :transfer,
11
+ :transfer_to_vesting,
12
+ :withdraw_vesting,
13
+
14
+ :limit_order_create,
15
+ :limit_order_cancel,
16
+
17
+ :feed_publish,
18
+ :convert,
19
+
20
+ :account_create,
21
+ :account_update,
22
+
23
+ :witness_update,
24
+ :account_witness_vote,
25
+ :account_witness_proxy,
26
+
27
+ :pow,
28
+
29
+ :custom,
30
+
31
+ :report_over_production,
32
+
33
+ :delete_comment,
34
+ :custom_json,
35
+ :comment_options,
36
+ :set_withdraw_vesting_route,
37
+ :limit_order_create2,
38
+ :challenge_authority,
39
+ :prove_authority,
40
+ :request_account_recovery,
41
+ :recover_account,
42
+ :change_recovery_account,
43
+ :escrow_transfer,
44
+ :escrow_dispute,
45
+ :escrow_release,
46
+ :pow2,
47
+ :escrow_approve,
48
+ :transfer_to_savings,
49
+ :transfer_from_savings,
50
+ :cancel_transfer_from_savings,
51
+ :custom_binary,
52
+ :decline_voting_rights,
53
+ :reset_account,
54
+ :set_reset_account,
55
+ :claim_reward_balance,
56
+ :delegate_vesting_shares,
57
+ :account_create_with_delegation,
58
+
59
+ # virtual operations below this point
60
+ :fill_convert_request,
61
+ :author_reward,
62
+ :curation_reward,
63
+ :comment_reward,
64
+ :liquidity_reward,
65
+ :interest,
66
+ :fill_vesting_withdraw,
67
+ :fill_order,
68
+ :shutdown_witness,
69
+ :fill_transfer_from_savings,
70
+ :hardfork,
71
+ :comment_payout_update,
72
+ :return_vesting_delegation,
73
+ :comment_benefactor_reward_operation
74
+ ]
75
+
76
+ def id(op)
77
+ IDS.find_index op
78
+ end
79
+ end
80
+ end