29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/cardano-up/ping.rb', line 29
def self.node(session_name, env)
CardanoUp::Configs.exist?(env)
CardanoUp::Session.network_or_raise?(session_name, env.to_sym)
CardanoUp::Session.node_or_raise?(session_name, env.to_sym)
session = CardanoUp::Session.get(session_name)
bin_dir = CardanoUp.config[:bin_dir]
ENV['CARDANO_NODE_SOCKET_PATH'] = session[env.to_sym][:node][:socket_path]
protocol_magic = session[env.to_sym][:node][:protocol_magic]
network_arg = env == 'mainnet' ? '--mainnet' : "--testnet-magic #{protocol_magic}"
exe = CardanoUp::Utils.win? ? '.exe' : ''
cmd = "#{File.join(bin_dir, 'cardano-cli')}#{exe} query tip #{network_arg}"
res = CardanoUp::Utils.cmd cmd
begin
r = JSON.parse(res)
c = 200
rescue JSON::ParserError
r = 'Not responding.'
c = 404
end
[r, c]
end
|