class MerkleTree::Leaf

An object to hold one-time signature @api private

Attributes

height[R]
left_index[R]
right_index[R]
value[RW]

Public Class Methods

build(value, position, digest: MerkleTree.default_digest) click to toggle source
# File lib/merkle_tree/leaf.rb, line 17
def self.build(value, position, digest: MerkleTree.default_digest)
  new(digest.(value), position, position)
end
new(value, left_index, right_index) click to toggle source

Create a leaf node

@api private

# File lib/merkle_tree/leaf.rb, line 24
def initialize(value, left_index, right_index)
  @value = value
  @left_index = left_index
  @right_index = right_index
  @height = 0
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/merkle_tree/leaf.rb, line 43
def <=>(other)
  value <=> other.value &&
    left_index <=> other.left_index &&
    right_index <=> other.right_index
end
include?(index) click to toggle source
# File lib/merkle_tree/leaf.rb, line 35
def include?(index)
  (left_index..right_index).cover?(index)
end
leaf?() click to toggle source
# File lib/merkle_tree/leaf.rb, line 31
def leaf?
  true
end
size() click to toggle source
# File lib/merkle_tree/leaf.rb, line 39
def size
  1
end
to_h() click to toggle source
# File lib/merkle_tree/leaf.rb, line 49
def to_h
  { value: value }
end
to_s(indent = "") click to toggle source
# File lib/merkle_tree/leaf.rb, line 53
def to_s(indent = "")
  indent + value
end