diff --git a/README.md b/README.md index 709ab38..4efbbf6 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,23 @@ -# bitcoin-blockchain-parser [![Build Status](https://travis-ci.org/alecalve/python-bitcoin-blockchain-parser.svg?branch=master)](https://travis-ci.org/alecalve/python-bitcoin-blockchain-parser) [![Coverage Status](https://coveralls.io/repos/alecalve/python-bitcoin-blockchain-parser/badge.svg?branch=master&service=github)](https://coveralls.io/github/alecalve/python-bitcoin-blockchain-parser?branch=master) -This Python 3 library provides a parser for the raw data stored by bitcoind. +This is a fork of the `bitcoin-blockchain-parser` project found here: +https://github.com/alecalve/python-bitcoin-blockchain-parser -## Features -- Detects outputs types -- Detects addresses in outputs -- Interprets scripts +Differences include: Modifications to make parsing work with altcoins such as +Dash, Dogecoin, Litecoin and Feathercoin. -## Examples +To use with litecoin: -```python -import sys -from blockchain_parser.blockchain import Blockchain + >>> ltc=Blockchain('/media/chris/3033-6537/litecoin/blocks', b"\xfb\xc0\xb6\xdb") + >>> next(ltc.get_unordered_blocks()) + Block(12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2) -# Instanciate the Blockchain by giving the path to the directory -# containing the .blk files created by bitcoind -blockchain = Blockchain(sys.argv[1]) -for block in blockchain.get_unordered_blocks(): - for tx in block.transactions: - for no, output in enumerate(tx.outputs): - print("tx=%s outputno=%d type=%s value=%s" % (tx.hash, no, output.type, output.value)) -``` - -More examples are available in the examples directory. - -## Installing - -Requirements : python-bitcoinlib, coverage for tests - -To install, just run -``` -python setup.py install -``` - -## Tests - -Run the test suite by lauching -``` -./tests.sh -``` +To use with bitcoin: + >>> btc=Blockchain('/home/chris/.bitcoin/blocks/') + >>> next(btc.get_unordered_blocks()) + Block(000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f) +and dash: + >>> dash=Blockchain('/media/chris/3033-6537/dash/blocks', b"\xbf\x0c\x6b\xbd") + >>> next(dash.get_unordered_blocks()) + Block(089fc444b06edd0f70d9fda85f9a3b2e22e549b354a1bdb210ce7804c69eb0a4) diff --git a/blockchain_parser/blockchain.py b/blockchain_parser/blockchain.py index ba81237..5b4a964 100644 --- a/blockchain_parser/blockchain.py +++ b/blockchain_parser/blockchain.py @@ -16,10 +16,6 @@ from .block import Block -# Constant separating blocks in the .blk files -BITCOIN_CONSTANT = b"\xf9\xbe\xb4\xd9" - - def get_files(path): """ Given the path to the .bitcoin directory, returns the sorted list of .blk @@ -31,7 +27,7 @@ def get_files(path): return sorted(files) -def get_blocks(blockfile): +def get_blocks(blockfile, pchMessageStart=b"\xf9\xbe\xb4\xd9"): """ Given the name of a .blk file, for every block contained in the file, yields its raw hexadecimal value @@ -47,7 +43,7 @@ def get_blocks(blockfile): offset = 0 block_count = 0 while offset < (length - 4): - if raw_data[offset:offset+4] == BITCOIN_CONSTANT: + if raw_data[offset:offset+4] == pchMessageStart: offset += 4 size = struct.unpack("