Class: Ethereum::IpcClient
- Inherits:
-
Client
- Object
- Client
- Ethereum::IpcClient
- Defined in:
- lib/ethereumex/ipc_client.rb
Instance Attribute Summary collapse
-
#ipcpath ⇒ Object
Returns the value of attribute ipcpath.
Instance Method Summary collapse
-
#initialize(ipcpath = "#{ENV['HOME']}/.ethereum/geth.ipc", log = false) ⇒ IpcClient
constructor
A new instance of IpcClient.
-
#send_batch(batch) ⇒ Object
TODO: Not sure if multithread safe Note: Guarantees the results are in the same order as defined in batch call.
- #send_single(payload) ⇒ Object
Constructor Details
#initialize(ipcpath = "#{ENV['HOME']}/.ethereum/geth.ipc", log = false) ⇒ IpcClient
Returns a new instance of IpcClient.
6 7 8 9 |
# File 'lib/ethereumex/ipc_client.rb', line 6 def initialize(ipcpath = "#{ENV['HOME']}/.ethereum/geth.ipc", log = false) super(log) @ipcpath = ipcpath end |
Instance Attribute Details
#ipcpath ⇒ Object
Returns the value of attribute ipcpath.
4 5 6 |
# File 'lib/ethereumex/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/ethereumex/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/ethereumex/ipc_client.rb', line 11 def send_single(payload) socket = UNIXSocket.new(@ipcpath) socket.puts(payload) read = socket.gets socket.close return read end |