radiator 0.4.5 → 0.4.8.pre.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/README.md +11 -11
  4. data/Rakefile +50 -20
  5. data/lib/radiator.rb +3 -1
  6. data/lib/radiator/api.rb +105 -14
  7. data/lib/radiator/bridge.rb +34 -0
  8. data/lib/radiator/chain_config.rb +9 -2
  9. data/lib/radiator/database_api.rb +1 -1
  10. data/lib/radiator/follow_api.rb +1 -1
  11. data/lib/radiator/market_history_api.rb +1 -1
  12. data/lib/radiator/operation.rb +3 -2
  13. data/lib/radiator/operation_types.rb +43 -27
  14. data/lib/radiator/ssc/base_steem_smart_contract_rpc.rb +52 -10
  15. data/lib/radiator/ssc/blockchain.rb +10 -0
  16. data/lib/radiator/ssc/contracts.rb +17 -0
  17. data/lib/radiator/stream.rb +15 -6
  18. data/lib/radiator/transaction.rb +41 -1
  19. data/lib/radiator/type/amount.rb +26 -50
  20. data/lib/radiator/type/beneficiaries.rb +8 -1
  21. data/lib/radiator/type/price.rb +2 -2
  22. data/lib/radiator/version.rb +1 -1
  23. data/radiator.gemspec +15 -13
  24. data/test/fixtures/empty.json +1 -0
  25. data/test/fixtures/error.json +29 -0
  26. data/test/fixtures/follow_api_get_followers.json +1 -0
  27. data/test/fixtures/get_account.json +165 -0
  28. data/test/fixtures/get_account_count.json +1 -0
  29. data/test/fixtures/get_account_references.json +1 -0
  30. data/test/fixtures/get_block.json +193 -0
  31. data/test/fixtures/get_dynamic_global_properties.json +32 -0
  32. data/test/fixtures/get_feed_history.json +684 -0
  33. data/test/fixtures/get_hardfork_version.json +1 -0
  34. data/test/fixtures/get_key_references.json +14 -0
  35. data/test/fixtures/get_stats_for_time.json +57 -0
  36. data/test/fixtures/get_vesting_delegation.json +936 -0
  37. data/test/fixtures/golos_get_dynamic_global_properties.json +32 -0
  38. data/test/fixtures/market_history_api_get_market_history_buckets.json +1 -0
  39. data/test/fixtures/market_history_api_get_order_book.json +109 -0
  40. data/test/fixtures/market_history_api_get_recent_trades.json +55 -0
  41. data/test/fixtures/market_history_api_get_ticker.json +11 -0
  42. data/test/fixtures/market_history_api_get_volume.json +1 -0
  43. data/test/fixtures/null.json +1 -0
  44. data/test/fixtures/vcr_cassettes/account_by_key_api_all_methods.yml +631 -0
  45. data/test/fixtures/vcr_cassettes/account_by_key_api_jsonrpc.yml +52 -0
  46. data/test/fixtures/vcr_cassettes/all_methods.yml +18155 -0
  47. data/test/fixtures/vcr_cassettes/api_all_methods.yml +13419 -0
  48. data/test/fixtures/vcr_cassettes/base_per_debt.yml +5408 -0
  49. data/test/fixtures/vcr_cassettes/base_per_mvest.yml +4351 -0
  50. data/test/fixtures/vcr_cassettes/block_time.yml +3687 -0
  51. data/test/fixtures/vcr_cassettes/broadcast_transaction.yml +1186 -0
  52. data/test/fixtures/vcr_cassettes/condenser_all_all_methods.yml +13462 -0
  53. data/test/fixtures/vcr_cassettes/condenser_api_jsonrpc.yml +51 -0
  54. data/test/fixtures/vcr_cassettes/expiration_initialize.yml +3997 -0
  55. data/test/fixtures/vcr_cassettes/find_account.yml +4004 -0
  56. data/test/fixtures/vcr_cassettes/find_block.yml +3946 -0
  57. data/test/fixtures/vcr_cassettes/find_comment.yml +12457 -0
  58. data/test/fixtures/vcr_cassettes/follow_api_jsonrpc.yml +52 -0
  59. data/test/fixtures/vcr_cassettes/get_account_count.yml +627 -0
  60. data/test/fixtures/vcr_cassettes/get_account_references.yml +663 -0
  61. data/test/fixtures/vcr_cassettes/get_accounts.yml +735 -0
  62. data/test/fixtures/vcr_cassettes/get_accounts_no_argument.yml +663 -0
  63. data/test/fixtures/vcr_cassettes/get_dynamic_global_properties.yml +721 -0
  64. data/test/fixtures/vcr_cassettes/get_feed_history.yml +1201 -0
  65. data/test/fixtures/vcr_cassettes/get_hardfork_version.yml +629 -0
  66. data/test/fixtures/vcr_cassettes/get_key_references.yml +1091 -0
  67. data/test/fixtures/vcr_cassettes/get_market_history.yml +1147 -0
  68. data/test/fixtures/vcr_cassettes/get_market_history_buckets.yml +1147 -0
  69. data/test/fixtures/vcr_cassettes/get_order_book.yml +1195 -0
  70. data/test/fixtures/vcr_cassettes/get_recent_trades.yml +1147 -0
  71. data/test/fixtures/vcr_cassettes/get_ticker.yml +1151 -0
  72. data/test/fixtures/vcr_cassettes/get_trade_history.yml +1153 -0
  73. data/test/fixtures/vcr_cassettes/get_vesting_delegations.yml +575 -0
  74. data/test/fixtures/vcr_cassettes/get_volume.yml +1155 -0
  75. data/test/fixtures/vcr_cassettes/get_witness_by_account.yml +627 -0
  76. data/test/fixtures/vcr_cassettes/look_up_witnesses.yml +575 -0
  77. data/test/fixtures/vcr_cassettes/market_history_api_all_methods.yml +4373 -0
  78. data/test/fixtures/vcr_cassettes/network_broadcast_api_all_methods.yml +1288 -0
  79. data/test/fixtures/vcr_cassettes/properties.yml +3992 -0
  80. data/test/fixtures/vcr_cassettes/recover_transaction.yml +1211 -0
  81. data/test/fixtures/vcr_cassettes/ssc_blockchain_block_info.yml +92 -0
  82. data/test/fixtures/vcr_cassettes/ssc_blockchain_block_info_invalid.yml +90 -0
  83. data/test/fixtures/vcr_cassettes/ssc_blockchain_latest_block_info.yml +91 -0
  84. data/test/fixtures/vcr_cassettes/ssc_blockchain_transaction_info.yml +92 -0
  85. data/test/fixtures/vcr_cassettes/ssc_contracts_contract.yml +366 -0
  86. data/test/fixtures/vcr_cassettes/ssc_contracts_find.yml +91 -0
  87. data/test/fixtures/vcr_cassettes/ssc_contracts_find_one.yml +89 -0
  88. data/test/fixtures/vcr_cassettes/stream_jsonrpc.yml +9175 -0
  89. data/test/fixtures/vcr_cassettes/transaction_expiration_initialize_nil.yml +3743 -0
  90. data/test/fixtures/vcr_cassettes/transaction_jsonrpc.yml +151 -0
  91. data/test/fixtures/vcr_cassettes/unknown_chain_id.yml +3869 -0
  92. data/test/fixtures/vcr_cassettes/valid_chains.yml +3427 -0
  93. data/test/radiator/account_by_key_api_test.rb +46 -0
  94. data/test/radiator/api_test.rb +135 -0
  95. data/test/radiator/chain_stats_api_test.rb +49 -0
  96. data/test/radiator/chain_test.rb +153 -0
  97. data/test/radiator/condenser_api_test.rb +48 -0
  98. data/test/radiator/follow_api_test.rb +48 -0
  99. data/test/radiator/market_history_api_test.rb +100 -0
  100. data/test/radiator/network_broadcast_api_test.rb +48 -0
  101. data/test/radiator/operation_test.rb +117 -0
  102. data/test/radiator/ssc/blockchain_test.rb +58 -0
  103. data/test/radiator/ssc/contracts_test.rb +65 -0
  104. data/test/radiator/stream_test.rb +48 -0
  105. data/test/radiator/tag_api_test.rb +40 -0
  106. data/test/radiator/transaction_test.rb +755 -0
  107. data/test/test_helper.rb +66 -0
  108. metadata +190 -80
  109. data/.codeclimate.yml +0 -19
  110. data/.gitignore +0 -52
  111. data/.travis.yml +0 -23
  112. data/gource.sh +0 -8
  113. data/images/Anthony Martin.png +0 -0
  114. data/images/Marvin Hofmann.jpg +0 -0
  115. data/images/Marvin Hofmann.png +0 -0
  116. data/lib/steem.rb +0 -17
