Class: Multichain::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/multichain/cli.rb

Instance Method Summary collapse

Instance Method Details

#dehexify(hex) ⇒ Object



18
19
20
# File 'lib/multichain/cli.rb', line 18

def dehexify hex
  puts Encoder.dehexify hex
end

#hexify(url) ⇒ Object



12
13
14
# File 'lib/multichain/cli.rb', line 12

def hexify url
  puts Encoder.hexify url
end

#send_url(recipient, url) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/multichain/cli.rb', line 40

def send_url recipient, url
  data = Client.new.send_url recipient, url
  out = "You sent '#{url}' to '#{recipient}'\n"
  out << "\n"
  out << "The transaction id is\n"
  out << "  #{data[:id]}\n"
  out << "\n"
  out << "The URL\n"
  out << "  #{url}\n"
  out << "hashed to\n"
  out << "  #{data[:hash]}\n"
  out << "at\n"
  out << "  #{Time.at(data[:timestamp].to_i).to_datetime}\n"
  out << "\n"
  out << "Verify the hash with\n"
  out << "  multichain verify #{data[:hex]}\n"

  puts out
end

#verify(hex) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/multichain/cli.rb', line 24

def verify hex
  url = Encoder.extract(Encoder.dehexify(hex))[:url]
  v = Encoder.verify hex

  case v
    when true
      puts "The URL '#{url}' is verified"
      exit 0 unless ENV['TEST']

    when false
      puts "The URL '#{url}' is not verified"
      exit 1 unless ENV['TEST']
  end
end

#versionObject



6
7
8
# File 'lib/multichain/cli.rb', line 6

def version
  puts "multichain version #{VERSION}"
end