以 Rust 语言编写的 Bitcoin 区块链解析器
rusty-blockparser is a Bitcoin Blockchain Parser that enables data extraction of various types (e.g.: blocks, transactions, scripts, public keys / hashes, balances) and full UTXO dumps.
⚠️ I removed this project from crates.io, as there is no point having this niche CLI hosted there. From now on GitHub is the only official source. The releases can be found here.
Bitcoin, Namecoin, Litecoin, Dogecoin, Myriadcoin, Unobtanium and NoteBlockchain.
IMPORTANT: A local unpruned copy of the blockchain with intact block index and blk files, downloaded
with Bitcoin Core 0.15.1+ or similar clients is required.
If you are not sure whether your local copy is valid you can apply --verify to validate the blockdata and block merkle
trees.
Bitcoin and Bitcoin Testnet transactions are parsed using rust-bitcoin, this includes transactions of type P2SH, P2PKH, P2PK, P2WSH, P2WPKH, P2TR, P2MS, OP_RETURN and SegWit.
Bitcoin forks (e.g.: Dogecoin, Litecoin, etc.) are evaluated via a custom script implementation which includes P2PK, P2PKH, P2SH, P2MS and OP_RETURN.
Data is being extracted via callbacks which are built on top of the core parser. They can be easily extended to extract specific types of information and can be found here.
The command balances extracts the balance of all known addresses and dumps it to a csv file called balances.csv with
the following format:
balances.csv: address ; balanceThe command unspentcsvdump can be used to dump all UTXOs
with their corresponding address balance to a csv file called unspent.csv.
The csv file is in the following format:
unspent.csv: txid ; indexOut ; height ; value ; addressNOTE: The total size of the csv dump is at least 8 GiB (height 635000).
The command opreturn can be used to show all embedded OP_RETURN data in the terminal that contains valid UTF8.
The command csvdump dumps all data to csv files. This data can be imported to a database for further analysis.
NOTE: The total size of the csv dump is at least 731 GiB (height 635,000).
The files are in the following format:
blocks.csv: block_hash ; height ; version ; blocksize ; hashPrev ; hashMerkleRoot ; nTime ; nBits ; nNoncetransactions.csv: txid ; hashBlock ; version ; lockTimetx_in.csv: txid ; hashPrevOut ; indexPrevOut ; scriptSig ; sequencetx_out.csv: txid ; indexOut ; height ; value ; scriptPubKey ; addressSee the block and transaction specifications if some of the fields are unclear. If you want to insert the files into MySql see sql/schema.sql (but be aware this hasn't been tested and used for quite some time now). It contains all table structures and SQL statements for bulk inserting. Also see sql/views.sql for some query examples.
The command simplestats can be used to show blockchain statistics, e.g.:
…To make a unspentcsvdump of the Bitcoin blockchain your command would look like this:
…This tool should run on Windows, OS X and Linux.
All you need is rust and cargo.
git clone https://github.com/gcarq/rusty-blockparser.git
cd rusty-blockparser
cargo build --release
cargo test
./target/release/rusty-blockparser --helpIMPORTANT: Building with --release is essential for performance.
Tested on Gentoo Linux with rust-stable 1.85.0
The required memory usage depends on the used callback:
NOTE: Those values are taken from parsing to block height 639,631 (17.07.2020).
Use the issue tracker to report problems, suggestions and questions. You may also contribute by submitting pull requests.
If you find this project helpful, please consider making a donation:
1LFidBTeg5joAqjw35ksebiNkVM8azFM1K
The tool can easily be customized to your coin. This section outlines the changes that need to be made and is for users not familiar with Rust and Blockchain. During this example the coin name used is NoCoinium.
src/blockchain/parser/types.rs.pub struct NoCoinium similar to other definitions.impl Coin for NoCoinium. You could easily copy a previous block e.g. Bitcoin. The
changes you need to do are highlighted below as comments…impl FromStr for CoinType under match coin_name. The first part will be the
string passed as argument to the program (see bullet point below) and the name within from() will be the name used
above. "bitcoin" => Ok(CoinType::from(Bitcoin)),
...
"nocoinium" => Ok(CoinType::from(NoCoinium)),
...src/main.rs. Under the fn parse_args() add your coin to the array of coins. The case you use
here will be the same value as you pass in the arguments when executing the blockchain (using the -c argument)暂无开放 Issues,或尚未同步最近议题。