Created
April 15, 2018 22:30
-
-
Save circulosmeos/ec550ad598569053f795c7e9e46947cd to your computer and use it in GitHub Desktop.
convert binary file //headers.electrum.org/blockchain_headers to CSV ASCII
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
#!/usr/bin/env python | |
# convert binary file http://headers.electrum.org/blockchain_headers | |
# to CSV ASCII | |
import binascii | |
STRUCT_OF_BLOCK = [ 4, 32, 32, 4, 4, 4 ] # blockchain_headers does not contain always "0x00" txn_count | |
BLOCK_SIZE = sum(STRUCT_OF_BLOCK) | |
FILE_OUT= open('blockchain_headers.csv','w') | |
FILE_OUT.write( "version,prev_block,merkle_root,timestamp,bits,nonce,txn_count\n" ) | |
with open('blockchain_headers','rb') as FILE: | |
block = FILE.read(BLOCK_SIZE) | |
while block != b'': | |
position = 0 | |
for i in STRUCT_OF_BLOCK: | |
FILE_OUT.write( bytearray(binascii.hexlify( block[position:(position+i)][::-1] )).decode('ascii') + ',') | |
position += i | |
if position >= BLOCK_SIZE: | |
FILE_OUT.write("00\n") # blockchain_headers does not contain always "0x00" txn_count | |
block = FILE.read(BLOCK_SIZE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment