11require 'block_io/version'
22require 'httpclient'
33require 'oj'
4- require 'oj_mimic_json'
54require 'connection_pool'
65require 'ecdsa'
76require 'openssl'
@@ -25,7 +24,7 @@ def self.set_options(args = {})
2524 @pin = args [ :pin ]
2625 @encryptionKey = Helper . pinToAesKey ( @pin ) if !@pin . nil?
2726
28- @conn_pool = ConnectionPool . new ( size : 1 , timeout : 300 ) { HTTPClient . new }
27+ @conn_pool = ConnectionPool . new ( size : 1 , timeout : 300 ) { h = HTTPClient . new ; h . tcp_keepalive = true ; h . ssl_config . ssl_version = :auto ; h }
2928
3029 @version = args [ :version ] || 2 # default version is 2
3130
@@ -78,7 +77,7 @@ def self.withdraw(args = {}, method_name = 'withdraw')
7877 Helper . signData ( inputs , [ key ] )
7978
8079 # the response object is now signed, let's stringify it and finalize this withdrawal
81- response = self . api_call ( [ 'sign_and_finalize_withdrawal' , { :signature_data => response [ 'data' ] . to_json } ] )
80+ response = self . api_call ( [ 'sign_and_finalize_withdrawal' , { :signature_data => Oj . dump ( response [ 'data' ] ) } ] )
8281
8382 # if we provided all the required signatures, this transaction went through
8483 # otherwise Block.io responded with data asking for more signatures
@@ -111,7 +110,7 @@ def self.sweep(args = {}, method_name = 'sweep_from_address')
111110 Helper . signData ( inputs , [ key ] )
112111
113112 # the response object is now signed, let's stringify it and finalize this withdrawal
114- response = self . api_call ( [ 'sign_and_finalize_sweep' , { :signature_data => response [ 'data' ] . to_json } ] )
113+ response = self . api_call ( [ 'sign_and_finalize_sweep' , { :signature_data => Oj . dump ( response [ 'data' ] ) } ] )
115114
116115 # if we provided all the required signatures, this transaction went through
117116 # otherwise Block.io responded with data asking for more signatures
@@ -132,11 +131,10 @@ def self.api_call(endpoint)
132131 @conn_pool . with do |hc |
133132 # prevent initiation of HTTPClients every time we make this call, use a connection_pool
134133
135- hc . ssl_config . ssl_version = :TLSv1
136134 response = hc . post ( "#{ @base_url . gsub ( 'API_CALL' , endpoint [ 0 ] ) . gsub ( 'VERSION' , 'v' +@version . to_s ) + @api_key } " , endpoint [ 1 ] )
137135
138136 begin
139- body = JSON . parse ( response . body )
137+ body = Oj . load ( response . body )
140138 raise Exception . new ( body [ 'data' ] [ 'error_message' ] ) if !body [ 'status' ] . eql? ( 'success' )
141139 rescue
142140 raise Exception . new ( 'Unknown error occurred. Please report this.' )
0 commit comments