radiator 0.3.0 → 0.3.1

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
  SHA1:
3
- metadata.gz: 5df9b0fd593b559881d44bfd81cffa32831e9ab9
4
- data.tar.gz: 0c1b4ab039cbf26d896477d45a7b817ea2978265
3
+ metadata.gz: 1f5f2643bbb6354a779623e8f20d7be5f5d83249
4
+ data.tar.gz: 327db2a8c46cd416de62ed449fac46af45333f54
5
5
  SHA512:
6
- metadata.gz: ef6d2abbaea8e67b695bcfd6ab0fd845f65afc09b9ce396b48bea316f49d5f2650890f70826e4bbde2527aae02adb2e8f493473e6144a6663e550195c1ac7dd6
7
- data.tar.gz: 3bcd4169779d4e88e7d23ea713ef94378b41ba0e6bb6b885e4a1ceec8f7b76007a5e1d7cf21bc86b776d2fb57c4b275aa2fe58f2472e42ef6e7d468357266954
6
+ metadata.gz: d0bbb1950e374f28f15f532b6839bf93c39436e489fef70c22cea2cb77e2e94bc7fd6d184d5199aa7235be07cf917a04b42aded9eca185d1c33786131af7b05c
7
+ data.tar.gz: 02c0666cdb6eaa058826608e630a3f4baf5ce89c3116e401d6d608a695132a6242a5c72fd0ee61d42f5a883558929132428f2e3bc70989016cdfa46f28439ad8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- radiator (0.3.0)
4
+ radiator (0.3.1)
5
5
  bitcoin-ruby (= 0.0.11)
6
6
  ffi (= 1.9.18)
7
7
  hashie (~> 3.5, >= 3.5.5)
data/README.md CHANGED
@@ -376,7 +376,7 @@ tx.process(true)
376
376
  Radiator also supports Golos. To use the Golos blockchain, provide a node and chain_id:
377
377
 
