Module: EPM::Server
Instance Method Summary collapse
- #eth_processes ⇒ Object
- #http_post_request(uri, post_body) ⇒ Object
- #is_eth_running? ⇒ Boolean
- #start(debug = false) ⇒ Object
- #stop ⇒ Object
Instance Method Details
#eth_processes ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/epm/utils.rb', line 42 def eth_processes a = `ps ux`.split("\n").select{|e| e[/eth.* --json-rpc-port/]} # a << `ps ux`.split("\n").select{|e| e[/ethereum/]} a << `ps ux`.split("\n").select{|e| e[/ethereal/]} a = a.flatten return a end |
#http_post_request(uri, post_body) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/epm/utils.rb', line 50 def http_post_request uri, post_body unless is_eth_running? p "Ethereum RPC Server is not running. Starting now. Please be patient for it to load." start end http = Net::HTTP.new uri.host, uri.port request = Net::HTTP::Post.new uri.request_uri request.content_type = 'application/json' request.body = post_body result = JSON.parse(http.request(request).body)['result'] return result end |
#is_eth_running? ⇒ Boolean
37 38 39 40 |
# File 'lib/epm/utils.rb', line 37 def is_eth_running? eth = eth_processes return (! eth.empty?) end |
#start(debug = false) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/epm/utils.rb', line 7 def start debug=false settings = EPM::Settings.check if debug debug = '' else debug = '>> /dev/null' end unless is_eth_running? case settings['preferred-client'] when 'cpp' server = "#{settings["path-to-eth"]} --json-rpc-port #{settings['json-port']} -r #{settings["remote"]} -d #{settings["directory"]} -m off -l #{settings["eth-listen-port"]} -c #{settings["name"]} -s #{settings["address-private-key"]} #{debug}" when 'go' server = "#{settings['path-to-go-ethereum']}" when 'ethereal' server = "#{settings['path-to-ethereal']}" end pid = spawn server sleep 7 end return pid end |
#stop ⇒ Object
30 31 32 33 34 35 |
# File 'lib/epm/utils.rb', line 30 def stop if is_eth_running? processes = eth_processes.map{|e| e.split(' ')[1]} processes.each{|p| `kill #{p}`} end end |