ledger-lite 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +166 -67
- data/lib/ledger-lite/base.rb +5 -0
- data/lib/ledger-lite/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2913a46758e571674fbeddb848ddfab228a2eace
|
4
|
+
data.tar.gz: 6783620e8081c675eb912810e8491ed781b53a8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f71518005dbf46557c6dbc807dc23fd363dc872ec41129bdde74d7c91df69866b98503c58cf0debd5654162c665b15396c2b926d98535c4a1f49d56fe501901
|
7
|
+
data.tar.gz: afa5f7913b4d85a2b8c16bfbe46ab40d32c1f563f86c545c3cbb0593af5b643f91333f2da0477c95f944976460c74aaf9d4f60a9e21669642499f0a5787ca596
|
data/README.md
CHANGED
@@ -9,21 +9,22 @@ ledger-lite library / gem - hyper ledger book for the distributed blockchain int
|
|
9
9
|
* rdoc :: [rubydoc.info/gems/ledger-lite](http://rubydoc.info/gems/ledger-lite)
|
10
10
|
|
11
11
|
|
12
|
+
|
12
13
|
## Usage
|
13
14
|
|
14
15
|
Let's add some transactions to the (hyper) ledger book:
|
15
16
|
|
16
|
-
| From
|
17
|
-
|
18
|
-
|
|
19
|
-
| Vincent
|
20
|
-
| Anne
|
21
|
-
| Julia
|
22
|
-
|
|
23
|
-
|
|
24
|
-
| Vincent
|
25
|
-
| Ruben
|
26
|
-
| Anne
|
17
|
+
| From | To | $ |
|
18
|
+
|---------------------------|--------------|----:|
|
19
|
+
| Central Bank (†) | Vincent | 11 |
|
20
|
+
| Vincent | Anne | 3 |
|
21
|
+
| Anne | Julia | 2 |
|
22
|
+
| Julia | Luuk | 1 |
|
23
|
+
| | | |
|
24
|
+
| De Nederlandsche Bank (†) | Ruben | 11 |
|
25
|
+
| Vincent | Max | 3 |
|
26
|
+
| Ruben | Julia | 2 |
|
27
|
+
| Anne | Martijn | 1 |
|
27
28
|
|
28
29
|
(†): Mining Transaction - New Dutch Gulden ($) on the Market!
|
29
30
|
|
@@ -35,15 +36,15 @@ Let's add some transactions to the (hyper) ledger book:
|
|
35
36
|
|
36
37
|
ledger = Ledger.new
|
37
38
|
|
38
|
-
ledger.send( "
|
39
|
-
ledger.send( "Vincent",
|
40
|
-
ledger.send( "Anne",
|
41
|
-
ledger.send( "Julia",
|
39
|
+
ledger.send( "Central Bank†", "Vincent", 11 )
|
40
|
+
ledger.send( "Vincent", "Anne", 3 )
|
41
|
+
ledger.send( "Anne", "Julia", 2 )
|
42
|
+
ledger.send( "Julia", "Luuk", 1 )
|
42
43
|
|
43
|
-
ledger.send( "
|
44
|
-
ledger.send( "Vincent",
|
45
|
-
ledger.send( "Ruben",
|
46
|
-
ledger.send( "Anne",
|
44
|
+
ledger.send( "De Nederlandsche Bank†", "Ruben", 11 )
|
45
|
+
ledger.send( "Vincent", "Max", 3 )
|
46
|
+
ledger.send( "Ruben", "Julia", 2 )
|
47
|
+
ledger.send( "Anne", "Martijn", 1 )
|
47
48
|
|
48
49
|
pp ledger ## pp = pretty print
|
49
50
|
|
@@ -85,15 +86,15 @@ Or use transaction hashes:
|
|
85
86
|
``` ruby
|
86
87
|
ledger = Ledger.new
|
87
88
|
|
88
|
-
ledger.write( from: "
|
89
|
-
ledger.write( from: "Vincent",
|
90
|
-
ledger.write( from: "Anne",
|
91
|
-
ledger.write( from: "Julia",
|
89
|
+
ledger.write( from: "Central Bank†", to: "Vincent", amount: 11 )
|
90
|
+
ledger.write( from: "Vincent", to: "Anne", amount: 3 )
|
91
|
+
ledger.write( from: "Anne", to: "Julia", amount: 2 )
|
92
|
+
ledger.write( from: "Julia", to: "Luuk", amount: 1 )
|
92
93
|
|
93
|
-
ledger.write( { from: "
|
94
|
-
{ from: "Vincent",
|
95
|
-
{ from: "Ruben",
|
96
|
-
{ from: "Anne",
|
94
|
+
ledger.write( { from: "De Nederlandsche Bank†", to: "Ruben", amount: 11 },
|
95
|
+
{ from: "Vincent", to: "Max", amount: 3 },
|
96
|
+
{ from: "Ruben", to: "Julia", amount: 2 },
|
97
|
+
{ from: "Anne", to: "Martijn", amount: 1 } )
|
97
98
|
|
98
99
|
pp ledger
|
99
100
|
```
|
@@ -103,15 +104,15 @@ Or use transaction (tx) classes/structs:
|
|
103
104
|
``` ruby
|
104
105
|
ledger = Ledger.new
|
105
106
|
|
106
|
-
ledger.write( Tx.new( "
|
107
|
-
ledger.write( Tx.new( "Vincent",
|
108
|
-
ledger.write( Tx.new( "Anne",
|
109
|
-
ledger.write( Tx.new( "Julia",
|
107
|
+
ledger.write( Tx.new( "Central Bank†", "Vincent", 11 ))
|
108
|
+
ledger.write( Tx.new( "Vincent", "Anne", 3 ))
|
109
|
+
ledger.write( Tx.new( "Anne", "Julia", 2 ))
|
110
|
+
ledger.write( Tx.new( "Julia", "Luuk", 1 ))
|
110
111
|
|
111
|
-
ledger.write( Tx.new( "
|
112
|
-
Tx.new( "Vincent",
|
113
|
-
Tx.new( "Ruben",
|
114
|
-
Tx.new( "Anne",
|
112
|
+
ledger.write( Tx.new( "De Nederlandsche Bank†", "Ruben", 11 ),
|
113
|
+
Tx.new( "Vincent", "Max", 3 ),
|
114
|
+
Tx.new( "Ruben", "Julia", 2 ),
|
115
|
+
Tx.new( "Anne", "Martijn", 1 ))
|
115
116
|
|
116
117
|
pp ledger
|
117
118
|
```
|
@@ -121,15 +122,15 @@ Or use the operator `<<` alias for `write`:
|
|
121
122
|
```ruby
|
122
123
|
ledger = Ledger.new
|
123
124
|
|
124
|
-
ledger << Tx.new( "
|
125
|
-
ledger << Tx.new( "Vincent",
|
126
|
-
ledger << Tx.new( "Anne",
|
127
|
-
ledger << Tx.new( "Julia",
|
125
|
+
ledger << Tx.new( "Central Bank†", "Vincent", 11 )
|
126
|
+
ledger << Tx.new( "Vincent", "Anne", 3 )
|
127
|
+
ledger << Tx.new( "Anne", "Julia", 2 )
|
128
|
+
ledger << Tx.new( "Julia", "Luuk", 1 )
|
128
129
|
|
129
|
-
ledger << [Tx.new( "
|
130
|
-
Tx.new( "Vincent",
|
131
|
-
Tx.new( "Ruben",
|
132
|
-
Tx.new( "Anne",
|
130
|
+
ledger << [Tx.new( "De Nederlandsche Bank†", "Ruben", 11 ),
|
131
|
+
Tx.new( "Vincent", "Max", 3 ),
|
132
|
+
Tx.new( "Ruben", "Julia", 2 ),
|
133
|
+
Tx.new( "Anne", "Martijn", 1 )]
|
133
134
|
|
134
135
|
pp ledger
|
135
136
|
```
|
@@ -141,14 +142,14 @@ Or use blocks of transaction hashes:
|
|
141
142
|
|
142
143
|
ledger = Ledger.new
|
143
144
|
|
144
|
-
ledger.write( Block.new( { from: "
|
145
|
-
{ from: "Vincent",
|
146
|
-
{ from: "Anne",
|
147
|
-
{ from: "Julia",
|
148
|
-
Block.new( { from: "
|
149
|
-
{ from: "Vincent",
|
150
|
-
{ from: "Ruben",
|
151
|
-
{ from: "Anne",
|
145
|
+
ledger.write( Block.new( { from: "Central Bank†", to: "Vincent", amount: 11 },
|
146
|
+
{ from: "Vincent", to: "Anne", amount: 3 },
|
147
|
+
{ from: "Anne", to: "Julia", amount: 2 },
|
148
|
+
{ from: "Julia", to: "Luuk", amount: 1 } ),
|
149
|
+
Block.new( { from: "De Nederlandsche Bank†", to: "Ruben", amount: 11 },
|
150
|
+
{ from: "Vincent", to: "Max", amount: 3 },
|
151
|
+
{ from: "Ruben", to: "Julia", amount: 2 },
|
152
|
+
{ from: "Anne", to: "Martijn", amount: 1 } ))
|
152
153
|
|
153
154
|
pp ledger
|
154
155
|
```
|
@@ -159,14 +160,14 @@ Or use blocks of transaction classes/structs:
|
|
159
160
|
``` ruby
|
160
161
|
ledger = Ledger.new
|
161
162
|
|
162
|
-
ledger.write( Block.new( Tx.new( "
|
163
|
-
Tx.new( "Vincent",
|
164
|
-
Tx.new( "Anne",
|
165
|
-
Tx.new( "Julia",
|
166
|
-
Block.new( Tx.new( "
|
167
|
-
Tx.new( "Vincent",
|
168
|
-
Tx.new( "Ruben",
|
169
|
-
Tx.new( "Anne",
|
163
|
+
ledger.write( Block.new( Tx.new( "Central Bank†", "Vincent", 11 ),
|
164
|
+
Tx.new( "Vincent", "Anne", 3 ),
|
165
|
+
Tx.new( "Anne", "Julia", 2 ),
|
166
|
+
Tx.new( "Julia", "Luuk", 1 )),
|
167
|
+
Block.new( Tx.new( "De Nederlandsche Bank†", "Ruben", 11 ),
|
168
|
+
Tx.new( "Vincent", "Max", 3 ),
|
169
|
+
Tx.new( "Ruben", "Julia", 2 ),
|
170
|
+
Tx.new( "Anne", "Martijn", 1 )))
|
170
171
|
|
171
172
|
pp ledger
|
172
173
|
```
|
@@ -176,23 +177,121 @@ Or use blocks of transaction classes/structs (with keyword arguments):
|
|
176
177
|
```ruby
|
177
178
|
ledger = Ledger.new
|
178
179
|
|
179
|
-
ledger.write( Block.new( Tx.new( from: "
|
180
|
-
Tx.new( from: "Vincent",
|
181
|
-
Tx.new( from: "Anne",
|
182
|
-
Tx.new( from: "Julia",
|
183
|
-
Block.new( Tx.new( from: "
|
184
|
-
Tx.new( from: "Vincent",
|
185
|
-
Tx.new( from: "Ruben",
|
186
|
-
Tx.new( from: "Anne",
|
180
|
+
ledger.write( Block.new( Tx.new( from: "Central Bank†", to: "Vincent", amount: 11 ),
|
181
|
+
Tx.new( from: "Vincent", to: "Anne", amount: 3 ),
|
182
|
+
Tx.new( from: "Anne", to: "Julia", amount: 2 ),
|
183
|
+
Tx.new( from: "Julia", to: "Luuk", amount: 1 )),
|
184
|
+
Block.new( Tx.new( from: "De Nederlandsche Bank†", to: "Ruben", amount: 11 ),
|
185
|
+
Tx.new( from: "Vincent", to: "Max", amount: 3 ),
|
186
|
+
Tx.new( from: "Ruben", to: "Julia", amount: 2 ),
|
187
|
+
Tx.new( from: "Anne", to: "Martijn", amount: 1 )))
|
188
|
+
|
189
|
+
pp ledger
|
190
|
+
```
|
191
|
+
|
192
|
+
# Bonus: Track Commodities, Collectibles or Assets
|
193
|
+
|
194
|
+
Ledger Lite lets you design / create your own transactions. For example, let's use
|
195
|
+
`from`, `to`, `qty` (quantity) and `name` (of commodity, collectible or asset).
|
196
|
+
Override the `Ledger#unpack` method for "unpacking" arguments from transactions
|
197
|
+
and the `Ledger#send` method for "committing" transactions:
|
198
|
+
|
199
|
+
|
200
|
+
``` ruby
|
201
|
+
def unpack( tx )
|
202
|
+
## "unpack" from, to, qty, name values
|
203
|
+
if tx.is_a?( Hash ) ## support hashes
|
204
|
+
from = tx[:from]
|
205
|
+
to = tx[:to]
|
206
|
+
qty = tx[:qty]
|
207
|
+
name = tx[:name]
|
208
|
+
else ## assume it's a transaction (tx) struct/class
|
209
|
+
from = tx.from
|
210
|
+
to = tx.to
|
211
|
+
qty = tx.qty
|
212
|
+
name = tx.name
|
213
|
+
end
|
214
|
+
[from,to,qty,name]
|
215
|
+
end
|
216
|
+
```
|
217
|
+
|
218
|
+
and
|
219
|
+
|
220
|
+
``` ruby
|
221
|
+
def send( from, to, qty, name )
|
222
|
+
if sufficient?( from, qty, name )
|
223
|
+
if self.class.config.coinbase?( from )
|
224
|
+
# note: coinbase has unlimited supply!! magic happens here
|
225
|
+
else
|
226
|
+
@addr[ from ][ name ] -= qty
|
227
|
+
end
|
228
|
+
@addr[ to ] ||= {} ## make sure addr exists (e.g. init with empty hash {})
|
229
|
+
@addr[ to ][ name ] ||= 0
|
230
|
+
@addr[ to ][ name ] += qty
|
231
|
+
end
|
232
|
+
end
|
233
|
+
```
|
234
|
+
|
235
|
+
Now use the ledger with the new transaction format like:
|
236
|
+
|
237
|
+
|
238
|
+
``` ruby
|
239
|
+
ledger = Ledger.new
|
240
|
+
|
241
|
+
ledger.send( "Keukenhof†", "Vincent", 11, "Tulip Admiral van Eijck" )
|
242
|
+
ledger.send( "Vincent", "Anne", 3, "Tulip Admiral van Eijck" )
|
243
|
+
ledger.send( "Anne", "Julia", 2, "Tulip Admiral van Eijck" )
|
244
|
+
ledger.send( "Julia", "Luuk", 1, "Tulip Admiral van Eijck" )
|
245
|
+
|
246
|
+
ledger.send( "Dutchgrown†", "Ruben", 11, "Tulip Semper Augustus" )
|
247
|
+
ledger.send( "Vincent", "Max", 3, "Tulip Admiral van Eijck" )
|
248
|
+
ledger.send( "Ruben", "Julia", 2, "Tulip Semper Augustus" )
|
249
|
+
ledger.send( "Anne", "Martijn", 1, "Tulip Admiral van Eijck" )
|
250
|
+
|
251
|
+
pp ledger ## pp == pretty print
|
252
|
+
```
|
253
|
+
|
254
|
+
resulting in:
|
255
|
+
|
256
|
+
```
|
257
|
+
#<LedgerLite::Ledger
|
258
|
+
@addr={
|
259
|
+
"Vincent" => {"Tulip Admiral van Eijck" => 5},
|
260
|
+
"Anne" => {"Tulip Admiral van Eijck" => 0},
|
261
|
+
"Julia" => {"Tulip Admiral van Eijck" => 1, "Tulip Semper Augustus" => 2},
|
262
|
+
"Luuk" => {"Tulip Admiral van Eijck" => 1},
|
263
|
+
"Ruben" => {"Tulip Semper Augustus" => 9},
|
264
|
+
"Max" => {"Tulip Admiral van Eijck" => 3},
|
265
|
+
"Martijn" => {"Tulip Admiral van Eijck" => 1}}>
|
266
|
+
```
|
267
|
+
|
268
|
+
Or use blocks of transaction classes/structs (with keyword arguments):
|
269
|
+
|
270
|
+
|
271
|
+
``` ruby
|
272
|
+
ledger = Ledger.new
|
273
|
+
|
274
|
+
ledger.write( Block.new( Tx.new( from: "Keukenhof†", to: "Vincent", qty: 11, name: "Tulip Admiral van Eijck" ),
|
275
|
+
Tx.new( from: "Vincent", to: "Anne", qty: 3, name: "Tulip Admiral van Eijck" ),
|
276
|
+
Tx.new( from: "Anne", to: "Julia", qty: 2, name: "Tulip Admiral van Eijck" ),
|
277
|
+
Tx.new( from: "Julia", to: "Luuk", qty: 1, name: "Tulip Admiral van Eijck" )),
|
278
|
+
Block.new( Tx.new( from: "Dutchgrown†", to: "Ruben", qty: 11, name: "Tulip Semper Augustus" ),
|
279
|
+
Tx.new( from: "Vincent", to: "Max", qty: 3, name: "Tulip Admiral van Eijck" ),
|
280
|
+
Tx.new( from: "Ruben", to: "Julia", qty: 2, name: "Tulip Semper Augustus" ),
|
281
|
+
Tx.new( from: "Anne", to: "Martijn", qty: 1, name: "Tulip Admiral van Eijck" )))
|
187
282
|
|
188
283
|
pp ledger
|
189
284
|
```
|
190
285
|
|
286
|
+
And so on and on.
|
287
|
+
|
288
|
+
|
191
289
|
|
192
290
|
|
193
291
|
## Ledger Lite in the Real World
|
194
292
|
|
195
293
|
- [**centralbank**](https://github.com/openblockchains/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
|
294
|
+
- [**tulipmania**](https://github.com/openblockchains/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
|
196
295
|
- [**shilling**](https://github.com/bitshilling/bitshilling.tools) - 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
|
197
296
|
- You? Add your tool / service
|
198
297
|
|
data/lib/ledger-lite/base.rb
CHANGED
@@ -90,6 +90,11 @@ class Base
|
|
90
90
|
if args.size == 1 && args[0].is_a?( Array )
|
91
91
|
puts " unwrap array in array"
|
92
92
|
blks_or_txns = args[0] ## "unwrap" array in array
|
93
|
+
elsif args.size == 1 && defined?( Blockchain ) && args[0].is_a?( Blockchain )
|
94
|
+
## support passing in of "top-level" defined blockchain class if defined
|
95
|
+
## pass along all blocks ("unwrapped" from blockchain)
|
96
|
+
blks_or_txns = []
|
97
|
+
args[0].each { |b| blks_or_txns << b }
|
93
98
|
else
|
94
99
|
blks_or_txns = args ## use "auto-wrapped" splat array
|
95
100
|
end
|
data/lib/ledger-lite/version.rb
CHANGED