Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
geraldb committed Nov 2, 2020
1 parent 9d0c001 commit b9c8170
Show file tree
Hide file tree
Showing 61 changed files with 2,734 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Gems:
- [p2p](p2p) - build your own peer-to-peer (p2p) networks; run your own peer-to-peer (p2p) nodes over HTTP


<!-- break -->

- [centralbank](centralbank) - 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
- [tulipmania](tulipmania) - 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



Expand Down
70 changes: 70 additions & 0 deletions centralbank/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
###########
# cached / saved state / data

data.json
data.*.json



##########
# ignore Gemfile.lock for now

Gemfile.lock


####
# ignore sass cache
.sass-cache



*.gem
*.rbc
/.config
/coverage/
/InstalledFiles
/pkg/
/spec/reports/
/spec/examples.txt
/test/tmp/
/test/version_tmp/
/tmp/

# Used by dotenv library to load environment variables.
# .env

## Specific to RubyMotion:
.dat*
.repl_history
build/
*.bridgesupport
build-iPhoneOS/
build-iPhoneSimulator/

## Specific to RubyMotion (use of CocoaPods):
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# vendor/Pods/

## Documentation cache and generated files:
/.yardoc/
/_yardoc/
/doc/
/rdoc/

## Environment normalization:
/.bundle/
/vendor/bundle
/lib/bundler/man/

# for a library or gem, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# Gemfile.lock
# .ruby-version
# .ruby-gemset

# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc
9 changes: 9 additions & 0 deletions centralbank/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM ruby

RUN mkdir /centralbank
WORKDIR /centralbank
COPY . /centralbank/
RUN bundle install --quiet
EXPOSE 9292
CMD [ "rackup", "--host", "0.0.0.0", "-p", "9292"]

7 changes: 7 additions & 0 deletions centralbank/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Gemfile

source "https://rubygems.org"

gem 'sinatra'
gem 'sass'
gem 'blockchain-lite'
3 changes: 3 additions & 0 deletions centralbank/HISTORY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### 0.1.0 / 2017-12-14

* Everything is new. First release.
26 changes: 26 additions & 0 deletions centralbank/Manifest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
HISTORY.md
LICENSE.md
Manifest.txt
README.md
Rakefile
bin/centralbank
lib/centralbank.rb
lib/centralbank/bank.rb
lib/centralbank/block.rb
lib/centralbank/blockchain.rb
lib/centralbank/cache.rb
lib/centralbank/ledger.rb
lib/centralbank/node.rb
lib/centralbank/pool.rb
lib/centralbank/service.rb
lib/centralbank/tool.rb
lib/centralbank/transaction.rb
lib/centralbank/version.rb
lib/centralbank/views/_blockchain.erb
lib/centralbank/views/_ledger.erb
lib/centralbank/views/_peers.erb
lib/centralbank/views/_pending_transactions.erb
lib/centralbank/views/_wallet.erb
lib/centralbank/views/index.erb
lib/centralbank/views/style.scss
lib/centralbank/wallet.rb
35 changes: 35 additions & 0 deletions centralbank/NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Notes


## Todos

- [ ] add favicon.png - why? why not? (see webservice gem)
- [ ] add a Pool class (for pending transaction pool) !!!!!
- [ ] add secure versions with signature e.g. SecureWallet, SecureTransaction, etc.

```
Source: https://www.reddit.com/r/ruby/comments/7ly337/day_24_ruby_advent_calendar_2017_centralbank/
I'm playing with your Ruby blockchain stuff. It's very good. It's giving me a way to learn it without having to learn Go or C++ at the same time. But...
When I try running central bank from the command line as described in blockchains section 6. using
centralbank
it doesn't work because centralbank is in the bin/ directory, so I tried (after setting chmod +x etc)
bin/centralbank
and then got an error I've never seen before
env: ruby\r: No such file or directory
So I wrote added one space at the end of the shebang header line That removed the extra \r and I then progressed to
bin/centralbank
Traceback (most recent call last):
(LoadError)h file or directory --
Because it doesn't know where the library path is. If I run with
ruby -Ilib bin/centralbank
Then it's fine.
So you need to do something to remove that \r at the end of the shebang line, and add the library path before the require.
```
118 changes: 118 additions & 0 deletions centralbank/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# centralbank library / gem and command line tool

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