@@ -10,6 +10,13 @@ module Radiator
10
10
  NETWORKS_STEEM_VEST_ASSET = 'VESTS'
11
11
  NETWORKS_STEEM_DEFAULT_NODE = 'https://api.steemit.com'
12
12
 
13
+ NETWORKS_HIVE_CHAIN_ID = 'beeab0de00000000000000000000000000000000000000000000000000000000'
14
+ NETWORKS_HIVE_ADDRESS_PREFIX = 'STM'
15
+ NETWORKS_HIVE_CORE_ASSET = 'HIVE'
16
+ NETWORKS_HIVE_DEBT_ASSET = 'HBD'
17
+ NETWORKS_HIVE_VEST_ASSET = 'VESTS'
18
+ NETWORKS_HIVE_DEFAULT_NODE = 'https://api.openhive.network'
19
+
13
20
  NETWORKS_TEST_CHAIN_ID = '18dcf0a285365fc58b71f18b3d3fec954aa0c141c44e4e5cb4cf777b9eab274e'
14
21
  NETWORKS_TEST_ADDRESS_PREFIX = 'TST'
15
22
  NETWORKS_TEST_CORE_ASSET = 'CORE'
@@ -17,6 +24,6 @@ module Radiator
17
24
  NETWORKS_TEST_VEST_ASSET = 'CESTS'
18
25
  NETWORKS_TEST_DEFAULT_NODE = 'https://test.steem.ws'
19
26
 
20
- NETWORK_CHAIN_IDS = [NETWORKS_STEEM_CHAIN_ID, NETWORKS_TEST_CHAIN_ID]
27
+ NETWORK_CHAIN_IDS = [NETWORKS_STEEM_CHAIN_ID, NETWORKS_HIVE_CHAIN_ID, NETWORKS_TEST_CHAIN_ID]
21
28
  end
22
- end
29
+ end
@@ -2,4 +2,4 @@ module Radiator
2
2
  # @see Api
3
3
  class DatabaseApi < Api
4
4
  end
5
- end
5
+ end
@@ -4,4 +4,4 @@ module Radiator
4
4
  :follow_api
5
5
  end
6
6
  end
7
- end
7
+ end
@@ -16,4 +16,4 @@ module Radiator
16
16
  :market_history_api
17
17
  end
18
18
  end
19
- end
19
+ end
@@ -5,11 +5,12 @@ module Radiator
5
5
  include Utils
6
6
 
7
7
  def initialize(options = {})
8
+ chain = options.delete(:chain) || :steem
8
9
  opt = options.dup
9
10
  @type = opt.delete(:type)
10
11
 
11
12
  opt.each do |k, v|
12
- instance_variable_set("@#{k}", type(@type, k, v))
13
+ instance_variable_set("@#{k}", type(chain, @type, k, v))
13
14
  end
14
15
 
15
16
  @use_condenser_namespace = if options.keys.include? :use_condenser_namespace
@@ -61,7 +62,7 @@ module Radiator
61
62
 
62
63
  params[p] = case v
63
64
  when Radiator::Type::Beneficiaries then [[0, v.to_h]]
64
- when Radiator::Type::Amount
65
+ when Hive::Type::Amount, Steem::Type::Amount
65
66
  if use_condenser_namespace?
66
67
  v.to_s
67
68
  else
@@ -4,18 +4,18 @@ module Radiator
4
4
  module OperationTypes
5
5
  TYPES = {
6
6
  transfer: {
7
- amount: Type::Amount
7
+ amount: Hive::Type::Amount
8
8
  },
9
9
  transfer_to_vesting: {
10
- amount: Type::Amount
10
+ amount: Hive::Type::Amount
11
11
  },
12
12
  withdraw_vesting: {
13
- vesting_shares: Type::Amount
13
+ vesting_shares: Hive::Type::Amount
14
14
  },
15
15
  limit_order_create: {
16
16
  orderid: Type::Uint32,
17
- amount_to_sell: Type::Amount,
18
- min_to_receive: Type::Amount,
17
+ amount_to_sell: Hive::Type::Amount,
18
+ min_to_receive: Hive::Type::Amount,
19
19
  expiration: Type::PointInTime
20
20
  },
21
21
  limit_order_cancel: {
@@ -26,10 +26,10 @@ module Radiator
26
26
  },
27
27
  convert: {
28
28
  requestid: Type::Uint32,
29
- amount: Type::Amount
29
+ amount: Hive::Type::Amount
30
30
  },
31
31
  account_create: {
32
- fee: Type::Amount,
32
+ fee: Hive::Type::Amount,
33
33
  owner: Type::Permission,
34
34
  active: Type::Permission,
35
35
  posting: Type::Permission,
@@ -51,7 +51,7 @@ module Radiator
51
51
  id: Type::Uint16
52
52
  },
53
53
  comment_options: {
54
- max_accepted_payout: Type::Amount,
54
+ max_accepted_payout: Hive::Type::Amount,
55
55
  allow_replies: Type::Future
56
56
  },
57
57
  set_withdraw_vesting_route: {
@@ -59,7 +59,7 @@ module Radiator
59
59
  },
60
60
  limit_order_create2: {
61
61
  orderid: Type::Uint32,
62
- amount_to_sell: Type::Amount,
62
+ amount_to_sell: Hive::Type::Amount,
63
63
  exchange_rate: Type::Price,
64
64
  expiration: Type::PointInTime
65
65
  },
@@ -71,10 +71,12 @@ module Radiator
71
71
  recent_owner_Permission: Type::Permission
72
72
  },
73
73
  escrow_transfer: {
74
- sbd_amount: Type::Amount,
75
- steem_amount: Type::Amount,
74
+ sbd_amount: Steem::Type::Amount,
75
+ hbd_amount: Hive::Type::Amount,
76
+ steem_amount: Steem::Type::Amount,
77
+ hive_amount: Hive::Type::Amount,
76
78
  escrow_id: Type::Uint32,
77
- fee: Type::Amount,
79
+ fee: Hive::Type::Amount,
78
80
  ratification_deadline: Type::PointInTime,
79
81
  escrow_expiration: Type::PointInTime
80
82
  },
@@ -83,40 +85,46 @@ module Radiator
83
85
  },
84
86
  escrow_release: {
85
87
  escrow_id: Type::Uint32,
86
- sbd_amount: Type::Amount,
87
- steem_amount: Type::Amount
88
+ sbd_amount: Steem::Type::Amount,
89
+ hbd_amount: Hive::Type::Amount,
90
+ steem_amount: Steem::Type::Amount,
91
+ hive_amount: Hive::Type::Amount
88
92
  },
89
93
  escrow_approve: {
90
94
  escrow_id: Type::Uint32
91
95
  },
92
96
  transfer_to_savings: {
93
- amount: Type::Amount
97
+ amount: Hive::Type::Amount
94
98
  },
95
99
  transfer_from_savings: {
96
100
  request_id: Type::Uint32,
97
- amount: Type::Amount
101
+ amount: Hive::Type::Amount
98
102
  },
99
103
  cancel_transfer_from_savings: {
100
104
  request_id: Type::Uint32
101
105
  },
102
106
  reset_account: {
103
- new_owner_permission: Type::Amount
107
+ new_owner_permission: Hive::Type::Amount
104
108
  },
105
109
  set_reset_account: {
106
- reward_steem: Type::Amount,
107
- reward_sbd: Type::Amount,
108
- reward_vests: Type::Amount
110
+ reward_steem: Steem::Type::Amount,
111
+ reward_hive: Hive::Type::Amount,
112
+ reward_sbd: Steem::Type::Amount,
113
+ reward_hbd: Hive::Type::Amount,
114
+ reward_vests: Hive::Type::Amount
109
115
  },
