Skip to content

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
Coinbase authored and Adrian Macneil committed Sep 4, 2014
0 parents commit d85dc04
Show file tree
Hide file tree
Showing 137 changed files with 140,785 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.DS_Store
/*.dump
/.bundle
/.env
/.vagrant
/BitcoindComparisonTool.*
/bootstrap_last_offset.txt
/config/toshi.yml
/log
/tmp
/vendor
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "spec/regtest/test-scripts"]
path = spec/regtest/test-scripts
url = git://github.com/TheBlueMatt/test-scripts.git
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--require spec_helper
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.1.2
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Start with an Ubuntu 14.04 image that has ruby 2.1.2
FROM litaio/ruby:2.1.2

# Install dependencies
RUN apt-get -y install libpq-dev
RUN gem install bundler

# Add the Gemfile to the image
# Separate this from the source so as not to bust the cache
ADD Gemfile /Gemfile
ADD Gemfile.lock /Gemfile.lock

# Install gems
RUN bundle install

# Add the source dir
ADD . /toshi

# Copy the config template
ADD config/toshi.yml.example /toshi/config/toshi.yml

# Set up our working dir
WORKDIR /toshi

# Expose port 5000 of the container to the host
EXPOSE 5000
25 changes: 25 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
source 'https://rubygems.org'
ruby '2.1.2'

gem 'rake'
gem 'foreman'
gem 'bitcoin-ruby', git: 'https://github.com/lian/bitcoin-ruby', branch: 'master', require: 'bitcoin'
gem 'ffi'
gem 'eventmachine'
gem 'pg'
gem 'sequel'
gem 'sequel_model'
gem 'sidekiq'
gem 'sidekiq-unique-jobs'
gem 'sinatra', require: 'sinatra/base'
gem 'sinatra-contrib'
gem 'thin'
gem 'slim'
gem 'faye-websocket'
gem 'bugsnag-em'

group :test do
gem 'rspec'
gem 'rack-test', :require => "rack/test"
gem 'database_cleaner'
end
124 changes: 124 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
GIT
remote: https://github.com/lian/bitcoin-ruby
revision: b7bd36fe7e6ac30ad5910a73c527617974e3086e
branch: master
specs:
bitcoin-ruby (0.0.5)

GEM
remote: https://rubygems.org/
specs:
backports (3.6.0)
bugsnag (2.2.2)
httparty (>= 0.6, < 1.0)
multi_json (~> 1.0)
bugsnag-em (0.1)
bugsnag
eventmachine
lspace (>= 0.13)
celluloid (0.15.2)
timers (~> 1.1.0)
connection_pool (2.0.0)
daemons (1.1.9)
database_cleaner (1.3.0)
diff-lcs (1.2.5)
dotenv (0.11.1)
dotenv-deployment (~> 0.0.2)
dotenv-deployment (0.0.2)
eventmachine (1.0.3)
faye-websocket (0.7.4)
eventmachine (>= 0.12.0)
websocket-driver (>= 0.3.1)
ffi (1.9.3)
foreman (0.74.0)
dotenv (~> 0.11.1)
thor (~> 0.19.1)
httparty (0.13.1)
json (~> 1.8)
multi_xml (>= 0.5.2)
json (1.8.1)
lspace (0.13)
mock_redis (0.13.2)
multi_json (1.10.1)
multi_xml (0.5.5)
pg (0.17.1)
rack (1.5.2)
rack-protection (1.5.3)
rack
rack-test (0.6.2)
rack (>= 1.0)
rake (10.3.2)
redis (3.1.0)
redis-namespace (1.5.1)
redis (~> 3.0, >= 3.0.4)
rspec (3.0.0)
rspec-core (~> 3.0.0)
rspec-expectations (~> 3.0.0)
rspec-mocks (~> 3.0.0)
rspec-core (3.0.3)
rspec-support (~> 3.0.0)
rspec-expectations (3.0.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.0.0)
rspec-mocks (3.0.3)
rspec-support (~> 3.0.0)
rspec-support (3.0.3)
sequel (4.13.0)
sequel_model (3.8.0)
sequel (>= 3.8.0)
sidekiq (3.2.1)
celluloid (>= 0.15.2)
connection_pool (>= 2.0.0)
json
redis (>= 3.0.6)
redis-namespace (>= 1.3.1)
sidekiq-unique-jobs (3.0.2)
mock_redis
sidekiq (>= 2.6)
sinatra (1.4.5)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
sinatra-contrib (1.4.2)
backports (>= 2.0)
multi_json
rack-protection
rack-test
sinatra (~> 1.4.0)
tilt (~> 1.3)
slim (2.0.3)
temple (~> 0.6.6)
tilt (>= 1.3.3, < 2.1)
temple (0.6.8)
thin (1.6.2)
daemons (>= 1.0.9)
eventmachine (>= 1.0.0)
rack (>= 1.0.0)
thor (0.19.1)
tilt (1.4.1)
timers (1.1.0)
websocket-driver (0.3.4)

PLATFORMS
ruby

DEPENDENCIES
bitcoin-ruby!
bugsnag-em
database_cleaner
eventmachine
faye-websocket
ffi
foreman
pg
rack-test
rake
rspec
sequel
sequel_model
sidekiq
sidekiq-unique-jobs
sinatra
sinatra-contrib
slim
thin
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014 Coinbase, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 4 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
web: bundle exec thin --port $PORT start
block_worker: bundle exec sidekiq -q blocks -c 1 -r ./config/environment.rb
transaction_worker: bundle exec sidekiq -q transactions -c 1 -r ./config/environment.rb
peer_manager: bundle exec ruby bin/peer_manager.rb
104 changes: 104 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Toshi: Bitcoin Node

トシ - Bright, intelligent

## Prerequisites

Vagrant will install and run all prerequisites (postgresql, redis):

1. Install [Vagrant](http://www.vagrantup.com/)
2. Run `vagrant up` to install and run dependencies

Handy Vagrant Commands:

* Run `vagrant halt` to cleanly shut down your VM
* Run `vagrant reload --provision` to rebuild VM (won't lose existing data)
* Run `vagrant destroy` to completely remove VM

## Run using docker

* Make sure docker is installed
* Run `docker build -t=coinbase/node .` from the repo root
* Run `docker run -e REDIS_URL=redis://... -e DATABASE_URL=postgres://... -e TOSHI_ENV=production coinbase/node foreman start` to run all processes in the Procfile within a container

## Running Toshi

1. Run `gem install bundler` to install bundler
2. Run `bundle install` to install all necessary gems
3. Run `foreman run rake db:migrate` to update database schema
4. Run `foreman start` to start the magic

## Running Tests Locally

1. Create the test database with `bundle exec rake db:create
TOSHI_ENV=test`
2. Run `bundle exec rspec`

## Configuration

Toshi parses config/toshi.yml according to its current environment (determined
by the `TOSHI_ENV` environment variable). Toshi will default to the
`development` environment when run normally and the `test` environment during
rspec tests.

## HTTP API Draft

API consists of two parts:

1. Blockchain queries
2. Composing transactions (except for signing)

----------------------------------------------------

1. Blockchain queries:

* `.bin`: raw binary
* `.hex`: raw binary, in hex form
* `.json`: parsed in JSON dictionary (default if extension not specified)

For GET requests, extension specifies the format of the returned data.
For POST/PUT requests, extension specifies the format of the request body.

1. Blocks

GET /api/blocks(.json)

Block by hash or height:

GET /api/blocks/<hash>(.json)
GET /api/blocks/<height>(.json)
GET /api/blocks/latest(.json)

Block transactions:

GET /api/blocks/<hash>/transactions(.json)

2. Transactions

Transaction by hash:

GET /api/transactions/<hash>(.json, .hex, .bin)

Unconfirmed transaction pool:

GET /api/unconfirmed_transactions(.json)

3. Broadcasting transactions

Post a transaction in HTTP body in a proper format. We only allow hex or binary to avoid any ambiguity

POST /api/transactions(.hex)

4. Addresses

Address balance details:

GET /api/addresses/<hash>(.json)

Address transactions:

GET /api/addresses/<hash>/transactions(.json)

Address unspent outputs:

GET /api/addresses/<hash>/unspent_outputs(.json)
Loading

0 comments on commit d85dc04

Please sign in to comment.