Top Level Namespace

Includes:
Universa

Defined Under Namespace

Modules: Universa Classes: Hash, KeyTool, MessageException, UBox, USettings

Constant Summary

Constants included from Universa

Universa::ALNUMS, Universa::NUMBERS, Universa::VERSION

Instance Method Summary collapse

Methods included from Universa

#derive_key, dump_bytes, #retry_with_timeout

Instance Method Details

#error(message) ⇒ Object

Raises:



11
12
13
# File 'lib/universa/keytool/keytool.rb', line 11

def error message
  raise MessageException, message
end

#format_text_object(data, type, **kwargs) ⇒ String

Generate universa text object representation from arbitrary data, see kb.universablockchain.com/text_format_for_universa_objects/311 for details.

Parameters:

  • data (Object)

    binary string to pack as universa text object

  • type (Object)

    object type, see link above

  • kwargs (Hash)

    any additional fields

Returns:

  • (String)

    string with properly framed universa object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/universa/text_objects.rb', line 11

def format_text_object(data, type, **kwargs)
  source = ["type: #{type}"]
  kwargs.each { |k, v|
    source << "#{k}: #{v}"
  }
  source << ""
  source << Base64.encode64(data)
  hash = Digest::SHA2.base64digest(source.join(''))
  "==== Begin Universa Object: #{hash} ====\n" +
    source.join("\n") +
    "\n===== End Universa Object: #{hash} =====\n"
end

#human_to_i(value, factor = 1000) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/universa/keytool/keytool.rb', line 17

def human_to_i value, factor = 1000
  head, tail = value[0...-1], value[-1]
  case tail
    when 'k', 'K'
      head.to_i * 1000
    when 'M', 'm'
      head.to_i * factor * factor
    when 'G', 'g'
      head.to_i * factor * factor * factor
    else
      value.to_t
  end
end

#seconds_to_hms(seconds) ⇒ Object



31
32
33
34
35
# File 'lib/universa/keytool/keytool.rb', line 31

def seconds_to_hms seconds
  mm, ss = seconds.divmod(60)
  hh, mm = mm.divmod(60)
  "%d:%02d:%02d" % [hh, mm, ss]
end