110
116
  claim_reward_balance: {
111
- reward_steem: Type::Amount,
112
- reward_sbd: Type::Amount,
113
- reward_vests: Type::Amount
117
+ reward_steem: Steem::Type::Amount,
118
+ reward_hive: Hive::Type::Amount,
119
+ reward_sbd: Steem::Type::Amount,
120
+ reward_hbd: Hive::Type::Amount,
121
+ reward_vests: Hive::Type::Amount
114
122
  },
115
123
  delegate_vesting_shares: {
116
- vesting_shares: Type::Amount
124
+ vesting_shares: Hive::Type::Amount
117
125
  },
118
126
  claim_account: {
119
- fee: Type::Amount
127
+ fee: Hive::Type::Amount
120
128
  },
121
129
  witness_update: {
122
130
  block_signing_key: Type::PublicKey,
@@ -127,13 +135,21 @@ module Radiator
127
135
  }
128
136
  }
129
137
 
130
- def type(key, param, value)
138
+ def type(chain, key, param, value)
131
139
  return if value.nil?
132
140
 
133
141
  t = TYPES[key] or return value
134
142
  p = t[param] or return value
135
143
 
136
- p.new(value)
144
+ if p == Hive::Type::Amount
145
+ case chain
146
+ when :steem then Steem::Type::Amount.new(value)
147
+ else
148
+ p.new(value)
149
+ end
150
+ else
151
+ p.new(value)
152
+ end
137
153
  end
138
154
  end
139
155
  end
@@ -7,6 +7,8 @@ module Radiator
7
7
  'User-Agent' => Radiator::AGENT_ID
8
8
  }
9
9
 
10
+ MAX_BACKOFF = 60.0
11
+
10
12
  def initialize(options = {})
11
13
  @root_url = options[:root_url] || 'https://api.steem-engine.com/rpc'
12
14
 
@@ -28,6 +30,12 @@ module Radiator
28
30
  true
29
31
  end
30
32
 
33
+ @persist = if options[:persist].nil?
34
+ true
35
+ else
36
+ options[:persist]
37
+ end
38
+
31
39
  if defined? Net::HTTP::Persistent::DEFAULT_POOL_SIZE
32
40
  @pool_size = options[:pool_size] || Net::HTTP::Persistent::DEFAULT_POOL_SIZE
33
41
  end
@@ -61,18 +69,24 @@ module Radiator
61
69
  end
62
70
 
63
71
  def http
64
- @http ||= if defined? Net::HTTP::Persistent::DEFAULT_POOL_SIZE
65
- Net::HTTP::Persistent.new(name: http_id, pool_size: @pool_size).tap do |http|
66
- http.keep_alive = 30
67
- http.idle_timeout = 10
68
- http.max_requests = @max_requests
69
- http.retry_change_requests = true
70
- http.reuse_ssl_sessions = @reuse_ssl_sessions
72
+ @http ||= if persist?
73
+ if defined? Net::HTTP::Persistent::DEFAULT_POOL_SIZE
74
+ Net::HTTP::Persistent.new(name: http_id, pool_size: @pool_size).tap do |http|
75
+ http.keep_alive = 30
76
+ http.idle_timeout = 10
77
+ http.max_requests = @max_requests
78
+ http.retry_change_requests = true if defined? http.retry_change_requests
79
+ http.reuse_ssl_sessions = @reuse_ssl_sessions
80
+ end
81
+ else
82
+ # net-http-persistent < 3.0
83
+ Net::HTTP::Persistent.new(http_id) do |http|
84
+ http = Net::HTTP.new(uri.host, uri.port)
85
+ http.use_ssl = uri.scheme == 'https'
86
+ end
71
87
  end
72
88
  else
73
- # net-http-persistent < 3.0
74
- Net::HTTP::Persistent.new(http_id) do |http|
75
- http = Net::HTTP.new(uri.host, uri.port)
89
+ Net::HTTP.new(uri.host, uri.port).tap do |http|
76
90
  http.use_ssl = uri.scheme == 'https'
77
91
  end
78
92
  end
@@ -84,8 +98,27 @@ module Radiator
84
98
 
85
99
  def request(options)
86
100
  request = post_request
101
+ skip_health_check = options.delete(:skip_health_check)
87
102
  request.body = JSON[options.merge(jsonrpc: '2.0', id: rpc_id)]
