centralbank 0.2.0 → 0.2.1
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 +52 -7
- data/lib/centralbank.rb +18 -2
- data/lib/centralbank/bank.rb +2 -2
- data/lib/centralbank/cache.rb +2 -2
- data/lib/centralbank/ledger.rb +2 -2
- data/lib/centralbank/service.rb +21 -22
- data/lib/centralbank/version.rb +1 -1
- data/lib/centralbank/views/_blockchain.erb +4 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 202c231a695058fedcfd45734447b823ecec5943
|
4
|
+
data.tar.gz: 793bcbc06a672be4a32f417b2c0c145cca9dace8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fd3ac2058c57dffcf3050124609d1fc6cad9f49a8e543e06a20d26b809d31b3ed5053f757e02fe736d0080c6c209736cb8afff9b0d230d325ac0b3a113cfd66
|
7
|
+
data.tar.gz: 6e7a6fad83c6cd24336ef5d074c7136f1e3f5153bd74d2979464fdfc914a1d859b25c1027ceac4570df7092a3ed23c12d8c356714ebedcbeecaf421cae7fd643
|
data/README.md
CHANGED
@@ -9,9 +9,59 @@ print your own money / cryptocurrency; run your own federated central bank nodes
|
|
9
9
|
* rdoc :: [rubydoc.info/gems/centralbank](http://rubydoc.info/gems/centralbank)
|
10
10
|
|
11
11
|
|
12
|
+
## Command Line
|
12
13
|
|
14
|
+
Use the `centralbank` command line tool. Try:
|
13
15
|
|
14
|
-
|
16
|
+
```
|
17
|
+
$ centralbank -h
|
18
|
+
```
|
19
|
+
|
20
|
+
resulting in:
|
21
|
+
|
22
|
+
```
|
23
|
+
Usage: centralbank [options]
|
24
|
+
|
25
|
+
Wallet options:
|
26
|
+
-n, --name=NAME Address name (default: Alice)
|
27
|
+
|
28
|
+
Server (node) options:
|
29
|
+
-o, --host HOST listen on HOST (default: 0.0.0.0)
|
30
|
+
-p, --port PORT use PORT (default: 4567)
|
31
|
+
-h, --help Prints this help
|
32
|
+
```
|
33
|
+
|
34
|
+
To start a new (network) node using the default wallet
|
35
|
+
address (that is, Alice) and the default server host and port settings
|
36
|
+
use:
|
37
|
+
|
38
|
+
```
|
39
|
+
$ centralbank
|
40
|
+
```
|
41
|
+
|
42
|
+
Stand back ten feets :-) while starting up the machinery.
|
43
|
+
Ready to print (mine) money on the blockchain?
|
44
|
+
In your browser open up the page e.g. `http://localhost:4567`. Voila!
|
45
|
+
|
46
|
+

|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
Note: You can start a second node on your computer -
|
51
|
+
make sure to use a different port (use the `-p/--port` option)
|
52
|
+
and (recommended)
|
53
|
+
a different wallet address (use the `-n/--name` option).
|
54
|
+
Example:
|
55
|
+
|
56
|
+
```
|
57
|
+
$ centralbank -p 5678 -n Bob
|
58
|
+
```
|
59
|
+
|
60
|
+
Happy mining!
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
## Local Development Setup
|
15
65
|
|
16
66
|
For local development - clone or download (and unzip) the centralbank code repo.
|
17
67
|
Next install all dependencies using bundler with a Gemfile e.g.:
|
@@ -50,12 +100,7 @@ and startup the money printing machine using rackup - the rack command line tool
|
|
50
100
|
$ rackup ## will use the config.ru - rackup configuration script (see above).
|
51
101
|
```
|
52
102
|
|
53
|
-
In your browser open up the page e.g. `http://localhost:9292`. Voila!
|
54
|
-
|
55
|
-

