-
Notifications
You must be signed in to change notification settings - Fork 193
Made pchMessageStart variable so it works with altcoins #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Thanks for your contribution! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would leave the BITCOIN_CONSTANT constant.
@@ -16,10 +16,6 @@ | |||
from .block import Block | |||
|
|||
|
|||
# Constant separating blocks in the .blk files | |||
BITCOIN_CONSTANT = b"\xf9\xbe\xb4\xd9" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would leave this constat here.
@@ -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"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would write pchMessageStart=BITCOIN_CONSTANT
here.
@@ -63,13 +59,14 @@ class Blockchain(object): | |||
maintained by bitcoind. | |||
""" | |||
|
|||
def __init__(self, path): | |||
def __init__(self, path, pchMessageStart=b"\xf9\xbe\xb4\xd9"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would write pchMessageStart=BITCOIN_CONSTANT
here.
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:
Or perhaps there is a better name to expose to the user. What does the "pch" in pchMessageStart stand for? |
I think |
Note that supporting altcoins would also include changing the version byte for addresses. |
It might also make sense to add this functionality in the # 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) |
We could also do it à la |
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 |
Magic number seems to be the appropriate name for the constant block separator. For what it's worth ;) |
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:
To use with bitcoin:
and dash: