13
13
#
14
14
# watchaddr test_list test_wallet
15
15
#
16
+ # Text preceding or following will be added as a label
17
+ # if separated by ':' or ' '.
18
+ #
16
19
17
20
import sys , json
18
21
19
- empty = "{\" accounts\" : {\" /x\" : {\" imported\" : { } } },\" wallet_type\" : \" imported\" }"
22
+ empty = "{\" accounts\" : {\" /x\" : {\" imported\" : { } } },\" labels\" :{},\" wallet_type\" : \" imported\" }"
23
+ labelsep = ':'
20
24
21
25
if len (sys .argv ) < 3 :
22
26
print "Usage: %s <address file> <wallet file>\n \n Read addresses from file and create/update wallet." % sys .argv [0 ]
@@ -25,26 +29,32 @@ if len(sys.argv) < 3:
25
29
sys .exit (1 )
26
30
27
31
if sys .argv [1 ] != "--" :
28
- sys .stdin = open (sys .argv [1 ], 'r' )
32
+ sys .stdin = open (sys .argv [1 ], 'r' )
29
33
30
34
try :
31
- with open (sys .argv [2 ]) as json_file :
32
- wallet = json .load (json_file )
35
+ with open (sys .argv [2 ]) as json_file :
36
+ wallet = json .load (json_file )
33
37
except IOError :
34
- wallet = json .loads (empty )
38
+ wallet = json .loads (empty )
35
39
36
40
if wallet ["wallet_type" ] != "imported" :
37
- sys .stdin .read ()
38
- sys .exit ("Error: Not a watch-only wallet." )
41
+ sys .stdin .read ()
42
+ sys .exit ("Error: Not a watch-only wallet." )
39
43
40
44
for line in sys .stdin :
41
- line = line .replace (' ' , '' ).replace ('\n ' , '' )
42
- if line [0 ] == '1' or line [0 ] == '3' :
43
- wallet ["accounts" ]["/x" ]["imported" ][line ] = [None ,None ]
44
- print "Added:" , line
45
+ line = line .replace ('\n ' , '' )
46
+ if line [0 ] == '1' or line [0 ] == '3' :
47
+ addr ,_ ,label = line .partition (labelsep if (labelsep in line ) else ' ' )
48
+ else :
49
+ label ,_ ,addr = line .partition (labelsep if (labelsep in line ) else ' ' )
50
+ if addr :
51
+ wallet ["accounts" ]["/x" ]["imported" ][addr ] = [None ,None ]
52
+ if label :
53
+ wallet ["labels" ][addr ] = label
54
+ print "Added:" , addr , label
45
55
46
56
with open (sys .argv [2 ], 'w' ) as json_file :
47
- json .dump (wallet , json_file , indent = 4 )
57
+ json .dump (wallet , json_file , indent = 4 )
48
58
49
59
50
60
0 commit comments