Module: CardanoUp::Ping

Defined in:
lib/cardano-up/ping.rb

Overview

Check status (ping) of running node and wallet services

Class Method Summary collapse

Class Method Details

.node(session_name, env) ⇒ Object

Parameters:

  • session_name (String)
  • env (String)

Raises:

  • CardanoUp::EnvNotSupportedError

  • CardanoUp::SessionNotExistsError

  • CardanoUp::SessionServiceNotUpError

  • CardanoUp::SessionEnvNotUpError



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

.wallet(session_name, env) ⇒ Object

Parameters:

  • session_name (String)
  • env (String)

Raises:

  • CardanoUp::EnvNotSupportedError

  • CardanoUp::SessionNotExistsError

  • CardanoUp::SessionServiceNotUpError

  • CardanoUp::SessionEnvNotUpError



12
13
14
15
16
17
18
19
20
21
# File 'lib/cardano-up/ping.rb', line 12

def self.wallet(session_name, env)
  CardanoUp::Configs.exist?(env)
  CardanoUp::Session.network_or_raise?(session_name, env.to_sym)
  CardanoUp::Session.wallet_or_raise?(session_name, env.to_sym)
  session = CardanoUp::Session.get(session_name)

  url = session[env.to_sym][:wallet][:url]
  r = HTTParty.get("#{url}/network/information")
  [r.parsed_response, r.code]
end