Module: C3D::EthRunner

Extended by:
EthRunner
Included in:
EthRunner
Defined in:
lib/c3d/util/processes.rb

Instance Method Summary collapse

Instance Method Details

#is_eth_running?Boolean

Returns:

  • (Boolean)


59
60
61
62
# File 'lib/c3d/util/processes.rb', line 59

def is_eth_running?
  a = `ps ux`.split("\n").select{|e| e[/eth --json-rpc-port/]}
  return (! a.empty?)
end

#start_ethereum(settings) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/c3d/util/processes.rb', line 28

def start_ethereum settings
  unless is_eth_running?
    path = settings["path-to-eth"] || "/opt/cpp-ethereum/build/eth/eth"
    port = settings["eth_rpc_port"] || "9090"
    peer_port = settings["eth_peer_port"] || "30303"
    client_name = settings["eth_client_name"] || "c3d-headless"
    remote = settings["eth_remote"] || ""
    if remote != ""
      remote = "-r #{remote}"
    end
    dir = settings["blockchain_dir"] || ""
    if dir != ""
      dir = "-d #{dir}"
    end
    mine = settings["eth_mine"] || "off"
    if mine == ("off" || "false")
      mine = "-m off"
    elsif mine == ("on" || "true")
      mine = "-m on"
    end
    key = settings["primary_account_key"] || ""
    if key != ""
      key = "-s #{key}"
    end
    pid = spawn "#{path} --json-rpc-port #{port} -l #{peer_port} -c #{client_name} #{remote} #{dir} #{mine} #{key}"
    sleep 7
    at_exit { Process.kill("INT", pid) }
  end
end