2 # Code for parsing the blkindex.dat file
7 from operator import itemgetter
11 from BCDataStream import *
12 from base58 import public_key_to_bc_address
13 from util import short_hex
14 from deserialize import *
16 def dump_blkindex_summary(db_env):
19 r = db.open("blkindex.dat", "main", DB_BTREE, DB_THREAD|DB_RDONLY)
24 logging.error("Couldn't open blkindex.dat/main. Try quitting any running Bitcoin apps.")
33 print("blkindex file summary:")
34 for (key, value) in db.items():
35 kds.clear(); kds.write(key)
36 vds.clear(); vds.write(value)
38 type = kds.read_string()
42 elif type == "blockindex":
44 elif type == "version":
45 version = vds.read_int32()
46 print(" Version: %d"%(version,))
47 elif type == "hashBestChain":
48 hash = vds.read_bytes(32)
49 print(" HashBestChain: %s"%(hash.encode('hex_codec'),))
51 logging.warn("blkindex: unknown type '%s'"%(type,))
54 print(" %d transactions, %d blocks."%(n_tx, n_blockindex))