88
103
 
104
+ unless skip_health_check
105
+ unless healthy?
106
+ @backoff ||= 0.1
107
+
108
+ backoff = @backoff
109
+
110
+ if !!backoff
111
+ raise "Too many failures on #{url}" if backoff >= MAX_BACKOFF
112
+
113
+ backoff *= backoff
114
+ @backoff = backoff
115
+ sleep backoff
116
+ end
117
+ end
118
+
119
+ @backoff = nil
120
+ end
121
+
89
122
  response = case http
90
123
  when Net::HTTP::Persistent then http.request(uri, request)
91
124
  when Net::HTTP then http.request(request)
@@ -100,6 +133,15 @@ module Radiator
100
133
 
101
134
  response.result
102
135
  end
136
+
137
+ def healthy?
138
+ warn("Health check not defined for: #{uri}")
139
+ true
140
+ end
141
+
142
+ def persist?
143
+ !!@persist
144
+ end
103
145
  end
104
146
  end
105
147
  end
@@ -42,6 +42,16 @@ module Radiator
42
42
  def transaction_info(trx_id)
43
43
  request(method: 'getTransactionInfo', params: {txid: trx_id})
44
44
  end
45
+ protected
46
+ def healthy?
47
+ begin
48
+ request(method: 'getBlockInfo', params: {blockNumber: -1}, skip_health_check: true).nil?
49
+ rescue => e
50
+ warn("Health check for #{uri.inspect} failed: #{e.inspect}")
51
+
52
+ !!shutdown
53
+ end
54
+ end
45
55
  end
46
56
  end
47
57
  end
@@ -66,6 +66,23 @@ module Radiator
66
66
  def find(options = {})
67
67
  request(method: 'find', params: options)
68
68
  end
69
+ protected
70
+ def healthy?
71
+ begin
72
+ request(method: 'find', params: {
73
+ contract: 'tokens',
74
+ table: 'transfers',
75
+ query: {
76
+ symbol: ''
77
+ },
78
+ limit: 0
79
+ }, skip_health_check: true).nil?
80
+ rescue => e
81
+ warn("Health check for #{uri.inspect} failed: #{e.inspect}")
82
+
83
+ !!shutdown
84
+ end
85
+ end
69
86
  end
70
87
  end
71
88
  end
@@ -258,7 +258,7 @@ module Radiator
258
258
  break if stop?
259
259
 
260
260
  catch :sequence do; begin
261
- head_block = api.get_dynamic_global_properties do |properties, error|
261
+ head_block = database_api.get_dynamic_global_properties do |properties, error|
262
262
  if !!error
