Giter Club home page Giter Club logo

toshi's Introduction

Toshi

Build Status Code Climate Inline Docs

Toshi is a complete implementation of the Bitcoin protocol, written in Ruby and backed by PostgreSQL. It provides a RESTful API that is ideal for building scalable web applications or analyzing blockchain data.

Toshi is designed to be fully compatible with Bitcoin Core. It performs complete transaction and block validation, and passes 100% of TheBlueMatt's regression test suite. For much of the core protocol logic, Toshi makes use of the bitcoin-ruby library written and maintained by Julian Langschaedel.

Toshi was built at Coinbase, with the goal of replacing our core Bitcoin network infrastructure in the near future. It is currently in beta, and not recommended for production use until it has received sufficient testing from the Bitcoin community.

You can see Toshi running on various networks at the following URLs:

Features

  • Complete Bitcoin node implementation
  • Fully passes TheBlueMatt's regression test suite
  • PostgreSQL backed (more convenient for web applications and research)
  • JSON, Hex, and Binary API
  • Simple web interface to monitor node status

What is a Bitcoin node?

A Bitcoin node is simply a client on the Bitcoin peer-to-peer network. It validates and relays transactions and blocks to other clients according to the consensus rules as implemented in Bitcoin Core. A "full node" implies that the client retains a complete copy of the Bitcoin blockchain.

Toshi vs. Bitcoin Core

Toshi is a Bitcoin implementation designed for building highly scalable web applications. It allows you to query the blockchain using a REST API or raw SQL. It comprises a number of individual services, using a shared database. Because Toshi saves much more information and indexes more data than Bitcoin Core, it requires much more space to store the blockchain (~220GB vs ~25GB as of September 2014). However, this makes it possible to run much richer queries that would otherwise not be possible with Bitcoin Core.

Bitcoin Core (the reference implementation) is designed to run on a single server, and uses a mixture of raw files and LevelDB to store the blockchain. It allows you to query the blockchain using a JSON-RPC interface.

Some examples of queries which Toshi can easily answer, which are not possible with Bitcoin Core:

  • List all unspent outputs for any address (Bitcoin Core only indexes unspent outputs for specific addresses added to the local "wallet").
  • Get the balance of any address
  • Get the balance of any address at a specific point in time
  • Find all transactions for any address
  • Find all transactions in a certain time period
  • Find all transactions over a certain amount
  • Find all transactions given a set of addresses

Usage

Hosted Toshi

Coinbase maintains a hosted version of Toshi that you can use at:

https://bitcoin.toshi.io

This is the easiest way to get up and running. You can also run your own version of Toshi as described below.

Running Toshi locally

$ git clone https://github.com/coinbase/toshi.git
$ cd toshi

We use Docker with Docker Compose:

$ docker-compose build
$ docker-compose up -d db
$ docker-compose run web bundle exec rake db:create
$ docker-compose up -d
$ open localdocker:5000 # use `boot2docker ip` for the address if using boot2docker

Testing

You can run the test suite for Toshi as follows:

$ git submodule init
$ git submodule update
$ docker-compose build
$ docker-compose run -e TOSHI_ENV=test web bundle exec rake db:create

$ docker-compose run -e TOSHI_ENV=test web bundle exec rspec

Bootstrap.dat

Toshi can import the standard bootstrap.dat file that bitcoind uses to load the beginning of the blockchain using the ./bin/bootstrap.rb command.

export BOOTSTRAP_FILE=/path/to/bootstrap.dat
export TOSHI_ENV=production
./bin/bootstrap.rb

Deployment

Toshi can be deployed directly to Heroku:

Deploy

After it is deployed, you can start syncing with the following command:

$ heroku ps:scale web=1 peer_manager=1 block_worker=1 transaction_worker=1

For more detailed Heroku deployment instructions you can read this page.

Toshi can also be installed on your own server. You will need:

  • PostgreSQL (300gb+ disk space required to sync mainnet)
  • Redis (50mb+ RAM recommended)
  • Ruby 2.0.0+

To run Toshi on your server, simply:

$ git clone https://github.com/coinbase/toshi.git
$ cd toshi
$ cp config/toshi.yml.example config/toshi.yml
$ vi config/toshi.yml
$ REDIS_URL=redis://... DATABASE_URL=postgres://... TOSHI_ENV=production bundle exec foreman start

API

Note: The Toshi API provides raw blockchain data only. If you are looking for APIs to store bitcoin securely, buy/sell bitcoin, send/request bitcoin, accept merchant payments, etc) please check out the proprietary Coinbase API.

The API supports three data types by adding an extension on any URL.

.json - JSON (default if none specified) .hex - raw binary, in hex form .bin - raw binary

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

Any API call which returns as list can also be passed an offset or limit parameter. The default limit is 100.

# Blocks
GET /api/v0/blocks                             # Get a paginated list of blocks
GET /api/v0/blocks/<hash>                      # Get a block by hash
GET /api/v0/blocks/<height>                    # Get a block by height
GET /api/v0/blocks/latest                      # Get the latest block
GET /api/v0/blocks/<hash>/transactions         # Get transactions in a block

# Transactions
GET /api/v0/transactions/<hash>                # Get transaction by hash
GET /api/v0/transactions/unconfirmed           # Get list of unconfirmed transactions
POST /api/v0/transactions                      # Broadcast a transaction to the network

# Addresses
GET /api/v0/addresses/<hash>                   # Get address balance and details
GET /api/v0/addresses/<hash>/transactions      # Get address transactions
GET /api/v0/addresses/<hash>/unspent_outputs   # Get unspent outputs on an address

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 if one isn't specified and the test environment during rspec tests.

Toshi will use the config/toshi.yml.example file if the config/toshi.yml file does not exist.

Contributing

  1. Fork this repo and make changes in your own fork
  2. Run existing tests with bundle exec rspec and add a new test for your changes if applicable.
  3. Commit your changes and push to your fork git push origin master
  4. Create a new pull request and submit it back to the project.

toshi's People

Contributors

aalness avatar barmstrong avatar lian avatar coblee avatar se3000 avatar hudon avatar maksim-s avatar csquared avatar samo-drole avatar amacneil avatar rrrene avatar leishman avatar george-carlin avatar sneak avatar jimpo avatar witoff avatar nicholalexander avatar shaulkf avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.