crawler parses Bitcoin blk*.dat files and streams parsed data to stdout.
The parser reads block headers and transactions, computes hashes, and emits one of two output formats:
sqlmode (default): SQLINSERTstatements forblock,tx, andoutdebugmode: verbose human-readable parsed fields
This is intended for fast offline ingestion/inspection of raw blockchain block files.
src/main.copens a.datfile and selects exporter mode.src/blk_dat_parser.cparses blocks and transactions from the binary stream.src/export_dispatch.croutes eachexport_*callback to the active backend.- Backend writes formatted output to
stdout.
The same crawl binary supports both backends at runtime.
- CLI argument:
./build/crawl <dat-file> [sql|debug] - Environment variable:
CRAWL_EXPORT_MODE=sql|debug
Examples:
./build/crawl tests/blk01985.dat
./build/crawl tests/blk01985.dat debug
CRAWL_EXPORT_MODE=debug ./build/crawl tests/blk01985.datIf both are set, the CLI argument takes precedence.
Requirements:
gcc- OpenSSL development headers/libs (
libcrypto) - POSIX environment (Linux/macOS shell)
Build:
makeOutput binary:
build/crawl
Generate SQL from a dat file:
./build/crawl /path/to/blk01985.dat > blk01985.sqlPipe directly into SQLite:
(
echo "BEGIN TRANSACTION;"
echo "PRAGMA foreign_keys = ON;"
./build/crawl /path/to/blk01985.dat
echo "COMMIT;"
) | sqlite3 blk01985.dbThis benchmark is only a reference point. Runtime depends on CPU, storage speed, kernel, compiler, and current system load.
Benchmark fixture:
- Input file:
tests/blk01985.dat - Input size:
133,521,047 bytes(~128 MiB)
Command profile:
- Build flags:
-O3 -march=native -DNDEBUG -flto - Runtime command:
./build/crawl tests/blk01985.dat [sql|debug] - Timing method: shell
time, 5 runs, output redirected to/dev/null
Measured output volume:
- SQL mode:
932,915lines,199,899,261bytes - Debug mode:
8,686,021lines,604,436,703bytes
Measured runtime (this machine):
- SQL mode average:
2.697 s(runs:2.759, 2.737, 2.639, 2.683, 2.669) - Debug mode average:
3.019 s(runs:3.104, 3.069, 2.977, 2.968, 2.977)
Reference machine info:
- OS:
Linux 6.1.0-42-amd64 x86_64 - CPU:
Intel(R) Core(TM) i5-8300H CPU @ 2.30GHz(4 cores / 8 threads, up to 4.00 GHz) - RAM:
15 GiB
How to extend benchmarks:
- Add more fixtures under
tests/(small, medium, large) - Add a script that runs each fixture in both modes and logs:
- input size
- output size
- average/median runtime across N runs
- output hash for SQL mode regression stability
Testing requires the presence of the file tests/blk01985.dat.
This is the .dat file from the blockchain, not included in the repo because of its size.
Run unit tests:
make unit-testUnit test binaries:
build/test_blk_dat_parserbuild/test_block_commonbuild/test_main
Run integration test:
make integration-testIntegration test checks:
- SQL output hash for
tests/blk01985.dat - non-zero exit on a truncated fixture
Run full test suite:
make testClean build artifacts:
make cleansrc/main.c: CLI entrypoint and mode selectionsrc/blk_dat_parser.c,src/blk_dat_parser.h: block/transaction parser coresrc/export_dispatch.c: runtime dispatch to active exporter backendsrc/export_block.c: SQL exporter backendsrc/export_debug.c: debug-text exporter backendsrc/export_block.h: shared exporter APIsrc/block_common.c,src/block_common.h: shared output-buffer utilitiestests/: unit and integration tests plus test fixtures