8fca690c8e46c57759c01594af6359046d087986
[novacoin.git] / bitcointools / address.py
1 #
2 # Code for parsing the addr.dat file
3 # NOTE: I think you have to shutdown the Bitcoin client to
4 # successfully read addr.dat...
5 #
6
7 from bsddb.db import *
8 import logging
9 from operator import itemgetter
10 import sys
11 import time
12
13 from BCDataStream import *
14 from base58 import public_key_to_bc_address
15 from util import short_hex
16 from deserialize import *
17
18 def dump_addresses(db_env):
19   db = DB(db_env)
20   try:
21     r = db.open("addr.dat", "main", DB_BTREE, DB_THREAD|DB_RDONLY)
22   except DBError:
23     r = True
24
25   if r is not None:
26     logging.error("Couldn't open addr.dat/main. Try quitting Bitcoin and running this again.")
27     sys.exit(1)
28
29   kds = BCDataStream()
30   vds = BCDataStream()
31
32   for (key, value) in db.items():
33     kds.clear(); kds.write(key)
34     vds.clear(); vds.write(value)
35
36     type = kds.read_string()
37
38     if type == "addr":
39       d = parse_CAddress(vds)
40       print(deserialize_CAddress(d))
41
42   db.close()