bitcoin-explorer
bitcoin_explorer
is an efficient library for reading
bitcoin-core binary blockchain file as a database (utilising multi-threading).
This package uses pyO3. Thus is also available in python.
How to install?
This library is designed for both python and rust.
For rust users, include bitcoin-explorer="0.1"
in Cargo.toml
.
For python users, pip install bitcoin-explorer
.
Install Requirements
Currently, only macOS py39 wheels are provided.
For pip to build the package on other OS or python version,
make sure that rust
toolchain is installed,
and cmake
is also installed.
Documentation
For rust users, go to Rust Documentation
For python documentation, go to Documentation.
Compatibility Note
This package deals with the binary file of another software Bitcoin Core
.
It might not be compatible with older Bitcoin Core versions.
Currently, it is compatible with Bitcoin Core version
Bitcoin Core version v0.21.1.0-g194b9b8792d9b0798fdb570b79fa51f1d1f5ebaf Copyright (C) 2009-2020 The Bitcoin Core developers
.
Performance
The current performance bottleneck is disk IO. SSD allows faster performance.
On HDD, iterating from heights 600000 to 700000 takes less than 30 minutes.
Iterating through connected blocks
from 0 to 700000 takes 5 hours.
Rust Examples
get a complete block (full format (i.e., see doc for what is full/simple format))
use ;
use Path;
let path = new.unwrap;
// launch without reading txindex
let db = new.unwrap;
// get block of height 600000
let block: FBlock = db.get_block_full.unwrap;
get a particular transaction
use ;
use Path;
let path = new.unwrap;
// !!must launch with txindex=true!!
let db = new.unwrap;
// get transaction
// e3bf3d07d4b0375638d5f1db5255fe07ba2c4cb067cd81b84ee974b6585fb468
let txid_str = "e3bf3d07d4b0375638d5f1db5255fe07ba2c4cb067cd81b84ee974b6585fb468";
let txid = from_hex.unwrap;
let tx: STransaction = db.get_transaction_simple.unwrap;
Iterate through blocks
use BitcoinDB;
use Path;
let path = new.unwrap;
// launch without reading txindex
let db = new.unwrap;
// iterate over block from 600000 to 700000
for block in db.get_block_full_iter_seq
Iterate through blocks (simple format) with outpoints connected to outputs
use BitcoinDB;
use Path;
let path = new.unwrap;
// launch without reading txindex
let db = new.unwrap;
// iterate over block from 0 to 700000
for block in db.get_block_simple_connected_iter
Python Examples
It contains one class BitcoinDB
.
# parse the same path as `--datadir` argument for `bitcoind`.
=
# get the length of the longest chain currently on disk.
# get block of a certain height
# to retrieve the connected outputs of each inputs as well
# get block hash of a certain height.
# a fast method for getting just the header.
# in memory query, no disk access
# get block of height 1000.
# get transaction from txid.
# This queries the `levelDB` each time, thus it is relatively slow.
# get the height of the block which this transaction belongs.
# get the script type and addresses from a script public key
# use iterator
# use iterator, iterate over heights
# use iterator, connect outpoints