Class: Ciri::P2P::NodeID

Inherits:
Object
  • Object
show all
Defined in:
lib/ciri/p2p/node.rb

Overview

present node id

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(public_key) ⇒ NodeID

Returns a new instance of NodeID.



43
44
45
46
47
48
# File 'lib/ciri/p2p/node.rb', line 43

def initialize(public_key)
  unless public_key.is_a?(Ciri::Key)
    raise TypeError.new("expect Ciri::Key but get #{public_key.class}")
  end
  @public_key = public_key
end

Instance Attribute Details

#public_keyObject (readonly) Also known as: key

Returns the value of attribute public_key.



39
40
41
# File 'lib/ciri/p2p/node.rb', line 39

def public_key
  @public_key
end

Class Method Details

.from_raw_id(raw_id) ⇒ Object



34
35
36
# File 'lib/ciri/p2p/node.rb', line 34

def from_raw_id(raw_id)
  NodeID.new(Ciri::Key.new(raw_public_key: "\x04".b + raw_id))
end

Instance Method Details

#==(other) ⇒ Object



56
57
58
# File 'lib/ciri/p2p/node.rb', line 56

def == (other)
  self.class == other.class && id == other.id
end

#idObject Also known as: to_bytes



50
51
52
# File 'lib/ciri/p2p/node.rb', line 50

def id
  @id ||= key.raw_public_key[1..-1]
end

#short_hexObject



66
67
68
# File 'lib/ciri/p2p/node.rb', line 66

def short_hex
  @short_hex ||= to_hex[0..8]
end

#to_hexObject Also known as: to_s



60
61
62
# File 'lib/ciri/p2p/node.rb', line 60

def to_hex
  Ciri::Utils.to_hex id
end