Class: Ethereum::IpcClient

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

Constant Summary collapse

IPC_PATHS =
[
  "#{ENV['HOME']}/.parity/jsonrpc.ipc",
  "#{ENV['HOME']}/Library/Ethereum/geth.ipc",
  "#{ENV['HOME']}/Library/Ethereum/testnet/geth.ipc"
]

Constants inherited from Client

Client::RPC_COMMANDS, Client::RPC_MANAGEMENT_COMMANDS

Instance Attribute Summary collapse

Attributes inherited from Client

#command, #default_account, #id, #log, #logger

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Client

#batch, create, #encode_params, #get_id, #int_to_hex, #reset_id

Constructor Details

#initialize(ipcpath = nil, log = true) ⇒ IpcClient

Returns a new instance of IpcClient.



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

def initialize(ipcpath = nil, log = true)
  super(log)
  ipcpath ||= IpcClient.default_path
  @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

Class Method Details

.default_path(paths = IPC_PATHS) ⇒ Object



18
19
20
# File 'lib/ethereum/ipc_client.rb', line 18

def self.default_path(paths = IPC_PATHS)
  paths.select { |path| File.exist?(path) }.first || ""
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]



37
38
39
40
41
42
43
44
# File 'lib/ethereum/ipc_client.rb', line 37

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



22
23
24
25
26
27
28
# File 'lib/ethereum/ipc_client.rb', line 22

def send_single(payload)
  socket = UNIXSocket.new(@ipcpath)
  socket.puts(payload)
  read = socket.recvmsg(nil)[0]
  socket.close
  return read
end