Class: EPM::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/epm/query.rb

Instance Method Summary collapse

Constructor Details

#initialize(address, position, settings = {}) ⇒ Query

Returns a new instance of Query.



5
6
7
8
9
10
# File 'lib/epm/query.rb', line 5

def initialize address, position, settings={}
  @uri      = URI.parse "http://localhost:#{settings['json-port']}"
  setup settings
  @address  = EPM::HexData.hex_guard address
  @position = EPM::HexData.query_guard position
end

Instance Method Details

#queryObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/epm/query.rb', line 12

def query
  if @settings['preferred-client'] == 'cpp'
    params = {
      'a' => @address,
      'x' => @position
    }
    post_body = { 'method' => 'storageAt', 'params' => params, 'id' => 'epm-rpc', "jsonrpc" => "2.0" }.to_json
  elsif @settings['preferred-client'] == ('go' || 'ethereal')
    params = {
      'address' => @address,
      'key' => @position
    }
    post_body = { 'method' => 'EthereumApi.GetStorageAt', 'params' => params, 'id' => 'epm-rpc', "jsonrpc" => "2.0" }.to_json
  end
  return EPM::Server.http_post_request @uri, post_body
end

#setup(settings) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/epm/query.rb', line 29

def setup settings
  unless settings.empty?
    @settings = settings
  else
    @settings = EPM::Settings.check
  end
end