Class: Ethmo::IPCSocket

Inherits:
UNIXSocket
  • Object
show all
Defined in:
lib/ethmo/ipc_socket.rb

Overview

:nodoc;

Constant Summary collapse

VERSION =
'2.0'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ IPCSocket

Returns a new instance of IPCSocket.



17
18
19
20
21
# File 'lib/ethmo/ipc_socket.rb', line 17

def initialize(path)
  @buffer = ''
  @id = self.class.next_id
  super
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



15
16
17
# File 'lib/ethmo/ipc_socket.rb', line 15

def id
  @id
end

Class Method Details

.next_idObject



7
8
9
10
# File 'lib/ethmo/ipc_socket.rb', line 7

def next_id
  @id ||= 1
  @id += 1
end

Instance Method Details

#exec(method, *params) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/ethmo/ipc_socket.rb', line 23

def exec(method, *params)
  send({
    id: id,
    jsonrpc: VERSION,
    method: method,
    params: params
  }.to_json, 0)
end

#readObject



32
33
34
35
# File 'lib/ethmo/ipc_socket.rb', line 32

def read
  @buffer = @buffer.to_s + recv(1024) until @buffer.to_s.include?("\n")
  (_, @buffer = @buffer.to_s.split("\n", 2)).first
end