Module: Nis::Util

Defined in:
lib/nis/util.rb,
lib/nis/util/convert.rb,
lib/nis/util/ed25519.rb,
lib/nis/util/assignable.rb,
lib/nis/util/serializer.rb,
lib/nis/util/deserializer.rb

Defined Under Namespace

Modules: Assignable, Convert, Deserializer, Ed25519, Serializer

Constant Summary collapse

MIJIN =
0x60000000
TESTNET =

-1744830464

0x98000000
MAINNET =

1744830464

0x68000000
VERSION_1 =

1

0x00000001
VERSION_2 =

2

0x00000002
TESTNET_VERSION_1 =

0x98000001 = -1744830463

TESTNET | VERSION_1
TESTNET_VERSION_2 =

0x98000002 = -1744830462

TESTNET | VERSION_2
MAINNET_VERSION_1 =

0x68000001 = 1744830465

MAINNET | VERSION_1
MAINNET_VERSION_2 =

0x68000002 = 1744830466

MAINNET | VERSION_2
NEM_EPOCH =
Time.utc(2015, 3, 29, 0, 6, 25, 0)

Class Method Summary collapse

Class Method Details

.deadline(seconds = 3600) ⇒ Object



33
34
35
# File 'lib/nis/util.rb', line 33

def self.deadline(seconds = 3600)
  timestamp + seconds
end

.error_handling(hash) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/nis/util.rb', line 41

def self.error_handling(hash)
  error_klass = case hash[:error]
                when 'Not Found' then Nis::NotFoundError
                when 'Bad Request' then Nis::BadRequestError
                when 'Internal Server Error' then Nis::InternalServerError
                else Nis::Error
  end
  error_klass.new(hash[:message])
end

.parse_nemtime(nemtime) ⇒ Object



29
30
31
# File 'lib/nis/util.rb', line 29

def self.parse_nemtime(nemtime)
  NEM_EPOCH + nemtime
end

.parse_network(network) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/nis/util.rb', line 20

def self.parse_network(network)
  case network
  when :mijin then MIJIN
  when :mainnet then MAINNET
  when :testnet then TESTNET
    else TESTNET
  end
end

.parse_version(network, version) ⇒ Object



16
17
18
# File 'lib/nis/util.rb', line 16

def self.parse_version(network, version)
  parse_network(network) | version
end

.timestampObject



37
38
39
# File 'lib/nis/util.rb', line 37

def self.timestamp
  (Time.now.utc - NEM_EPOCH).to_i
end