* home :: [github.com/openblockchains/centralbank](https://github.com/openblockchains/centralbank)
* bugs :: [github.com/openblockchains/centralbank/issues](https://github.com/openblockchains/centralbank/issues)
* gem :: [rubygems.org/gems/centralbank](https://rubygems.org/gems/centralbank)
* rdoc :: [rubydoc.info/gems/centralbank](http://rubydoc.info/gems/centralbank)


## Command Line

Use the `centralbank` command line tool. Try:

```
$ centralbank -h
```

resulting in:

```
Usage: centralbank [options]
Wallet options:
-n, --name=NAME Address name (default: Alice)
Server (node) options:
-o, --host HOST listen on HOST (default: 0.0.0.0)
-p, --port PORT use PORT (default: 4567)
-h, --help Prints this help
```

To start a new (network) node using the default wallet
address (that is, Alice) and the default server host and port settings
use:

```
$ centralbank
```

Stand back ten feets :-) while starting up the machinery.
Ready to print (mine) money on the blockchain?
In your browser open up the page e.g. `http://localhost:4567`. Voila!

![](centralbank.png)



Note: You can start a second node on your computer -
make sure to use a different port (use the `-p/--port` option)
and (recommended)
a different wallet address (use the `-n/--name` option).
Example:

```
$ centralbank -p 5678 -n Bob
```

Happy mining!



## Local Development Setup

For local development - clone or download (and unzip) the centralbank code repo.
Next install all dependencies using bundler with a Gemfile e.g.:

``` ruby
# Gemfile

source "https://rubygems.org"

gem 'sinatra'
gem 'sass'
gem 'blockchain-lite'
```

run

```
$ bundle ## will use the Gemfile (see above)
```

and now you're ready to run your own centralbank server node. Use the [`config.ru`](config.ru) script for rack:

``` ruby
# config.ru

$LOAD_PATH << './lib'

require 'centralbank'

run Centralbank::Service
```

and startup the money printing machine using rackup - the rack command line tool:

```
$ rackup ## will use the config.ru - rackup configuration script (see above).
```

In your browser open up the page e.g. `http://localhost:9292`. Voila! Happy mining!




## References

[**Programming Cryptocurrencies and Blockchains (in Ruby)**](http://yukimotopress.github.io/blockchains) by Gerald Bauer et al, 2018, Yuki & Moto Press


## License

![](https://publicdomainworks.github.io/buttons/zero88x31.png)

The `centralbank` scripts are dedicated to the public domain.
Use it as you please with no restrictions whatsoever.
32 changes: 32 additions & 0 deletions centralbank/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'hoe'
require './lib/centralbank/version.rb'

Hoe.spec 'centralbank' do

self.version = Centralbank::VERSION

self.summary = 'centralbank - 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'
self.description = summary

self.urls = ['https://github.com/openblockchains/centralbank']

self.author = 'Gerald Bauer'
self.email = '[email protected]'

# switch extension to .markdown for gihub formatting
self.readme_file = 'README.md'
self.history_file = 'History.md'

self.extra_deps = [
['sinatra', '>=2.0'],
['sass'], ## used for css style preprocessing (scss)
['blockchain-lite', '>=1.3.1'],
]

self.licenses = ['Public Domain']

self.spec_extras = {
required_ruby_version: '>= 2.3'
}

end
17 changes: 17 additions & 0 deletions centralbank/bin/centralbank
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env ruby

###################
# == DEV TIPS:
#
# For local testing run like:
#
# ruby -Ilib bin/centralbank
#
# Set the executable bit in Linux. Example:
#
# % chmod a+x bin/centralbank
#

require 'centralbank'

Centralbank.main
Binary file added centralbank/centralbank.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions centralbank/config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### note: for local testing - add to load path ./lib
## to test / run use:
## $ rackup


$LOAD_PATH << './lib'

require 'centralbank'


run Centralbank::Service
Loading

0 comments on commit b9c8170

Please sign in to comment.