Skip to content

Commit 8d1128c

Browse files
author
neocogent
committed
label support in watchaddr, fix qrclip
1 parent 87d9822 commit 8d1128c

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

scripts/qrclip

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ proc.visible = False
2828

2929
# extract results
3030
for symbol in proc.results:
31-
clipboard.copy(symbol.data if argv[1] != 'strip' else symbol.data.split(':')[-1])
31+
clipboard.copy(symbol.data if 'strip' in argv else symbol.data.split(':')[-1])
3232

scripts/watchaddr

+22-12
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@
1313
#
1414
# watchaddr test_list test_wallet
1515
#
16+
# Text preceding or following will be added as a label
17+
# if separated by ':' or ' '.
18+
#
1619

1720
import sys, json
1821

19-
empty = "{\"accounts\": {\"/x\": {\"imported\": { } } },\"wallet_type\": \"imported\" }"
22+
empty = "{\"accounts\": {\"/x\": {\"imported\": { } } },\"labels\":{},\"wallet_type\": \"imported\" }"
23+
labelsep = ':'
2024

2125
if len(sys.argv) < 3:
2226
print "Usage: %s <address file> <wallet file>\n\nRead addresses from file and create/update wallet." % sys.argv[0]
@@ -25,26 +29,32 @@ if len(sys.argv) < 3:
2529
sys.exit(1)
2630

2731
if sys.argv[1] != "--":
28-
sys.stdin = open(sys.argv[1], 'r')
32+
sys.stdin = open(sys.argv[1], 'r')
2933

3034
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)
3337
except IOError:
34-
wallet = json.loads(empty)
38+
wallet = json.loads(empty)
3539

3640
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.")
3943

4044
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
4555

4656
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)
4858

4959

5060

0 commit comments

Comments
 (0)