Class: LiabilityProof::Tree::LeafNode

Inherits:
Struct
  • Object
show all
Includes:
Node
Defined in:
lib/liability-proof/tree/leaf_node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Node

#as_json, #as_user_json, #decimal_to_digits, #sum_string

Constructor Details

#initialize(user, sum, nonce, hash = nil) ⇒ LeafNode

Returns a new instance of LeafNode.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
16
# File 'lib/liability-proof/tree/leaf_node.rb', line 7

def initialize(user, sum, nonce, hash=nil)
  raise ArgumentError, "sum must be BigDecimal" unless sum.is_a?(BigDecimal)

  super(user, sum, nonce)
  self.hash  = hash || generate_hash

  if user && hash && nonce
    raise ArgumentError, "Hash doesn't match" if generate_hash != hash
  end
end

Instance Attribute Details

#hashObject

Returns the value of attribute hash

Returns:

  • (Object)

    the current value of hash



4
5
6
# File 'lib/liability-proof/tree/leaf_node.rb', line 4

def hash
  @hash
end

#nonceObject

Returns the value of attribute nonce

Returns:

  • (Object)

    the current value of nonce



4
5
6
# File 'lib/liability-proof/tree/leaf_node.rb', line 4

def nonce
  @nonce
end

#sumObject

Returns the value of attribute sum

Returns:

  • (Object)

    the current value of sum



4
5
6
# File 'lib/liability-proof/tree/leaf_node.rb', line 4

def sum
  @sum
end

#userObject

Returns the value of attribute user

Returns:

  • (Object)

    the current value of user



4
5
6
# File 'lib/liability-proof/tree/leaf_node.rb', line 4

def user
  @user
end