|
56
|
-
|
57
|
-
|
58
|
-
Happy mining!
|
103
|
+
In your browser open up the page e.g. `http://localhost:9292`. Voila! Happy mining!
|
59
104
|
|
60
105
|
|
61
106
|
|
data/lib/centralbank.rb
CHANGED
@@ -49,15 +49,31 @@ module Centralbank
|
|
49
49
|
attr_accessor :coinbase
|
50
50
|
attr_accessor :mining_reward
|
51
51
|
|
52
|
+
## note: add a (†) coinbase marker
|
53
|
+
COINBASE = ['Everest†', 'Aconcagua†', 'Denali†',
|
54
|
+
'Kilimanjaro†', 'Elbrus†', 'Vinson†',
|
55
|
+
'Puncak Jaya†', 'Kosciuszko†',
|
56
|
+
'Mont Blanc†'
|
57
|
+
]
|
58
|
+
|
52
59
|
|
53
60
|
def initialize
|
54
61
|
## try default setup via ENV variables
|
55
62
|
## pick "random" address if nil (none passed in)
|
56
|
-
@address = ENV[ 'CENTRALBANK_NAME'] ||
|
63
|
+
@address = ENV[ 'CENTRALBANK_NAME'] || rand_address()
|
57
64
|
|
58
|
-
@coinbase
|
65
|
+
@coinbase = COINBASE ## use a different name - why? why not?
|
66
|
+
## note: for now is an array (multiple coinbases)
|
59
67
|
@mining_reward = 5
|
60
68
|
end
|
69
|
+
|
70
|
+
def rand_address() WALLET_ADDRESSES[rand( WALLET_ADDRESSES.size )]; end
|
71
|
+
def rand_coinbase() @coinbase[rand( @coinbase.size )]; end
|
72
|
+
|
73
|
+
def coinbase?( address ) ## check/todo: use wallet - why? why not? (for now wallet==address)
|
74
|
+
@coinbase.include?( address )
|
75
|
+
end
|
76
|
+
|
61
77
|
end # class Configuration
|
62
78
|
|
63
79
|
|
data/lib/centralbank/bank.rb
CHANGED
@@ -18,7 +18,7 @@ class Bank
|
|
18
18
|
@pending = Pool.from_json( h['transactions'] )
|
19
19
|
else
|
20
20
|
@chain = Blockchain.new
|
21
|
-
@chain << [Tx.new( Centralbank.config.
|
21
|
+
@chain << [Tx.new( Centralbank.config.rand_coinbase,
|
22
22
|
@address,
|
23
23
|
Centralbank.config.mining_reward )] # genesis (big bang!) starter block
|
24
24
|
@pending = Pool.new
|
@@ -31,7 +31,7 @@ class Bank
|
|
31
31
|
|
32
32
|
|
33
33
|
def mine_block!
|
34
|
-
add_transaction( Tx.new( Centralbank.config.
|
34
|
+
add_transaction( Tx.new( Centralbank.config.rand_coinbase,
|
35
35
|
@address,
|
36
36
|
Centralbank.config.mining_reward ))
|
37
37
|
|
data/lib/centralbank/cache.rb
CHANGED
@@ -6,14 +6,14 @@ class Cache
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def write( data )
|
9
|
-
File.open( @name, 'w' ) do |f|
|
9
|
+
File.open( @name, 'w:utf-8' ) do |f|
|
10
10
|
f.write JSON.pretty_generate( data )
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
def read
|
15
15
|
if File.exists?( @name )
|
16
|
-
data = File.
|
16
|
+
data = File.open( @name, 'r:bom|utf-8' ).read
|
17
17
|
JSON.parse( data )
|
18
18
|
else
|
19
19
|
nil
|
data/lib/centralbank/ledger.rb
CHANGED
@@ -10,7 +10,7 @@ class Ledger
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def sufficient_funds?( wallet, amount )
|
13
|
-
return true if
|
13
|
+
return true if Centralbank.config.coinbase?( wallet )
|
14
14
|
@wallets.has_key?( wallet ) && @wallets[wallet] - amount >= 0
|
15
15
|
end
|
16
16
|
|
@@ -20,7 +20,7 @@ private
|
|
20
20
|
def apply_transactions( transactions )
|
21
21
|
transactions.each do |tx|
|
22
22
|
if sufficient_funds?(tx.from, tx.amount)
|
23
|
-
@wallets[tx.from] -= tx.amount unless
|
23
|
+
@wallets[tx.from] -= tx.amount unless Centralbank.config.coinbase?( tx.from )
|
24
24
|
@wallets[tx.to] ||= 0
|
25
25
|
@wallets[tx.to] += tx.amount
|
26
26
|
end
|
data/lib/centralbank/service.rb
CHANGED
@@ -12,9 +12,6 @@ module Centralbank
|
|
12
12
|
PUBLIC_FOLDER = "#{Centralbank.root}/lib/centralbank/public"
|
13
13
|
VIEWS_FOLDER = "#{Centralbank.root}/lib/centralbank/views"
|
14
14
|
|
15
|
-
puts "[centralbank] boot - setting public folder to: #{PUBLIC_FOLDER}"
|
16
|
-
puts "[centralbank] boot - setting views folder to: #{VIEWS_FOLDER}"
|
17
|
-
|
18
15
|
set :public_folder, PUBLIC_FOLDER # set up the static dir (with images/js/css inside)
|
19
16
|
set :views, VIEWS_FOLDER # set up the views dir
|
20
17
|
|
@@ -24,24 +21,6 @@ module Centralbank
|
|
24
21
|
set connections: []
|
25
22
|
|
26
23
|
|
27
|
-
#########
|
28
|
-
## return network node (built and configured on first use)
|
29
|
-
## fix: do NOT use @@ - use a class level method or something
|
30
|
-
def node
|
31
|
-
if defined?( @@node )
|
32
|
-
@@node
|
33
|
-
else
|
34
|
-
puts "[debug] centralbank - build (network) node (address: #{Centralbank.config.address})"
|
35
|
-
@@node = Node.new( address: Centralbank.config.address )
|
36
|
-
@@node
|
37
|
-
end
|
38
|
-
####
|
39
|
-
## check why this is a syntax error:
|
40
|
-
## @node ||= do
|
41
|
-
## puts "[debug] centralbank - build (network) node (address: #{Centralbank.config.address})"
|
42
|
-
## @node = Node.new( address: Centralbank.config.address )
|
43
|
-
## end
|
44
|
-
end
|
45
24
|
|
46
25
|
get '/style.css' do
|
47
26
|
scss :style ## note: converts (pre-processes) style.scss to style.css
|
@@ -107,7 +86,27 @@ module Centralbank
|
|
107
86
|
out.callback { settings.connections.delete(out) }
|
108
87
|
end
|
109
88
|
end
|
110
|
-
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
#########
|
93
|
+
## return network node (built and configured on first use)
|
94
|
+
## fix: do NOT use @@ - use a class level method or something
|
95
|
+
def node
|
96
|
+
if defined?( @@node )
|
97
|
+
@@node
|
98
|
+
else
|
99
|
+
puts "[debug] centralbank - build (network) node (address: #{Centralbank.config.address})"
|
100
|
+
@@node = Node.new( address: Centralbank.config.address )
|
101
|
+
@@node
|
102
|
+
end
|
103
|
+
####
|
104
|
+
## check why this is a syntax error:
|
105
|
+
## @node ||= do
|
106
|
+
## puts "[debug] centralbank - build (network) node (address: #{Centralbank.config.address})"
|
107
|
+
## @node = Node.new( address: Centralbank.config.address )
|
108
|
+
## end
|
109
|
+
end
|
111
110
|
|
112
111
|
end # class Service
|
113
112
|
|
data/lib/centralbank/version.rb
CHANGED
@@ -23,7 +23,7 @@
|
|
23
23
|
$<%= tx.amount %>
|
24
24
|
</td>
|
25
25
|
<td>
|
26
|
-
<%= tx.from[0..
|
26
|
+
<%= tx.from[0..15] %> → <%= tx.to[0..15] %>
|
27
27
|
</td>
|
28
28
|
</tr>
|
29
29
|
<% end %>
|
@@ -31,4 +31,7 @@
|
|
31
31
|
</div>
|
32
32
|
<% end %>
|
33
33
|
</div>
|
34
|
+
<p>
|
35
|
+
†: Miner Transaction - New $$ on the Market!
|
36
|
+
</p>
|
34
37
|
</div>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: centralbank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
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-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|