blockchain-lite 1.1.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e7543889414d4d92f12f6f5bfe9d708ba12c0093
4
- data.tar.gz: 96017ba92283640a77ed3be91d52721f1e245791
2
+ SHA256:
3
+ metadata.gz: c23e20fae718239734cf599d73beded949a12312de4fc2535769fadaa71ca77e
4
+ data.tar.gz: 82dd5188d90c78c80f767ddb0be664d1bce6800fdebf80cd4723dec8b6440e20
5
5
  SHA512:
6
- metadata.gz: 9648bcb18e39173799709aef395c346f63ff4fe6fdff824199cc0934b3b2ade710e5ef6e11e1a802d7d435cdb2ee3d905bc4bf28efbcafe64e94c3b154198d10
7
- data.tar.gz: 9b0ca66ac0656b65bc3179387ba7b9818313f94ec7e6d7f25b6ac2cb54ed57a492be7a2a37a13a813a7c6ca9550b7e50c22e3bb0268d8a4c2284d62847079b0d
6
+ metadata.gz: 45e04027704febb2ee957b1547343a1b0829868a2256ea74d1656f7f79895d0b6d3862be2b546793372315ba4508d766c79993bf087a9a7b65acfd16102906d6
7
+ data.tar.gz: 073a34f50dbcb36da1d1a0e20268cfe3ca96e89f5e7f27cf195f3430e3dba5b4a631d662164d5db52b7c2f66ebf90104c5567474c8d8411bf06128a31c8036c1
@@ -1,3 +1,3 @@
1
- ### 0.0.1 / 2017-09-16
2
-
3
- * Everything is new. First release
1
+ ### 0.0.1 / 2017-09-16
2
+
3
+ * Everything is new. First release
@@ -1,12 +1,11 @@
1
- HISTORY.md
2
- LICENSE.md
1
+ CHANGELOG.md
3
2
  Manifest.txt
4
3
  README.md
5
4
  Rakefile
6
5
  lib/blockchain-lite.rb
6
+ lib/blockchain-lite/base.rb
7
7
  lib/blockchain-lite/basic/block.rb
8
8
  lib/blockchain-lite/bitcoin/block.rb
9
- lib/blockchain-lite/block.rb
10
9
  lib/blockchain-lite/blockchain.rb
11
10
  lib/blockchain-lite/proof_of_work/block.rb
12
11
  lib/blockchain-lite/version.rb
@@ -15,3 +14,4 @@ test/test_block.rb
15
14
  test/test_block_basic.rb
16
15
  test/test_block_proof_of_work.rb
17
16
  test/test_blockchain.rb