378
378
  ```ruby
379
- tx = Radiator::Transaction.new(wif: 'Your Wif Here', chain: :golos, url: 'https://node.golos.ws')
379
+ tx = Radiator::Transaction.new(wif: 'Your Wif Here', chain: :golos, url: 'https://ws.golos.io')
380
380
  vote = {
381
381
  type: :vote,
382
382
  voter: 'xeroc',
data/lib/radiator/api.rb CHANGED
@@ -131,10 +131,12 @@ module Radiator
131
131
  # @see https://steemit.github.io/steemit-docs/#accounts
132
132
  #
133
133
  class Api
134
- DEFAULT_URL = 'https://steemd.steemit.com'
134
+ DEFAULT_STEEM_URL = 'https://steemd.steemit.com'
135
135
 
136
- DEFAULT_FAILOVER_URLS = [
137
- DEFAULT_URL,
136
+ DEFAULT_GOLOS_URL = 'https://ws.golos.io'
137
+
138
+ DEFAULT_STEEM_FAILOVER_URLS = [
139
+ DEFAULT_STEEM_URL,
138
140
  'https://steemd-int.steemit.com',
139
141
  'https://steemd.steemitstage.com',
140
142
  'https://gtg.steem.house:8090',
@@ -144,11 +146,35 @@ module Radiator
144
146
  'https://rpc.steemliberator.com'
145
147
  ]
146
148
 
149
+ DEFAULT_GOLOS_FAILOVER_URLS = [
150
+ DEFAULT_GOLOS_URL
151
+ ]
152
+
147
153
  # @private
148
154
  POST_HEADERS = {
149
155
  'Content-Type' => 'application/json'
150
156
  }
151
157
 
158
+ # These are known SSL versions supported by:
159
+ # https://github.com/ruby/openssl/blob/master/lib/openssl/ssl.rb
160
+ SSL_VERSIONS = [:TLSv1_2, :TLSv1_1, :TLSv1, :SSLv3, :SSLv2, :SSLv23]
161
+
162
+ def self.default_url(chain)
163
+ case chain.to_sym
164
+ when :steem then DEFAULT_STEEM_URL
165
+ when :golos then DEFAULT_GOLOS_URL
166
+ else; raise ApiError, "Unsupported chain: #{chain}"
167
+ end
168
+ end
169
+
170
+ def self.default_failover_urls(chain)
171
+ case chain.to_sym
172
+ when :steem then DEFAULT_STEEM_FAILOVER_URLS
173
+ when :golos then DEFAULT_GOLOS_FAILOVER_URLS
174
+ else; raise ApiError, "Unsupported chain: #{chain}"
175
+ end
176
+ end
177
+
152
178
  # Cretes a new instance of Radiator::Api.
153
179
  #
154
180
  # Examples:
@@ -164,16 +190,18 @@ module Radiator
164
190
  def initialize(options = {})
165
191
  @user = options[:user]
166
192
  @password = options[:password]
167
- @url = options[:url] || DEFAULT_URL
193
+ @chain = options[:chain] || :steem
194
+ @url = options[:url] || Api::default_url(@chain)
168
195
  @preferred_url = @url.dup
169
196
  @failover_urls = options[:failover_urls]
170
197
  @debug = !!options[:debug]
171
198
  @logger = options[:logger] || Radiator.logger
172
199
  @hashie_logger = options[:hashie_logger] || Logger.new(nil)
173
200
  @max_requests = options[:max_requests] || 30
201
+ @ssl_version = nil # default
174
202
 
175
203
  if @failover_urls.nil?
176
- @failover_urls = DEFAULT_FAILOVER_URLS - [@url]
204
+ @failover_urls = Api::default_failover_urls(@chain) - [@url]
177
205
  end
178
206
 
179
207
  @failover_urls = [@failover_urls].flatten.compact
@@ -191,7 +219,7 @@ module Radiator
191
219
 
192
220
  Hashie.logger = @hashie_logger
193
221
  @method_names = nil
194
- @api_options = options.dup
222
+ @api_options = options.dup.merge(chain: @chain)
195
223
  end
196
224
 
197
225
  # Get a specific block or range of blocks.
@@ -419,7 +447,8 @@ module Radiator
419
447
  rescue RangeError => e
420
448
  warning 'Range Error, retrying ...', method_name
421
449
  rescue OpenSSL::SSL::SSLError => e
422
- warning "SSL Error (#{e.message}), retrying ...", method_name
450
+ @ssl_version = SSL_VERSIONS.sample
451
+ warning "SSL Error (#{e.message}), switching to #{@ssl_version} and retrying ...", method_name
423
452
  rescue SocketError => e
424
453
  warning "Socket Error (#{e.message}), retrying ...", method_name
425
454
  rescue JSON::ParserError => e
@@ -485,7 +514,13 @@ module Radiator
485
514
  http.idle_timeout = idempotent ? 10 : nil
486
515
  http.max_requests = @max_requests
487
516
  http.retry_change_requests = idempotent
488
- http.reuse_ssl_sessions = !flappy?
517
+
518
+ if flappy?
519
+ http.reuse_ssl_sessions = false
520
+ http.ssl_version = @ssl_version
521
+ else
522
+ http.reuse_ssl_sessions = true
523
+ end
489
524
  end
490
525
  end
491
526
 
@@ -573,7 +608,7 @@ module Radiator
573
608
  @backoff_sleep *= 2
574
609
  sleep @backoff_sleep
575
610
 
576
- if Time.now - @backoff_at > 300
611
+ if !!@backoff_at && Time.now - @backoff_at > 300
577
612
  @backoff_at = nil
578
613
  @backoff_sleep = nil
579
614
  end
@@ -15,7 +15,7 @@ module Radiator
15
15
  NETWORKS_GOLOS_CORE_ASSET = 'GOLOS'
16
16
  NETWORKS_GOLOS_DEBT_ASSET = 'GBG'
17
17
  NETWORKS_GOLOS_VEST_ASSET = 'GESTS'
18
- NETWORKS_GOLOS_DEFAULT_NODE = 'https://node.golos.ws'
18
+ NETWORKS_GOLOS_DEFAULT_NODE = 'https://ws.golos.io'
19
19
 
20
20
  NETWORKS_TEST_CHAIN_ID = '18dcf0a285365fc58b71f18b3d3fec954aa0c141c44e4e5cb4cf777b9eab274e'
21
21
  NETWORKS_TEST_ADDRESS_PREFIX = 'TST'
@@ -24,8 +24,7 @@ module Radiator
24
24
  MAX_BLOCKS_PER_NODE = 100
25
25
 
26
26
  def initialize(options = {})
27
- @api_options = options.dup
28
- @logger = @api_options[:logger] || Radiator.logger
27
+ super
29
28
  end
30
29
 
31
30
  # Returns the latest operations from the blockchain.
@@ -43,7 +43,7 @@ module Radiator
43
43
  @private_key = Bitcoin::Key.from_base58 wif
44
44
  end
45
45
 
46
- options = options.merge(url: @url)
46
+ options = options.merge(url: @url, chain: @chain)
47
47
  @api = Api.new(options)
48
48
  @network_broadcast_api = NetworkBroadcastApi.new(options)
49
49
  end
@@ -1,3 +1,3 @@
1
1
  module Radiator
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radiator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Martin