Module: LiabilityProof::Tree::Node

Included in:
InternalNode, LeafNode
Defined in:
lib/liability-proof/tree/node.rb

Instance Method Summary collapse

Instance Method Details

#as_jsonObject



6
7
8
# File 'lib/liability-proof/tree/node.rb', line 6

def as_json
  { 'sum' => sum_string, 'hash' => hash }
end

#as_user_jsonObject



10
11
12
# File 'lib/liability-proof/tree/node.rb', line 10

def as_user_json
  { 'sum' => sum_string, 'nonce' => nonce, 'user' => user }
end

#decimal_to_digits(d) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/liability-proof/tree/node.rb', line 18

def decimal_to_digits(d)
  _, significant_digits, _, exponent = d.split
  if d.zero?
    '0'
  elsif exponent >= significant_digits.size
    d.to_i.to_s
  else
    d.to_s('F')
  end
end

#sum_stringObject



14
15
16
# File 'lib/liability-proof/tree/node.rb', line 14

def sum_string
  decimal_to_digits sum
end