blockchain-lite 1.2.0 → 1.3.0
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/README.md +7 -9
- data/Rakefile +1 -0
- data/lib/blockchain-lite.rb +3 -0
- data/lib/blockchain-lite/basic/block.rb +1 -3
- data/lib/blockchain-lite/proof_of_work/block.rb +5 -3
- data/lib/blockchain-lite/version.rb +1 -1
- data/test/test_blockchain.rb +4 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b722f05bc1278363432a4645667ea2f1f6beb135
|
4
|
+
data.tar.gz: ecb976219a2e0f7b9ff8ad90a8f7ebd60d9ba052
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d56f16148e7706e848183a94f4a6133f88b26591e34db1c3e024ab4dd0b8e7a5d94d8711101962bfc5108d52de8711ca9fe00dbf418a8bbb218dc01817d78ab9
|
7
|
+
data.tar.gz: 861642febb265b139bf25e4da9d305cbabf28be8797a918e9834ddf00204d68fa9cb70df5a302c88052ce550107d4680db44d41ecf0321dc6530ba7277775781
|
data/README.md
CHANGED
@@ -48,21 +48,21 @@ will pretty print (pp) something like:
|
|
48
48
|
@hash = "edbd4e11e69bc399a9ccd8faaea44fb27410fe8e3023bb9462450a0a9c4caa1b">,
|
49
49
|
#<Block:0x1eec9a0
|
50
50
|
@index = 1,
|
51
|
-
@timestamp = 2017-09-15
|
51
|
+
@timestamp = 2017-09-15 21:02:38,
|
52
52
|
@transactions_count = 1,
|
53
53
|
@transactions = ["Transaction Data..."],
|
54
54
|
@hash = "eb8ecbf6d5870763ae246e37539d82e37052cb32f88bb8c59971f9978e437743",
|
55
55
|
@previous_hash = "edbd4e11e69bc399a9ccd8faaea44fb27410fe8e3023bb9462450a0a9c4caa1b">,
|
56
56
|
#<Block:0x1eec838
|
57
57
|
@index = 2,
|
58
|
-
@timestamp = 2017-09-15
|
58
|
+
@timestamp = 2017-09-15 21:12:38,
|
59
59
|
@transactions_count = 1,
|
60
60
|
@transactions = ["Transaction Data..."],
|
61
61
|
@hash = "be50017ee4bbcb33844b3dc2b7c4e476d46569b5df5762d14ceba9355f0a85f4",
|
62
62
|
@previous_hash = "eb8ecbf6d5870763ae246e37539d82e37052cb32f88bb8c59971f9978e437743">,
|
63
63
|
#<Block:0x1eec6d0
|
64
64
|
@index = 3,
|
65
|
-
@timestamp = 2017-09-15
|
65
|
+
@timestamp = 2017-09-15 21:22:38
|
66
66
|
@transactions_count = 1,
|
67
67
|
@transactions = ["Transaction Data..."],
|
68
68
|
@hash = "5ee2981606328abfe0c3b1171440f0df746c1e1f8b3b56c351727f7da7ae5d8d",
|
@@ -100,10 +100,8 @@ class Block
|
|
100
100
|
|
101
101
|
def calc_hash
|
102
102
|
sha = Digest::SHA256.new
|
103
|
-
sha.update( @
|
104
|
-
@timestamp.to_s +
|
103
|
+
sha.update( @timestamp.to_s +
|
105
104
|
@transactions.to_s +
|
106
|
-
@transactions_count.to_s +
|
107
105
|
@previous_hash )
|
108
106
|
sha.hexdigest
|
109
107
|
end
|
@@ -123,6 +121,7 @@ class Block
|
|
123
121
|
attr_reader :timestamp
|
124
122
|
attr_reader :transactions_count
|
125
123
|
attr_reader :transactions
|
124
|
+
attr_reader :transactions_hash ## merkle_root
|
126
125
|
attr_reader :previous_hash
|
127
126
|
attr_reader :nonce ## proof of work if hash starts with leading zeros (00)
|
128
127
|
attr_reader :hash
|
@@ -132,6 +131,7 @@ class Block
|
|
132
131
|
@timestamp = Time.now.utc ## note: use coordinated universal time (utc)
|
133
132
|
@transactions = transactions
|
134
133
|
@transactions_count = transactions.size
|
134
|
+
@transactions_hash = MerkleTree.compute_root_for( transactions )
|
135
135
|
@previous_hash = previous_hash
|
136
136
|
@nonce, @hash = compute_hash_with_proof_of_work
|
137
137
|
end
|
@@ -139,10 +139,8 @@ class Block
|
|
139
139
|
def calc_hash
|
140
140
|
sha = Digest::SHA256.new
|
141
141
|
sha.update( @nonce.to_s +
|
142
|
-
@index.to_s +
|
143
142
|
@timestamp.to_s +
|
144
|
-
@
|
145
|
-
@transactions_count.to_s +
|
143
|
+
@transactions_hash +
|
146
144
|
@previous_hash )
|
147
145
|
sha.hexdigest
|
148
146
|
end
|
data/Rakefile
CHANGED
data/lib/blockchain-lite.rb
CHANGED
@@ -10,6 +10,7 @@ class Block
|
|
10
10
|
attr_reader :timestamp
|
11
11
|
attr_reader :transactions_count # use alias - txn_count - why? why not?
|
12
12
|
attr_reader :transactions # use alias - txn - why? why not?
|
13
|
+
attr_reader :transactions_hash # use alias - merkle_root - why? why not?
|
13
14
|
attr_reader :previous_hash
|
14
15
|
attr_reader :nonce # ("lucky" number used once) - proof of work if hash starts with leading zeros (00)
|
15
16
|
attr_reader :hash
|
@@ -21,6 +22,9 @@ class Block
|
|
21
22
|
@transactions = transactions
|
22
23
|
@transactions_count = transactions.size
|
23
24
|
|
25
|
+
## todo: add empty array check to merkletree.compute why? why not?
|
26
|
+
@transactions_hash = transactions.empty? ? '0' : MerkleTree.compute_root_for( transactions )
|
27
|
+
|
24
28
|
@previous_hash = previous_hash
|
25
29
|
|
26
30
|
## note: use coordinated universal time (utc)
|
@@ -68,10 +72,8 @@ private
|
|
68
72
|
def calc_hash_with_nonce( nonce=0 )
|
69
73
|
sha = Digest::SHA256.new
|
70
74
|
sha.update( nonce.to_s +
|
71
|
-
@index.to_s +
|
72
75
|
@timestamp.to_s +
|
73
|
-
@
|
74
|
-
@transactions_count.to_s +
|
76
|
+
@transactions_hash +
|
75
77
|
@previous_hash )
|
76
78
|
sha.hexdigest
|
77
79
|
end
|
data/test/test_blockchain.rb
CHANGED
@@ -61,7 +61,10 @@ def test_wrap
|
|
61
61
|
assert_equal true, b.valid?
|
62
62
|
|
63
63
|
## corrupt data in block in chain
|
64
|
-
b2.instance_eval
|
64
|
+
b2.instance_eval <<RUBY
|
65
|
+
@transactions = ['xxxxxx']
|
66
|
+
@transactions_hash = MerkleTree.compute_root_for( @transactions )
|
67
|
+
RUBY
|
65
68
|
|
66
69
|
assert_equal true, b.broken?
|
67
70
|
assert_equal false, b.valid?
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blockchain-lite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: merkletree
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rdoc
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|