Class: EvmClient::IpcClient

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

Constant Summary collapse

IPC_PATHS =
[
  "#{ENV['HOME']}/.parity/jsonrpc.ipc",
  "#{ENV['HOME']}/.openethereum/jsonrpc.ipc",
  "#{ENV['HOME']}/Library/Ethereum/geth.ipc",
  "#{ENV['HOME']}/Library/Ethereum/testnet/geth.ipc",
  "#{ENV['HOME']}/Library/Application\ Support/io.parity.ethereum/jsonrpc.ipc",
  "#{ENV['HOME']}/Library/Application\ Support/io.openethereum.ethereum/jsonrpc.ipc",
  "#{ENV['HOME']}/.local/share/parity/jsonrpc.ipc",
  "#{ENV['HOME']}/.local/share/io.parity.ethereum/jsonrpc.ipc",
  "#{ENV['HOME']}/AppData/Roaming/Parity/Ethereum/jsonrpc.ipc",
  "#{ENV['HOME']}/.local/share/openethereum/jsonrpc.ipc",
  "#{ENV['HOME']}/.local/share/io.openethereum.ethereum/jsonrpc.ipc",
  "#{ENV['HOME']}/AppData/Roaming/openethereum/Ethereum/jsonrpc.ipc",
  "#{ENV['HOME']}/.ethereum/geth.ipc",
  "#{ENV['HOME']}/.ethereum/testnet/geth.ipc"
]

Constants inherited from Client

Client::DEFAULT_BLOCK_NUMBER, Client::DEFAULT_GAS_LIMIT, Client::DEFAULT_GAS_PRICE, Client::RPC_COMMANDS, Client::RPC_MANAGEMENT_COMMANDS

Instance Attribute Summary collapse

Attributes inherited from Client

#block_number, #command, #default_account, #gas_limit, #gas_price, #id, #log, #logger

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Client

#batch, create, #encode_params, #get_balance, #get_chain, #get_id, #get_nonce, #int_to_hex, #reset_id, #send_command, #transfer, #transfer_and_wait, #transfer_to, #transfer_to_and_wait, #wait_for

Constructor Details

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

Returns a new instance of IpcClient.



23
24
25
26
27
# File 'lib/evm_client/ipc_client.rb', line 23

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/evm_client/ipc_client.rb', line 4

def ipcpath
  @ipcpath
end

Class Method Details

.default_path(paths = IPC_PATHS) ⇒ Object



29
30
31
32
# File 'lib/evm_client/ipc_client.rb', line 29

def self.default_path(paths = IPC_PATHS)
  path = paths.find { |path| File.exist?(path) }
  path || raise("Ipc file not found. Please pass in the file path explicitly to IpcClient initializer")
end

Instance Method Details

#send_batch(batch) ⇒ Object

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]



48
49
50
51
52
53
54
55
# File 'lib/evm_client/ipc_client.rb', line 48

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



34
35
36
37
38
39
40
# File 'lib/evm_client/ipc_client.rb', line 34

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