@@ -30,6 +30,8 @@ def self.[](currency)
30
30
name = 'CNT'
31
31
elsif c . proto == 'FNT'
32
32
name = 'FNT'
33
+ elsif c . proto == 'TOU'
34
+ name = 'TOU'
33
35
else
34
36
name = c [ :handler ]
35
37
end
@@ -253,6 +255,55 @@ def getblockchaininfo
253
255
end
254
256
end
255
257
258
+ class TOU < self
259
+ def handle ( name , *args )
260
+ post_body = { "jsonrpc" => "2.0" , 'method' => name , 'params' => args , 'id' => '1' } . to_json
261
+ Rails . logger . info "TOU " + post_body
262
+ resp = JSON . parse ( http_post_request ( post_body ) )
263
+ Rails . logger . info resp
264
+ raise JSONRPCError , resp [ 'error' ] if resp [ 'error' ]
265
+ result = resp [ 'result' ]
266
+ if result == nil
267
+ return result
268
+ end
269
+ result . symbolize_keys! if result . is_a? Hash
270
+ result
271
+ end
272
+ def http_post_request ( post_body )
273
+ http = Net ::HTTP . new ( @uri . host , @uri . port )
274
+ request = Net ::HTTP ::Post . new ( @uri . request_uri )
275
+ request . basic_auth @uri . user , @uri . password
276
+ request . content_type = 'application/json'
277
+ request . body = post_body
278
+ @reply = http . request ( request ) . body
279
+ # Rails.logger.info @reply
280
+ return @reply
281
+ rescue Errno ::ECONNREFUSED => e
282
+ raise ConnectionRefusedError
283
+ end
284
+
285
+ def safe_getbalance
286
+ begin
287
+ #Rails.logger.info @rest + " -> " + "#{@rest}/cgi-bin/total.cgi"
288
+ ( open ( "#{ @rest } /cgi-bin/total.cgi" ) . read . rstrip . to_f )
289
+ rescue => ex
290
+ Rails . logger . info "[error]: " + ex . message + "\n " + ex . backtrace . join ( "\n " ) + "\n "
291
+ 'N/A'
292
+ end
293
+ end
294
+
295
+ def getblockchaininfo
296
+ @lastBlock = eth_getBlockByNumber ( "latest" , true )
297
+ #Rails.logger.info @lastBlock
298
+ #Rails.logger.info "number = " + Integer(@lastBlock[:number]).to_s + ", timestamp = " + Integer(@lastBlock[:timestamp]).to_s
299
+
300
+ {
301
+ blocks : Integer ( @lastBlock [ :number ] ) ,
302
+ headers : 0 ,
303
+ mediantime : Integer ( @lastBlock [ :timestamp ] )
304
+ }
305
+ end
306
+ end
256
307
class LISK < self
257
308
def handle ( name , *args )
258
309
post_body = { "jsonrpc" => "2.0" , 'method' => name , 'params' => args , 'id' => '1' } . to_json
0 commit comments