liability-proof 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/lproof +4 -0
- data/lib/liability-proof/tree/{interior_node.rb → internal_node.rb} +1 -1
- data/lib/liability-proof/tree/node.rb +4 -0
- data/lib/liability-proof/tree.rb +18 -15
- data/lib/liability-proof/verifier.rb +1 -1
- data/lib/liability-proof/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db5ca59224c57ebe11b02903e9dd708ae4886850
|
4
|
+
data.tar.gz: c95e4b04d3a91733924d48e8abd555f3451bde0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb7225d8ef7cfe15823183e4c10850483b23cd5304c1e761772d55cfa631f0b62c8f43b1cdcad11913e2e646291ab82d518f33fe02f089ab4280098b066789be
|
7
|
+
data.tar.gz: 86f79282441b53e8ecd5718d223e6372a16c3e850b6627721fcc150d310b8fe6768c341d60c8ebd65907974184c43f2233f6efce722f290dcc870b17870bc0ea
|
data/bin/lproof
CHANGED
data/lib/liability-proof/tree.rb
CHANGED
@@ -6,7 +6,7 @@ module LiabilityProof
|
|
6
6
|
|
7
7
|
autoload :Node, 'liability-proof/tree/node'
|
8
8
|
autoload :LeafNode, 'liability-proof/tree/leaf_node'
|
9
|
-
autoload :
|
9
|
+
autoload :InternalNode, 'liability-proof/tree/internal_node'
|
10
10
|
|
11
11
|
attr :root, :indices
|
12
12
|
|
@@ -16,18 +16,22 @@ module LiabilityProof
|
|
16
16
|
@accounts = accounts
|
17
17
|
@root = generate
|
18
18
|
@indices = Hash[index_leaves(@root)]
|
19
|
+
|
20
|
+
@currency = options.delete(:currency) || 'BTC'
|
19
21
|
end
|
20
22
|
|
21
23
|
def root_json
|
22
24
|
{ 'root' => {
|
23
25
|
'hash' => root.hash,
|
24
|
-
'sum' => root.sum_string
|
26
|
+
'sum' => root.sum_string
|
27
|
+
},
|
28
|
+
'currency' => @currency,
|
29
|
+
'timestamp' => rfc822_format(Time.now)
|
30
|
+
}
|
25
31
|
end
|
26
32
|
|
27
33
|
def partial(user)
|
28
|
-
|
29
|
-
_partial user, @root, @indices[user].dup, h
|
30
|
-
h
|
34
|
+
_partial user, @root, @indices[user].dup, {}
|
31
35
|
end
|
32
36
|
|
33
37
|
def partial_json(user)
|
@@ -38,14 +42,7 @@ module LiabilityProof
|
|
38
42
|
|
39
43
|
def _partial(user, node, index, acc)
|
40
44
|
if node.is_a?(LeafNode)
|
41
|
-
acc['data'] = node.as_json
|
42
|
-
|
43
|
-
if node.user == user
|
44
|
-
acc['data'].merge!({
|
45
|
-
'user' => user,
|
46
|
-
'nonce' => node.nonce
|
47
|
-
})
|
48
|
-
end
|
45
|
+
acc['data'] = node.user == user ? node.as_user_json : node.as_json
|
49
46
|
else
|
50
47
|
follow_direction = index.shift
|
51
48
|
other_direction = follow_direction == :left ? :right : :left
|
@@ -53,9 +50,11 @@ module LiabilityProof
|
|
53
50
|
other_child = node.send other_direction
|
54
51
|
|
55
52
|
acc[other_direction.to_s] = { 'data' => other_child.as_json }
|
56
|
-
acc[follow_direction.to_s] = {
|
53
|
+
acc[follow_direction.to_s] = {}
|
57
54
|
_partial user, follow_child, index, acc[follow_direction.to_s]
|
58
55
|
end
|
56
|
+
|
57
|
+
acc
|
59
58
|
end
|
60
59
|
|
61
60
|
def generate
|
@@ -80,7 +79,7 @@ module LiabilityProof
|
|
80
79
|
parents = nodes.each_slice(2).map do |(left, right)|
|
81
80
|
# if right is not nil, return combined interior node;
|
82
81
|
# otherwise keep the left leaf node
|
83
|
-
right ?
|
82
|
+
right ? InternalNode.new(left, right) : left
|
84
83
|
end
|
85
84
|
|
86
85
|
combine parents
|
@@ -98,5 +97,9 @@ module LiabilityProof
|
|
98
97
|
end
|
99
98
|
end
|
100
99
|
|
100
|
+
def rfc822_format(time)
|
101
|
+
time.strftime("%a, %d %b %Y %H:%M:%S %z")
|
102
|
+
end
|
103
|
+
|
101
104
|
end
|
102
105
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: liability-proof
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peatio Opensource
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|
@@ -38,7 +38,7 @@ files:
|
|
38
38
|
- lib/liability-proof/generator.rb
|
39
39
|
- lib/liability-proof/pretty_printer.rb
|
40
40
|
- lib/liability-proof/tree.rb
|
41
|
-
- lib/liability-proof/tree/
|
41
|
+
- lib/liability-proof/tree/internal_node.rb
|
42
42
|
- lib/liability-proof/tree/leaf_node.rb
|
43
43
|
- lib/liability-proof/tree/node.rb
|
44
44
|
- lib/liability-proof/verifier.rb
|