To your functions could also be this dataset is adequate: http://headers.electrum.org/blockchain_headers
It accommodates simply the block headers. To get all headers (not simply the newest ones since a checkpoint block), you must clear the checkpoints.json file and let Electrum sync.
It’s binary, however will be simply transformed to a csv ASCII file with this Python script:
#!/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 doesn't comprise at all times "0x00" txn_count
BLOCK_SIZE = sum(STRUCT_OF_BLOCK)
FILE_OUT= open('blockchain_headers.csv','w')
FILE_OUT.write( "model,prev_block,merkle_root,timestamp,bits,nonce,txn_countn" )
with open('blockchain_headers','rb') as FILE:
block = FILE.learn(BLOCK_SIZE)
whereas block != b'':
place = 0
for i in STRUCT_OF_BLOCK:
FILE_OUT.write( bytearray(binascii.hexlify( block[position:(position+i)][::-1] )).decode('ascii') + ',')
place += i
if place >= BLOCK_SIZE:
FILE_OUT.write("00n") # blockchain_headers doesn't comprise at all times "0x00" txn_count
block = FILE.learn(BLOCK_SIZE)