2017-08-28 11:10:33 -06:00
|
|
|
# blockbook
|
|
|
|
|
|
|
|
## Install
|
|
|
|
|
2018-02-01 14:28:20 -07:00
|
|
|
Setup go environment (Debian 9):
|
2017-08-28 11:10:33 -06:00
|
|
|
|
|
|
|
```
|
|
|
|
sudo apt-get install git
|
2018-02-01 14:28:20 -07:00
|
|
|
wget https://storage.googleapis.com/golang/go1.9.2.linux-amd64.tar.gz
|
|
|
|
sudo mv go /usr/local
|
|
|
|
sudo ln -s /usr/local/go/bin/go /usr/bin/go
|
2017-08-28 11:10:33 -06:00
|
|
|
go help gopath
|
|
|
|
```
|
|
|
|
|
|
|
|
Install RocksDB: https://github.com/facebook/rocksdb/blob/master/INSTALL.md
|
|
|
|
|
|
|
|
```
|
2018-02-01 14:28:20 -07:00
|
|
|
sudo apt-get install libgflags-dev libsnappy-dev zlib1g-dev libbz2-dev liblz4-dev
|
|
|
|
git clone https://github.com/facebook/rocksdb.git
|
|
|
|
cd rocksdb
|
2017-08-28 11:10:33 -06:00
|
|
|
make static_lib
|
|
|
|
```
|
|
|
|
|
|
|
|
Install gorocksdb: https://github.com/tecbot/gorocksdb
|
|
|
|
|
|
|
|
```
|
|
|
|
CGO_CFLAGS="-I/path/to/rocksdb/include" \
|
2018-02-01 14:28:20 -07:00
|
|
|
CGO_LDFLAGS="-L/path/to/rocksdb -lrocksdb -lstdc++ -lm -lz -lbz2 -lsnappy -llz4" \
|
2017-08-28 11:10:33 -06:00
|
|
|
go get github.com/tecbot/gorocksdb
|
|
|
|
```
|
|
|
|
|
2018-01-19 07:58:46 -07:00
|
|
|
Install ZeroMQ: https://github.com/zeromq/libzmq
|
|
|
|
|
|
|
|
Install Go interface to ZeroMQ:
|
|
|
|
```
|
|
|
|
go get github.com/pebbe/zmq4
|
|
|
|
```
|
|
|
|
|
2018-01-30 10:22:25 -07:00
|
|
|
Install glog logging:
|
|
|
|
```
|
|
|
|
go get github.com/golang/glog
|
|
|
|
```
|
|
|
|
|
2017-08-28 11:10:33 -06:00
|
|
|
Install blockbook:
|
|
|
|
|
|
|
|
```
|
2018-02-01 14:28:20 -07:00
|
|
|
cd $GOPATH/src
|
|
|
|
git clone https://github.com/jpochyla/blockbook.git
|
|
|
|
cd blockbook
|
|
|
|
go build
|
2017-08-28 11:10:33 -06:00
|
|
|
```
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
```
|
|
|
|
$GOPATH/bin/blockbook --help
|
2018-01-25 10:04:35 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
# Data storage in RocksDB
|
|
|
|
|
2018-01-30 02:04:09 -07:00
|
|
|
Blockbook stores data the key-value store RocksDB. Data are stored in binary form to save space.
|
2018-01-27 16:30:55 -07:00
|
|
|
The data are separated to different column families:
|
2018-01-25 10:04:35 -07:00
|
|
|
|
|
|
|
- **default**
|
|
|
|
|
|
|
|
at the moment not used, will store statistical data etc.
|
|
|
|
|
2018-01-27 16:30:55 -07:00
|
|
|
- **height** - maps *block height* to *block hash*
|
2018-01-25 10:04:35 -07:00
|
|
|
|
2018-01-30 02:04:09 -07:00
|
|
|
*Block heigh* stored as array of 4 bytes (big endian uint32)
|
|
|
|
*Block hash* stored as array of 32 bytes
|
2018-01-25 10:04:35 -07:00
|
|
|
|
|
|
|
Example - the first four blocks (all data hex encoded)
|
|
|
|
```
|
2018-01-30 02:04:09 -07:00
|
|
|
0x00000000 : 0x000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943
|
|
|
|
0x00000001 : 0x00000000b873e79784647a6c82962c70d228557d24a747ea4d1b8bbe878e1206
|
|
|
|
0x00000002 : 0x000000006c02c8ea6e4ff69651f7fcde348fb9d557a06e6957b65552002a7820
|
|
|
|
0x00000003 : 0x000000008b896e272758da5297bcd98fdc6d97c9b765ecec401e286dc1fdbe10
|
2018-01-25 10:04:35 -07:00
|
|
|
```
|
|
|
|
|
2018-01-30 02:04:09 -07:00
|
|
|
- **outputs** - maps *output script+block height* to *array of outpoints*
|
2018-01-25 10:04:35 -07:00
|
|
|
|
2018-01-30 02:04:09 -07:00
|
|
|
*Output script (ScriptPubKey)+block height* stored as variable length array of bytes for output script + 4 bytes (big endian uint32) block height
|
|
|
|
*array of outpoints* stored as array of 32 bytes for transaction id + variable length outpoint index for each outpoint
|
2018-01-25 10:04:35 -07:00
|
|
|
|
|
|
|
Example - (all data hex encoded)
|
|
|
|
```
|
2018-01-30 02:04:09 -07:00
|
|
|
0x001400efeb484a24a1c1240eafacef8566e734da429c000e2df6 : 0x1697966cbd76c75eb9fc736dfa3ba0bc045999bab1e8b10082bc0ba546b0178302
|
|
|
|
0xa9143e3d6abe282d92a28cb791697ba001d733cefdc7870012c4b1 : 0x7246e79f97b5f82e7f51e291d533964028ec90be0634af8a8ef7d5a903c7f6d301
|
2018-01-25 10:04:35 -07:00
|
|
|
```
|
|
|
|
|
2018-01-27 16:30:55 -07:00
|
|
|
- **inputs** - maps *transaction outpoint* to *input transaction* that spends it
|
|
|
|
|
2018-01-30 02:04:09 -07:00
|
|
|
*Transaction outpoint* stored as array of 32 bytes for transaction id + variable length outpoint index
|
|
|
|
*Input transaction* stored as array of 32 bytes for transaction id + variable length input index
|
2018-01-27 16:30:55 -07:00
|
|
|
|
|
|
|
Example - (all data hex encoded)
|
|
|
|
```
|
|
|
|
0x7246e79f97b5f82e7f51e291d533964028ec90be0634af8a8ef7d5a903c7f6d300 : 0x0a7aa90ea0269c79f844c516805e4cac594adb8830e56fca894b66aab19136a428
|
|
|
|
0x7246e79f97b5f82e7f51e291d533964028ec90be0634af8a8ef7d5a903c7f6d301 : 0x4303a9fcfe6026b4d33ba488df6443c9a99bca7b7fcb7c6f6cd65cea24a749b700
|
|
|
|
```
|