Convert old latin1 labels, Raise exception if json conversion fails.
A couple of changes 1) Old electrum wallets seemed to save labels in latin1, when you call json.dumps on line 83/84 it fails silently, which causes the label import to fail. Whenever electrum saves, it then overwrites your default wallet with no labels - essentially deleting all your labels. The solution to this is iterating over all the labels for old wallets decoding anything that fails to unicode() as latin1, and then unicoding it :) 2) Failing to import data and then deleting it is bad. So I'm raising an exception to avoid data being lost.
This commit is contained in:
parent
59a9e4f710
commit
fe5be618db
|
@ -72,12 +72,18 @@ class WalletStorage(object):
|
|||
except Exception as e:
|
||||
raise IOError("Cannot read wallet file '%s'" % self.path)
|
||||
self.data = {}
|
||||
# In old versions of Electrum labels were latin1 encoded, this fixes breakage.
|
||||
for i, label in d['labels'].items():
|
||||
try:
|
||||
unicode(label)
|
||||
except UnicodeDecodeError:
|
||||
d['labels'][i] = unicode(label.decode('latin1'))
|
||||
for key, value in d.items():
|
||||
try:
|
||||
json.dumps(key)
|
||||
json.dumps(value)
|
||||
except:
|
||||
continue
|
||||
raise Exception('Failed to convert wallet to 2.x format')
|
||||
self.data[key] = value
|
||||
self.file_exists = True
|
||||
|
||||
|
|
Loading…
Reference in New Issue