Class: Peatio::Eos::Client
- Inherits:
-
Object
- Object
- Peatio::Eos::Client
- Extended by:
- Memoist
- Defined in:
- lib/ultex/eos/client.rb
Defined Under Namespace
Classes: ConnectionError, ResponseError
Constant Summary collapse
- Error =
Class.new(StandardError)
Instance Method Summary collapse
-
#initialize(endpoint, idle_timeout: 500) ⇒ Client
constructor
A new instance of Client.
- #json_rpc(path, params = nil, port = nil) ⇒ Object
Constructor Details
#initialize(endpoint, idle_timeout: 500) ⇒ Client
Returns a new instance of Client.
21 22 23 24 |
# File 'lib/ultex/eos/client.rb', line 21 def initialize(endpoint, idle_timeout: 500) @rpc_endpoint = URI.parse(endpoint) @idle_timeout = idle_timeout end |
Instance Method Details
#json_rpc(path, params = nil, port = nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ultex/eos/client.rb', line 26 def json_rpc(path, params=nil, port=nil) # We need to communicate with keosd to sign transaction, # keosd is running on non default eos port which is 8900 # and passed to json_rpc function when we sign transaction rpc = URI.parse(@rpc_endpoint.to_s) rpc.port = (port.present? ? port : @rpc_endpoint.port) response = connection(rpc).post do |req| req.url path # To communicate with keosd to sign transaction we need to pass Host param with keosd port req.headers["Host"] = "0.0.0.0:#{port}" if port.present? req.headers["Content-Type"] = "application/json" req.body = params.to_json if params.present? req..timeout = 120 end response.assert_success! response = JSON.parse(response.body) return response if response.is_a?(Array) # get balance call return an array response["error"].tap {|error| raise ResponseError.new(error["code"], error["message"]) if error } response rescue Faraday::Error => e raise ConnectionError, e rescue StandardError => e raise Error, e end |