python-bitcoin-blockchain-parser icon indicating copy to clipboard operation
python-bitcoin-blockchain-parser copied to clipboard

Made pchMessageStart variable so it works with altcoins

Open priestc opened this issue 7 years ago • 8 comments

The variable name pchMessageStart comes from the variable name in the bitcoin C++ code:

https://github.com/dashpay/dash/blob/master/src/chainparams.cpp#L115 https://github.com/dogecoin/dogecoin/blob/master/src/chainparams.cpp#L82

This allows this library to work on altcoins.

To use with litecoin:

>>> ltc=Blockchain('/media/chris/3033-6537/litecoin/blocks', b"\xfb\xc0\xb6\xdb")
>>> next(ltc.get_unordered_blocks())
Block(12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2)

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)

priestc avatar Apr 22 '17 02:04 priestc

Thanks for your contribution! The code looks good to me, I'll merge it once you revert the changes to the README

alecalve avatar Apr 24 '17 18:04 alecalve

I agree with @sembrestels that it would be nice to have a constant variable that equals the Bitcoin header. It would also be nice if there were also a few altcoin headers that we included for convenience as well. Perhaps:

blockchain.BITCOIN_CONSTANT
blockchain.LITECOIN_CONSTANT
blockchain.DASH_CONSTANT

Or perhaps there is a better name to expose to the user. What does the "pch" in pchMessageStart stand for?

brannondorsey avatar Feb 26 '18 17:02 brannondorsey

I think pch is some bitcoind C++ jargon. I agree with providing some defaults one (maybe including testnet and BCH)

alecalve avatar Feb 26 '18 17:02 alecalve

Note that supporting altcoins would also include changing the version byte for addresses.

alecalve avatar Feb 26 '18 17:02 alecalve

It might also make sense to add this functionality in the Blockchain() constructor. Something like:

# not sure if this is the real litecoin directory name, but you get the idea
# not sure what the best name is for "block_separator". blockchain? type?
blockchain = Blockchain('~/.litecoin/blocks', block_seperator=blockchain.LITECOIN)

brannondorsey avatar Feb 26 '18 17:02 brannondorsey

We could also do it à la bitcoinj where a params object is used which encapsulates all the variable parameters for a given chain (genesis block, separator, version bytes for addresses, etc..).

alecalve avatar Feb 26 '18 18:02 alecalve

Yeah, that is nice. Makes it clean and a bit more extensible for blockchains that potentially don't exist yet. We could have a few pre-filled objects for common coins and networks that a user could use by default by passing them along in the constructor via a named parameter e.g. blockchain=blockchain.LITECOIN. But then if a user wanted to parse a new blockchain it would be as simple creating an object with all of the right properties.

brannondorsey avatar Feb 26 '18 18:02 brannondorsey

Magic number seems to be the appropriate name for the constant block separator. For what it's worth ;)

brannondorsey avatar Feb 27 '18 15:02 brannondorsey