Class: Ethereum::IpcClient

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

Constant Summary

Constants inherited from Client

Client::RPC_COMMANDS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Client

#clear_batch, #get_id

Constructor Details

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



6
7
8
9
10
11
12
13
14
# File 'lib/ethereum/ipc_client.rb', line 6

def initialize(ipcpath = "#{ENV['HOME']}/.ethereum/geth.ipc", log = true)
  @ipcpath = ipcpath
  @id = 1
  @batch = []
  @log = log
  if @log == true
    @logger = Logger.new("/tmp/ethereum_ruby_ipc.log")
  end
end

Instance Attribute Details

#batchObject

Returns the value of attribute batch.



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

def batch
  @batch
end

#commandObject

Returns the value of attribute command.



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

def command
  @command
end

#converted_transactionsObject

Returns the value of attribute converted_transactions.



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

def converted_transactions
  @converted_transactions
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#ipcpathObject

Returns the value of attribute ipcpath.



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

def ipcpath
  @ipcpath
end

#logObject

Returns the value of attribute log.



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

def log
  @log
end

#loggerObject

Returns the value of attribute logger.



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

def logger
  @logger
end

Instance Method Details

#send_batchObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ethereum/ipc_client.rb', line 43

def send_batch
  socket = UNIXSocket.new(@ipcpath)
  socket.write(@batch.join(" "))
  socket.close_write
  read = socket.read
  collection = read.chop.split("}{").collect do |output|
    if output[0] == "{"
      JSON.parse("#{output}}")["result"]
    else
      JSON.parse("{#{output}}")["result"]
    end
  end
  return collection
end