Class: Ethereum::IpcClient

Inherits:
Client
  • Object
show all
Defined in:
lib/ethereum/ipc_client.rb

Constant Summary

Constants inherited from Client

Client::RPC_COMMANDS, Client::RPC_MANAGEMENT_COMMANDS

Instance Attribute Summary collapse

Attributes inherited from Client

#command, #id, #log, #logger

Instance Method Summary collapse

Methods inherited from Client

#batch, #get_id, #reset_id

Constructor Details

#initialize(ipcpath = "#{ENV['HOME']}/.ethereum/geth.ipc", log = false) ⇒ IpcClient

Returns a new instance of IpcClient


6
7
8
9
# File 'lib/ethereum/ipc_client.rb', line 6

def initialize(ipcpath = "#{ENV['HOME']}/.ethereum/geth.ipc", log = false)
  super(log)
  @ipcpath = ipcpath
end

Instance Attribute Details

#ipcpathObject

Returns the value of attribute ipcpath


4
5
6
# File 'lib/ethereum/ipc_client.rb', line 4

def ipcpath
  @ipcpath
end

Instance Method Details

#send_batch(batch) ⇒ Object

TODO: Not sure if multithread safe Note: Guarantees the results are in the same order as defined in batch call. client.batch do

client.eth_block_number
client.eth_mining

end

> [“id”=>1, “result”=>“0x26”, “id”=>2, “result”=>false]


26
27
28
29
30
31
32
33
# File 'lib/ethereum/ipc_client.rb', line 26

def send_batch(batch)
  result = send_single(batch.to_json)
  result = JSON.parse(result)

  # Make sure the order is the same as it was when batching calls
  # See 6 Batch here http://www.jsonrpc.org/specification
  return result.sort_by! { |c| c['id'] }
end

#send_single(payload) ⇒ Object


11
12
13
14
15
16
17
# File 'lib/ethereum/ipc_client.rb', line 11

def send_single(payload)
  socket = UNIXSocket.new(@ipcpath)
  socket.puts(payload)
  read = socket.gets
  socket.close
  return read
end