Class: LiabilityProof::Tree
- Inherits:
-
Object
- Object
- LiabilityProof::Tree
show all
- Defined in:
- lib/liability-proof/tree.rb,
lib/liability-proof/tree/node.rb,
lib/liability-proof/tree/leaf_node.rb,
lib/liability-proof/tree/internal_node.rb
Defined Under Namespace
Modules: Node
Classes: InternalNode, LeafNode
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(accounts, options = {}) ⇒ Tree
Returns a new instance of Tree.
13
14
15
16
17
18
19
20
21
|
# File 'lib/liability-proof/tree.rb', line 13
def initialize(accounts, options={})
raise ArgumentError, 'accounts is empty' unless accounts && accounts.size > 0
@accounts = accounts
@root = generate
@indices = Hash[index_leaves(@root)]
@currency = options.delete(:currency) || 'BTC'
end
|
Instance Attribute Details
#root ⇒ Object
Returns the value of attribute root.
11
12
13
|
# File 'lib/liability-proof/tree.rb', line 11
def root
@root
end
|
Instance Method Details
#last_user_node ⇒ Object
41
42
43
|
# File 'lib/liability-proof/tree.rb', line 41
def last_user_node
@user_data
end
|
#partial(user) ⇒ Object
33
34
35
|
# File 'lib/liability-proof/tree.rb', line 33
def partial(user)
_partial user, @root, @indices[user].dup, {}
end
|
#partial_json(user) ⇒ Object
37
38
39
|
# File 'lib/liability-proof/tree.rb', line 37
def partial_json(user)
{ 'partial_tree' => partial(user) }
end
|
#root_json ⇒ Object
23
24
25
26
27
28
29
30
31
|
# File 'lib/liability-proof/tree.rb', line 23
def root_json
{ 'root' => {
'hash' => root.hash,
'sum' => root.sum_string
},
'currency' => @currency,
'timestamp' => Time.now.to_f*1000
}
end
|