17
+ test/test_version.rb
data/README.md CHANGED
@@ -1,197 +1,310 @@
1
- # Blockchain Lite (Ruby Edition)
2
-
3
- blockchain-lite library / gem - build your own blockchain with crypto hashes - revolutionize the world with blockchains, blockchains, blockchains one block at a time
4
-
5
- * home :: [github.com/openblockchains/blockchain.lite.rb](https://github.com/openblockchains/blockchain.lite.rb)
6
- * bugs :: [github.com/openblockchains/blockchain.lite.rb/issues](https://github.com/openblockchains/blockchain.lite.rb/issues)
7
- * gem :: [rubygems.org/gems/blockchain-lite](https://rubygems.org/gems/blockchain-lite)
8
- * rdoc :: [rubydoc.info/gems/blockchain-lite](http://rubydoc.info/gems/blockchain-lite)
9
-
10
-
11
- ## What's a Blockchain?
12
-
13
- > A blockchain is a distributed database -
14
- > a list (that is, chain) of records (that is, blocks)
15
- > linked and secured by digital fingerprints
16
- > (that is, hashes also known as (one-way) crypto(graphic) hash digest checksums).
17
-
18
- See the [Awesome Blockchains](https://github.com/openblockchains/awesome-blockchains) page for more.
19
-
20
-
21
- ## Usage
22
-
23
- Let's get started. Build your own blockchain one block at a time.
24
- Example:
25
-
26
- ``` ruby
27
- require 'blockchain-lite'
28
-
29
- b0 = Block.first( 'Genesis' )
30
- b1 = Block.next( b0, 'Transaction Data...' )
31
- b2 = Block.next( b1, 'Transaction Data......' )
32
- b3 = Block.next( b2, 'More Transaction Data...' )
33
-
34
- blockchain = [b0, b1, b2, b3]
35
-
36
- pp blockchain
37
-
38
- ######
39
- # will pretty print (pp) something like:
40
- #
41
- # [#<Block:0x1eed2a0
42
- # @index = 0,
43
- # @timestamp = 2017-09-15 20:52:38,
44
- # @data = "Genesis",
45
- # @previous_hash = "0",
46
- # @hash ="edbd4e11e69bc399a9ccd8faaea44fb27410fe8e3023bb9462450a0a9c4caa1b">,
47
- # #<Block:0x1eec9a0
48
- # @index = 1,
49
- # @timestamp = 2017-09-15 20:52:38,
50
- # @data = "Transaction Data...",
51
- # @hash = "eb8ecbf6d5870763ae246e37539d82e37052cb32f88bb8c59971f9978e437743",
52
- # @previous_hash = "edbd4e11e69bc399a9ccd8faaea44fb27410fe8e3023bb9462450a0a9c4caa1b">,
53
- # #<Block:0x1eec838
54
- # @index = 2,
55
- # @timestamp = 2017-09-15 20:52:38,
56
- # @data = "Transaction Data......",
57
- # @hash = "be50017ee4bbcb33844b3dc2b7c4e476d46569b5df5762d14ceba9355f0a85f4",
58
- # @previous_hash = "eb8ecbf6d5870763ae246e37539d82e37052cb32f88bb8c59971f9978e437743">,
59
- # #<Block:0x1eec6d0
60
- # @index = 3,
61
- # @timestamp = 2017-09-15 20:52:38
62
- # @data = "More Transaction Data...",
63
- # @hash = "5ee2981606328abfe0c3b1171440f0df746c1e1f8b3b56c351727f7da7ae5d8d",
64
- # @previous_hash = "be50017ee4bbcb33844b3dc2b7c4e476d46569b5df5762d14ceba9355f0a85f4">]
65
- ```
66
-
67
- ### Blocks
68
-
69
- [Basic](#basic)
70
- [Proof-of-Work](#proof-of-work)
71
-
72
- Supported block types / classes for now include:
73
-
74
- #### Basic
75
-
76
- ``` ruby
77
- class Block
78
-
79
- attr_reader :index
80
- attr_reader :timestamp
81
- attr_reader :data
82
- attr_reader :previous_hash
83
- attr_reader :hash
84
-
85
- def initialize(index, data, previous_hash)
86
- @index = index
87
- @timestamp = Time.now.utc ## note: use coordinated universal time (utc)
88
- @data = data
89
- @previous_hash = previous_hash
90
- @hash = calc_hash
91
- end
92
-
93
- def calc_hash
94
- sha = Digest::SHA256.new
95
- sha.update( @index.to_s + @timestamp.to_s + @data + @previous_hash )
96
- sha.hexdigest
97
- end
98
- ...
99
- end
100
- ```
101
-
102
- (Source: [basic/block.rb](lib/blockchain-lite/basic/block.rb))
103
-
104
-
105
- #### Proof-of-Work
106
-
107
- ``` ruby
108
- class Block
109
-
110
- attr_reader :index
111
- attr_reader :timestamp
112
- attr_reader :data
113
- attr_reader :previous_hash
114
- attr_reader :nonce ## proof of work if hash starts with leading zeros (00)
115
- attr_reader :hash
116
-
117
- def initialize(index, data, previous_hash)
118
- @index = index
119
- @timestamp = Time.now.utc ## note: use coordinated universal time (utc)
120
- @data = data
121
- @previous_hash = previous_hash
122
- @nonce, @hash = compute_hash_with_proof_of_work
123
- end
124
-
125
- def calc_hash
126
- sha = Digest::SHA256.new
127
- sha.update( @nonce.to_s + @index.to_s + @timestamp.to_s + @data + @previous_hash )
128
- sha.hexdigest
129
- end
130
- ...
131
- end
132
- ```
133
-
134
- (Source: [proof_of_work/block.rb](lib/blockchain-lite/proof_of_work/block.rb))
135
-
136
-
137
-
138
- ### Blockchain Helper / Convenience Wrapper
139
-
140
- The `Blockchain` class offers some convenience helpers
141
- for building and checking blockchains. Example:
142
-
143
- ``` ruby
144
- b = Blockchain.new # note: will (auto-) add the first (genesis) block
145
-
146
- b << 'Transaction Data...'
147
- b << 'Transaction Data......'
148
- b << 'More Transaction Data...'
149
-
150
- pp b
151
- ```
152
-
153
- Check for broken chain links. Example:
154
-
155
- ``` ruby
156
-
157
- b.broken?
158
- # => false ## blockchain OK
159
- ```
160
-
161
- or use the `Blockchain` class as a wrapper (pass in the blockchain array):
162
-
163
- ``` ruby
164
- b0 = Block.first( 'Genesis' )
165
- b1 = Block.next( b0, 'Transaction Data...' )
166
- b2 = Block.next( b1, 'Transaction Data......' )
167
- b3 = Block.next( b2, 'More Transaction Data...' )
168
-
169
- blockchain = [b0, b1, b2, b3]
170
-
171
-
172
- b = Blockchain.new( blockchain )
173
-
174
- b.broken?
175
- # => false ## blockchain OK
176
- ```
177
-
178
- and so on.
179
-
180
-
181
-
182
-
183
- ## Install
184
-
185
- Just install the gem:
186
-
187
- ```
188
- $ gem install blockchain-lite
189
- ```
190
-
191
-
192
- ## License
193
-
194
- ![](https://publicdomainworks.github.io/buttons/zero88x31.png)
195
-
196
- The `blockchain.lite` scripts are dedicated to the public domain.
197
- Use it as you please with no restrictions whatsoever.
1
+ # Blockchain Lite
2
+
3
+ blockchain-lite library / gem - build your own blockchain with crypto hashes - revolutionize the world with blockchains, blockchains, blockchains one block at a time
4
+
5
+ * home :: [github.com/rubycoco/blockchain](https://github.com/rubycoco/blockchain)
6
+ * bugs :: [github.com/rubycoco/blockchain/issues](https://github.com/rubycoco/blockchain/issues)
7
+ * gem :: [rubygems.org/gems/blockchain-lite](https://rubygems.org/gems/blockchain-lite)
8
+ * rdoc :: [rubydoc.info/gems/blockchain-lite](http://rubydoc.info/gems/blockchain-lite)
9
+
10
+
11
+
12
+ ## What's a Blockchain?
13
+
14
+ > A blockchain is a
15
+ > a list (that is, chain) of records (that is, blocks)
16
+ > linked and secured by digital fingerprints
17
+ > (that is, crypto hashes).
18
+
19
+ See the [Awesome Blockchains](https://github.com/openblockchains/awesome-blockchains) page for more.
20
+
21
+
22
+ ## Usage
23
+
24
+ Let's get started. Build your own blockchain one block at a time.
25
+ Example:
26
+
27
+ ``` ruby
28
+ require 'blockchain-lite'
29
+
30
+ b0 = Block.first( 'Genesis' )
31
+ b1 = Block.next( b0, 'Transaction Data...' )
32
+ b2 = Block.next( b1, 'Transaction Data...' )
33
+ b3 = Block.next( b2, 'Transaction Data...' )
34
+
35
+ blockchain = [b0, b1, b2, b3]
36
+
37
+ pp blockchain
38
+ ```
39
+
40
+ will pretty print (pp) something like:
41
+
42
+ ```
43
+ [#<Block:0x1eed2a0
44
+ @index = 0,
45
+ @timestamp = 2021-09-15 20:52:38,
46
+ @transactions_count = 1,
47
+ @transactions = ["Genesis"],
48
+ @previous_hash = "0",
49
+ @hash = "edbd4e11e69bc399a9ccd8faaea44fb27410fe8e3023bb9462450a0a9c4caa1b">,
50
+ #<Block:0x1eec9a0
51
+ @index = 1,
52
+ @timestamp = 2021-09-15 21:02:38,
53
+ @transactions_count = 1,
54
+ @transactions = ["Transaction Data..."],
55
+ @hash = "eb8ecbf6d5870763ae246e37539d82e37052cb32f88bb8c59971f9978e437743",
56
+ @previous_hash = "edbd4e11e69bc399a9ccd8faaea44fb27410fe8e3023bb9462450a0a9c4caa1b">,
57
+ #<Block:0x1eec838
58
+ @index = 2,
59
+ @timestamp = 2021-09-15 21:12:38,
60
+ @transactions_count = 1,
61
+ @transactions = ["Transaction Data..."],
62
+ @hash = "be50017ee4bbcb33844b3dc2b7c4e476d46569b5df5762d14ceba9355f0a85f4",
63
+ @previous_hash = "eb8ecbf6d5870763ae246e37539d82e37052cb32f88bb8c59971f9978e437743">,
64
+ #<Block:0x1eec6d0
65
+ @index = 3,
66
+ @timestamp = 2021-09-15 21:22:38
67
+ @transactions_count = 1,
68
+ @transactions = ["Transaction Data..."],
69
+ @hash = "5ee2981606328abfe0c3b1171440f0df746c1e1f8b3b56c351727f7da7ae5d8d",
70
+ @previous_hash = "be50017ee4bbcb33844b3dc2b7c4e476d46569b5df5762d14ceba9355f0a85f4">]
71
+ ```
72
+
73
+
74
+ ### Blocks
75
+
76
+ [Basic](#basic)
77
+ [Proof-of-Work](#proof-of-work)
78
+
79
+ Supported block types / classes for now include:
80
+
81
+ #### Basic
82
+
83
+ ``` ruby
84
+ class Block
85
+
86
+ attr_reader :index
87
+ attr_reader :timestamp
88
+ attr_reader :transactions_count
89
+ attr_reader :transactions
90
+ attr_reader :previous_hash
91
+ attr_reader :hash
92
+
93
+ def initialize(index, transactions, previous_hash)
94
+ @index = index
95
+ @timestamp = Time.now.utc ## note: use coordinated universal time (utc)
96
+ @transactions = transactions
97
+ @transactions_count = transactions.size
98
+ @previous_hash = previous_hash
99
+ @hash = calc_hash
100
+ end
101
+
102
+ def calc_hash
103
+ sha = Digest::SHA256.new
104
+ sha.update( @timestamp.to_s +
105
+ @transactions.to_s +
106
+ @previous_hash )
107
+ sha.hexdigest
108
+ end
109
+ ...
110
+ end
111
+ ```
112
+
113
+ (Source: [basic/block.rb](lib/blockchain-lite/basic/block.rb))
114
+
115
+
116
+ #### Proof-of-Work
117
+
118
+ ``` ruby
119
+ class Block
120
+
121
+ attr_reader :index
122
+ attr_reader :timestamp
123
+ attr_reader :transactions_count
124
+ attr_reader :transactions
125
+ attr_reader :transactions_hash ## merkle_root
126
+ attr_reader :previous_hash
127
+ attr_reader :nonce ## proof of work if hash starts with leading zeros (00)
128
+ attr_reader :hash
129
+
130
+ def initialize(index, transactions, previous_hash)
131
+ @index = index
132
+ @timestamp = Time.now.utc ## note: use coordinated universal time (utc)
133
+ @transactions = transactions
134
+ @transactions_count = transactions.size
135
+ @transactions_hash = MerkleTree.compute_root_for( transactions )
136
+ @previous_hash = previous_hash
137
+ @nonce, @hash = compute_hash_with_proof_of_work
138
+ end
139
+
140
+ def calc_hash
141
+ sha = Digest::SHA256.new
142
+ sha.update( @nonce.to_s +
143
+ @timestamp.to_s +
144
+ @transactions_hash +
145
+ @previous_hash )
146
+ sha.hexdigest
147
+ end
148
+ ...
149
+ end
150
+ ```
151
+
152
+ (Source: [proof_of_work/block.rb](lib/blockchain-lite/proof_of_work/block.rb))
153
+
154
+
155
+
156
+ ### Blockchain Helper / Convenience Wrapper
157
+
158
+ The `Blockchain` class offers some convenience helpers
159
+ for building and checking blockchains. Example:
160
+
161
+ ``` ruby
162
+ b = Blockchain.new # note: will (auto-) add the first (genesis) block
163
+
164
+ b << 'Transaction Data...'
165
+ b << 'Transaction Data...'
166
+ b << 'Transaction Data...'
167
+
168
+ pp b
169
+ ```
170
+
171
+ Check for broken chain links. Example:
172
+
173
+ ``` ruby
174
+
175
+ b.broken?
176
+ # => false ## blockchain OK
177
+ ```
178
+
179
+ or use the `Blockchain` class as a wrapper (pass in the blockchain array):
180
+
181
+ ``` ruby
182
+ b0 = Block.first( 'Genesis' )
183
+ b1 = Block.next( b0, 'Transaction Data...' )
184
+ b2 = Block.next( b1, 'Transaction Data...' )
185
+ b3 = Block.next( b2, 'Transaction Data...' )
186
+
187
+ blockchain = [b0, b1, b2, b3]
188
+
189
+
190
+ b = Blockchain.new( blockchain )
191
+
192
+ b.broken?
193
+ # => false ## blockchain OK
194
+ ```
195
+
196
+ and so on.
197
+
198
+
199
+ ### Transactions
200
+
201
+ Let's put the transactions from the (hyper) ledger book from [Tulips on the Blockchain!](https://github.com/openblockchains/tulips)
202
+ on the blockchain:
203
+
204
+
205
+ | From | To | What | Qty |
206
+ |---------------------|--------------|---------------------------|----:|
207
+ | Dutchgrown (†) | Vincent | Tulip Bloemendaal Sunset | 10 |
208
+ | Keukenhof (†) | Anne | Tulip Semper Augustus | 7 |
209
+ | | | | |
210
+ | Flowers (†) | Ruben | Tulip Admiral van Eijck | 5 |
211
+ | Vicent | Anne | Tulip Bloemendaal Sunset | 3 |
212
+ | Anne | Julia | Tulip Semper Augustus | 1 |
213
+ | Julia | Luuk | Tulip Semper Augustus | 1 |
214
+ | | | | |
215
+ | Bloom & Blossom (†) | Daisy | Tulip Admiral of Admirals | 8 |
216
+ | Vincent | Max | Tulip Bloemendaal Sunset | 2 |
217
+ | Anne | Martijn | Tulip Semper Augustus | 2 |
218
+ | Ruben | Julia | Tulip Admiral van Eijck | 2 |
219
+ | | | | |
220
+ | Teleflora (†) | Max | Tulip Red Impression | 11 |
221
+ | Anne | Naomi | Tulip Bloemendaal Sunset | 1 |
222
+ | Daisy | Vincent | Tulip Admiral of Admirals | 3 |
223
+ | Julia | Mina | Tulip Admiral van Eijck | 1 |
224
+
225
+ (†): Grower Transaction - New Tulips on the Market!
226
+
227
+
228
+ ```ruby
229
+ b0 = Block.first(
230
+ { from: "Dutchgrown", to: "Vincent", what: "Tulip Bloemendaal Sunset", qty: 10 },
231
+ { from: "Keukenhof", to: "Anne", what: "Tulip Semper Augustus", qty: 7 } )
232
+
233
+ b1 = Block.next( b0,
234
+ { from: "Flowers", to: "Ruben", what: "Tulip Admiral van Eijck", qty: 5 },
235
+ { from: "Vicent", to: "Anne", what: "Tulip Bloemendaal Sunset", qty: 3 },
236
+ { from: "Anne", to: "Julia", what: "Tulip Semper Augustus", qty: 1 },
237
+ { from: "Julia", to: "Luuk", what: "Tulip Semper Augustus", qty: 1 } )
238
+
239
+ b2 = Block.next( b1,
240
+ { from: "Bloom & Blossom", to: "Daisy", what: "Tulip Admiral of Admirals", qty: 8 },
241
+ { from: "Vincent", to: "Max", what: "Tulip Bloemendaal Sunset", qty: 2 },
242
+ { from: "Anne", to: "Martijn", what: "Tulip Semper Augustus", qty: 2 },
243
+ { from: "Ruben", to: "Julia", what: "Tulip Admiral van Eijck", qty: 2 } )
244
+ ...
245
+ ```
246
+
247
+ resulting in:
248
+
249
+ ```
250
+ [#<Block:0x2da3da0
251
+ @index = 0,
252
+ @timestamp = 1637-09-24 11:40:15,
253
+ @previous_hash = "0",
254
+ @hash = "32bd169baebba0b70491b748329ab631c85175be15e1672f924ca174f628cb66",
255
+ @transactions_count = 2,
256
+ @transactions =
257
+ [{:from=>"Dutchgrown", :to=>"Vincent", :what=>"Tulip Bloemendaal Sunset", :qty=>10},
258
+ {:from=>"Keukenhof", :to=>"Anne", :what=>"Tulip Semper Augustus", :qty=>7}]>,
259
+ #<Block:0x2da2ff0
260
+ @index = 1,
261
+ @timestamp = 1637-09-24 11:50:15,
262
+ @previous_hash = "32bd169baebba0b70491b748329ab631c85175be15e1672f924ca174f628cb66",
263
+ @hash = "57b519a8903e45348ac8a739c788815e2bd90423663957f87e276307f77f1028",
264
+ @transactions_count = 4,
265
+ @transactions =
266
+ [{:from=>"Flowers", :to=>"Ruben", :what=>"Tulip Admiral van Eijck", :qty=>5},
267
+ {:from=>"Vicent", :to=>"Anne", :what=>"Tulip Bloemendaal Sunset", :qty=>3},
268
+ {:from=>"Anne", :to=>"Julia", :what=>"Tulip Semper Augustus", :qty=>1},
269
+ {:from=>"Julia", :to=>"Luuk", :what=>"Tulip Semper Augustus", :qty=>1}]>,
270
+ #<Block:0x2da2720
271
+ @index = 2,
272
+ @timestamp = 1637-09-24 12:00:15,
273
+ @previous_hash = "57b519a8903e45348ac8a739c788815e2bd90423663957f87e276307f77f1028",
274
+ @hash = "ec7dd5ea86ab966d4d4db182abb7aa93c7e5f63857476e6301e7e38cebf36568",
275
+ @transactions_count = 4,
276
+ @transactions =
277
+ [{:from=>"Bloom & Blossom", :to=>"Daisy", :what=>"Tulip Admiral of Admirals", :qty=>8},
278
+ {:from=>"Vincent", :to=>"Max", :what=>"Tulip Bloemendaal Sunset", :qty=>2},
279
+ {:from=>"Anne", :to=>"Martijn", :what=>"Tulip Semper Augustus", :qty=>2},
280
+ {:from=>"Ruben", :to=>"Julia", :what=>"Tulip Admiral van Eijck", :qty=>2}]>,
281
+ ...
282
+ ```
283
+
284
+
285
+ ## Blockchain Lite in the Real World
286
+
287
+ - [**centralbank**](../centralbank) - command line tool (and core library) - print your own money / cryptocurrency; run your own federated central bank nodes on the blockchain peer-to-peer over HTTP; revolutionize the world one block at a time
288
+ - [**tulipmania**](../tulipmania) - command line tool (and core library) - tulips on the blockchain; learn by example from the real world (anno 1637) - buy! sell! hodl! enjoy the beauty of admiral of admirals, semper augustus, and more; run your own hyper ledger tulip exchange nodes on the blockchain peer-to-peer over HTTP; revolutionize the world one block at a time
289
+
290
+ <!--
291
+ - [**shilling**](https://github.com/bitshilling/bitshilling) - command line tool (and core library) - shilling (or schilling) on the blockchain! rock-solid alpine dollar from austria; print (mine) your own shillings; run your own federated shilling central bank nodes w/ public distributed (hyper) ledger book on the blockchain peer-to-peer over HTTP; revolutionize the world one block at a time
292
+ -->
293
+
294
+ - You? Add your tool / service
295
+
296
+
297
+ ## References
298
+
299
+ [**Programming Cryptocurrencies and Blockchains (in Ruby)**](http://yukimotopress.github.io/blockchains) by Gerald Bauer et al, 2018, Yuki & Moto Press
300
+
301
+ And many more @ [**Best of Crypto Books**](https://openblockchains.github.io/crypto-books/) - a collection of books, white papers & more about crypto and blockchains
302
+
303
+
304
+
305
+ ## License
306
+
307
+ ![](https://publicdomainworks.github.io/buttons/zero88x31.png)
308
+
309
+ The `blockchain.lite` scripts are dedicated to the public domain.
310
+ Use it as you please with no restrictions whatsoever.