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 _read_CDiskTxPos(stream):
17 n_file = stream.read_uint32()
18 n_block_pos = stream.read_uint32()
19 n_tx_pos = stream.read_uint32()
20 return (n_file, n_block_pos, n_tx_pos)
22 def dump_blockindex(db_env, owner=None, n_to_dump=1000):
24 r = db.open("blkindex.dat", "main", DB_BTREE, DB_THREAD|DB_RDONLY)
26 logging.error("Couldn't open blkindex.dat/main")
32 wallet_transactions = []
34 for (i, (key, value)) in enumerate(db.items()):
38 kds.clear(); kds.write(key)
39 vds.clear(); vds.write(value)
41 type = kds.read_string()
44 hash256 = kds.read_bytes(32)
45 version = vds.read_uint32()
46 tx_pos = _read_CDiskTxPos(vds)
47 print("Tx(%s:%d %d %d)"%((short_hex(hash256),)+tx_pos))
48 n_tx_out = vds.read_compact_size()
49 for i in range(0,n_tx_out):
50 tx_out = _read_CDiskTxPos(vds)
51 if tx_out[0] != 0xffffffffL: # UINT_MAX means no TxOuts (unspent)
52 print(" ==> TxOut(%d %d %d)"%tx_out)
55 logging.warn("blkindex: type %s"%(type,))