263
263
  standby "Node responded with: #{error.message || 'unknown error'}, retrying ...", {
264
264
  error: error,
@@ -268,7 +268,7 @@ module Radiator
268
268
 
269
269
  break if stop?
270
270
 
271
- if properties.head_block_number.nil?
271
+ if properties.nil? || properties.head_block_number.nil?
272
272
  # This can happen if a reverse proxy is acting up.
273
273
  standby "Bad block sequence after height: #{latest_block_number}", {
274
274
  and: {throw: :sequence}
@@ -281,7 +281,7 @@ module Radiator
281
281
  else; raise StreamError, '"mode" has to be "head" or "irreversible"'
282
282
  end
283
283
  end
284
-
284
+
285
285
  if head_block == latest_block_number
286
286
  # This can happen when there's a delay in block production.
287
287
 
@@ -390,6 +390,7 @@ module Radiator
390
390
 
391
391
  @api = nil
392
392
  @block_api = nil
393
+ @database_api = nil if @api.nil? || @block_api.nil?
393
394
  GC.start
394
395
  end
395
396
 
@@ -435,6 +436,14 @@ module Radiator
435
436
  else; nil
436
437
  end
437
438
  end
439
+
440
+ def database_api
441
+ @database_api ||= case @chain
442
+ when :steem then Steem::DatabaseApi.new(url: @api.send(:uri).to_s)
443
+ when :hive then Hive::DatabaseApi.new(url: @api.send(:uri).to_s)
444
+ else; api
445
+ end
446
+ end
438
447
  private
439
448
  def method_missing(m, *args, &block)
440
449
  super unless respond_to_missing?(m)
@@ -445,11 +454,11 @@ module Radiator
445
454
  break if stop?
446
455
 
447
456
  value = if (n = method_params(m)).nil?
448
- key_value = api.get_dynamic_global_properties.result[m]
457
+ key_value = database_api.get_dynamic_global_properties.result[m]
449
458
  else
450
459
  key = n.keys.first
451
460
  if !!n[key]
452
- r = api.get_dynamic_global_properties.result
461
+ r = database_api.get_dynamic_global_properties.result
453
462
  key_value = param = r[n[key]]
454
463
  result = nil
455
464
  loop do
@@ -466,7 +475,7 @@ module Radiator
466
475
  reset_timeout
467
476
  result
468
477
  else
469
- key_value = api.get_dynamic_global_properties.result[key]
478
+ key_value = database_api.get_dynamic_global_properties.result[key]
470
479
  end
471
480
  end
472
481
  unless @latest_values.include? key_value
@@ -81,6 +81,11 @@ module Radiator
81
81
 
82
82
  case chain.to_s.downcase.to_sym
83
83
  when :steem then NETWORKS_STEEM_CHAIN_ID
84
+ when :hive
85
+ database_api = Hive::DatabaseApi.new(url: @url)
86
+ database_api.get_config do |config|
87
+ config['HIVE_CHAIN_ID']
88
+ end rescue nil || NETWORKS_HIVE_CHAIN_ID
84
89
  when :test then NETWORKS_TEST_CHAIN_ID
85
90
  end
86
91
  end
@@ -88,6 +93,7 @@ module Radiator
88
93
  def url
89
94
  case chain.to_s.downcase.to_sym
90
95
  when :steem then NETWORKS_STEEM_DEFAULT_NODE
96
+ when :hive then NETWORKS_HIVE_DEFAULT_NODE
91
97
  when :test then NETWORKS_TEST_DEFAULT_NODE
92
98
  end
93
99
  end
@@ -114,6 +120,26 @@ module Radiator
114
120
  else
115
121
  self
116
122
  end
123
+ rescue OperationError => e
124
+ trx_builder, network_api = case @chain.to_sym
125
+ when :steem then [
126
+ Steem::TransactionBuilder.new(wif: @wif),
127
+ Steem::NetworkBroadcastApi.new(url: @url)
128
+ ]
129
+ when :hive then [
130
+ Hive::TransactionBuilder.new(wif: @wif),
131
+ Hive::NetworkBroadcastApi.new(url: @url)
132
+ ]
133
+ end
134
+
135
+ raise e if trx_builder.nil?
136
+
137
+ @operations.each do |op|
138
+ type = op.delete(:type)
139
+ trx_builder.put({type => op})
140
+ end
141
+
142
+ network_api.broadcast_transaction_synchronous(trx_builder.transaction)
117
143
  ensure
118
144
  shutdown
119
145
  end
@@ -122,7 +148,7 @@ module Radiator
122
148
  @operations = @operations.map do |op|
123
149
  case op
124
150
  when Operation then op
125
- else; Operation.new(op)
151
+ else; Operation.new(op.merge(chain: @chain))
126
152
  end
127
153
  end
128
154
  end
@@ -147,6 +173,19 @@ module Radiator
147
173
  def use_condenser_namespace?
148
174
  !!@use_condenser_namespace
149
175
  end
176
+
177
+ def inspect
178
+ properties = %w(
179
+ url ref_block_num ref_block_prefix expiration chain
180
+ use_condenser_namespace immutable_expiration payload
181
+ ).map do |prop|
182
+ if !!(v = instance_variable_get("@#{prop}"))
183
+ "@#{prop}=#{v}"
184
+ end
185
+ end.compact.join(', ')
186
+
187
+ "#<#{self.class.name} [#{properties}]>"
188
+ end
150
189
  private
151
190
  def broadcast_payload(payload)
152
191
  if use_condenser_namespace?
@@ -238,6 +277,7 @@ module Radiator
238
277
  bytes << op.to_bytes
239
278
  end
240
279
 
280
+ # FIXME Should pakC(0) instead?
241
281
  bytes << 0x00 # extensions
242
282
 
243
283
  bytes