@@ -24,18 +24,47 @@ def read_dump(file_name, addrs, hd_master_addr_old):
2424 # only read non comment lines
2525 if line [0 ] != "#" and len (line ) > 10 :
2626 # split out some data
27- key_label , comment = line .split ("#" )
28- # key = key_label.split(" ")[0]
29- keytype = key_label .split (" " )[2 ]
30- addr = comment .split (" addr=" )[1 ].strip ()
27+ key_date_label , comment = line .split ("#" )
28+ key_date_label = key_date_label .split (" " )
29+
30+ date = key_date_label [1 ]
31+ keytype = key_date_label [2 ]
32+
33+ imported_key = date == '1970-01-01T00:00:01Z'
34+ if imported_key :
35+ # Imported keys have multiple addresses, no label (keypath) and timestamp
36+ # Skip them
37+ continue
38+
39+ addr_keypath = comment .split (" addr=" )[1 ]
40+ addr = addr_keypath .split (" " )[0 ]
41+ keypath = None
42+
43+ if keytype == "hdseed=1" :
44+ # ensure we have generated a new hd master key
45+ assert hd_master_addr_old != addr
46+ hd_master_addr_ret = addr
47+ elif keytype == "script=1" :
48+ # scripts don't have keypaths
49+ keypath = None
50+ else :
51+ keypath = addr_keypath .rstrip ().split ("hdkeypath=" )[1 ]
3152
3253 # count key types
33- if addr in addrs :
34- found_addr += 1
35- elif keytype == "change=1" :
36- found_addr_chg += 1
37- elif keytype == "reserve=1" :
38- found_addr_rsv += 1
54+ for addrObj in addrs :
55+ if addrObj ['address' ] == addr .split ("," )[0 ] and addrObj ['hdkeypath' ] == keypath and keytype == "label=" :
56+ if addr .startswith ('x' ) or addr .startswith ('y' ):
57+ # P2PKH address
58+ found_addr += 1
59+ # else: todo: add staking/anonymous addresses here
60+ break
61+ elif keytype == "change=1" :
62+ found_addr_chg += 1
63+ break
64+ elif keytype == "reserve=1" :
65+ found_addr_rsv += 1
66+ break
67+
3968 return found_addr , found_addr_chg , found_addr_rsv , hd_master_addr_ret
4069
4170
@@ -60,8 +89,8 @@ def run_test (self):
6089 addrs = []
6190 for i in range (0 ,test_addr_count ):
6291 addr = self .nodes [0 ].getnewaddress ()
63- # vaddr= self.nodes[0].validateaddress (addr) # required to get hd keypath
64- addrs .append (addr )
92+ vaddr = self .nodes [0 ].getaddressinfo (addr ) # required to get hd keypath
93+ addrs .append (vaddr )
6594 # Should be a no-op:
6695 self .nodes [0 ].keypoolrefill ()
6796
0 commit comments