Created
April 2, 2021 06:54
-
-
Save PiRK/4ed6adec3b8f9cfa7a7a09b9f676ea74 to your computer and use it in GitHub Desktop.
Print the coinbase data for all ancestors of a block, up to a specified block height
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import subprocess | |
tip = "00000000000000002b3ca56c3fdef9a74b8758bc7da5d9c9aecd79ed922a3692" | |
FORK_HEIGHT = 679555 | |
def print_chain(tip_hash: str, min_height: int = FORK_HEIGHT): | |
"""Print block information starting at a given chain tip and going | |
backward up to (and including) the block with height min_height""" | |
block = json.loads(subprocess.check_output( | |
['bitcoin-cli', 'getblock', tip_hash])) | |
height = block["height"] | |
if height < min_height: | |
return | |
coinbase_id = block["tx"][0] | |
print(f"Block height {height}; hash {tip_hash}; coinbase tx {coinbase_id}") | |
tx = json.loads(subprocess.check_output( | |
['bitcoin-cli', 'getrawtransaction', coinbase_id, "true", tip_hash])) | |
coinbase_data = bytes.fromhex(tx["vin"][0]["coinbase"]) | |
print(coinbase_data) | |
assert b"ZULUPooL-" in coinbase_data | |
parent_hash = block["previousblockhash"] | |
print_chain(parent_hash, min_height) | |
if __name__ == '__main__': | |
print_chain(tip, FORK_HEIGHT) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment