Class: Bitshares::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/bitshares/client.rb

Defined Under Namespace

Classes: Err

Class Method Summary collapse

Class Method Details

.initObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/bitshares/client.rb', line 7

def self.init
  bitshares_running?
  user = ENV['BITSHARES_ACCOUNT']
  password = ENV['BITSHARES_PASSWORD']
  @uri = URI("http://localhost:#{rpc_http_port}/rpc")
  @req = Net::HTTP::Post.new(@uri)
  @req.content_type = 'application/json'
  @req.basic_auth user, password
  return self
end

.method_missing(m, *args) ⇒ Object



22
23
24
# File 'lib/bitshares/client.rb', line 22

def self.method_missing(m, *args)
  self.request(m, args)
end

.request(m, args = []) ⇒ Object

Raises:



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/bitshares/client.rb', line 26

def self.request(m, args = [])
  resp = nil
  Net::HTTP.start(@uri.hostname, @uri.port) do |http|
    @req.body = { method: m, params: args, jsonrpc: '2.0', id: 0 }.to_json
    resp = http.request(@req)
  end
  raise Err, 'Bad credentials' if resp.class == Net::HTTPUnauthorized
  result = JSON.parse(resp.body)
  e = result['error']
  raise Err, JSON.pretty_generate(e), "#{m} #{args.join(' ') if args}" if e
  return result['result']
end

.synced?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/bitshares/client.rb', line 18

def self.synced?
  blockchain_get_block_count >= self.get_info['blockchain_head_block_num']
end