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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd1a3709646aa06e6baf39c31146b46f6b0cada3
4
- data.tar.gz: 495c56c9e5a5e386183a19bf646966fd7c4287a5
3
+ metadata.gz: db5ca59224c57ebe11b02903e9dd708ae4886850
4
+ data.tar.gz: c95e4b04d3a91733924d48e8abd555f3451bde0d
5
5
  SHA512:
6
- metadata.gz: 3790c82513fa9d484040e5b830372d6d8dd33c2dd8dd91007922cb553ca48042acedfc444467f2d2fe66afce31bb489d1c07ce56b0bb294eeef397c0ae040ecc
7
- data.tar.gz: 86c04ed283e6e6fbfb54ed4e8f01e52122eed9832e6b04ea7bd3cdfc8df6e1955a79866a939f71a1a9037c2691313345206db94bdf3a1eb46a3024cec323ed85
6
+ metadata.gz: eb7225d8ef7cfe15823183e4c10850483b23cd5304c1e761772d55cfa631f0b62c8f43b1cdcad11913e2e646291ab82d518f33fe02f089ab4280098b066789be
7
+ data.tar.gz: 86f79282441b53e8ecd5718d223e6372a16c3e850b6627721fcc150d310b8fe6768c341d60c8ebd65907974184c43f2233f6efce722f290dcc870b17870bc0ea
data/bin/lproof CHANGED
@@ -29,6 +29,10 @@ opt_parser = OptionParser.new do |opt|
29
29
  options[:partial_trees_dir] = d
30
30
  end
31
31
 
32
+ opt.on("-c", "--currency code", "Specify the currency code, used by root.json.") do |c|
33
+ options[:currency] = c
34
+ end
35
+
32
36
  end
33
37
 
34
38
  opt_parser.parse!
@@ -1,7 +1,7 @@
1
1
  module LiabilityProof
2
2
  class Tree
3
3
 
4
- class InteriorNode < Struct.new(:left, :right, :sum, :hash)
4
+ class InternalNode < Struct.new(:left, :right, :sum, :hash)
5
5
  include ::LiabilityProof::Tree::Node
6
6
 
7
7
  def initialize(left, right)
@@ -7,6 +7,10 @@ module LiabilityProof
7
7
  { 'sum' => sum_string, 'hash' => hash }
8
8
  end
9
9
 
10
+ def as_user_json
11
+ { 'sum' => sum_string, 'nonce' => nonce, 'user' => user }
12
+ end
13
+
10
14
  def sum_string
11
15
  decimal_to_digits sum
12
16
  end
@@ -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 :InteriorNode, 'liability-proof/tree/interior_node'
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
- h = { 'data' => nil }
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] = { 'data' => nil }
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 ? InteriorNode.new(left, right) : left
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
@@ -58,7 +58,7 @@ module LiabilityProof
58
58
  else
59
59
  left = reduce node['left']
60
60
  right = reduce node['right']
61
- Tree::InteriorNode.new(left, right)
61
+ Tree::InternalNode.new(left, right)
62
62
  end
63
63
  end
64
64
 
@@ -1,3 +1,3 @@
1
1
  module LiabilityProof
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  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.5
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-22 00:00:00.000000000 Z
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/interior_node.rb
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