Module: C3D::EthRunner

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

Instance Method Summary collapse

Instance Method Details

#eth_processObject



87
88
89
90
91
92
93
94
# File 'lib/c3d/util/processes.rb', line 87

def eth_process
  if is_eth_running?
    a = `ps ux`.split("\n").select{|e| e[/eth .*--json-rpc-port/]}[0].split(" ")[1]
    return a
  else
    return false
  end
end

#is_eth_running?Boolean

Returns:

  • (Boolean)


82
83
84
85
# File 'lib/c3d/util/processes.rb', line 82

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

#start_ethereum(settings) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/c3d/util/processes.rb', line 51

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 = ENV['ETH_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 15
    at_exit { Process.kill("INT", pid) }
  end
end