fix #2326: backward-compatibility of wallet files

This commit is contained in:
ThomasV 2017-03-23 09:20:32 +01:00
parent aa090007e9
commit 85f2f667c3
1 changed files with 21 additions and 1 deletions

View File

@ -80,7 +80,27 @@ class WalletStorage(PrintError):
try:
self.data = json.loads(s)
except:
raise IOError("Cannot read wallet file '%s'" % self.path)
try:
d = ast.literal_eval(s)
labels = d.get('labels', {})
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 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:
self.print_error('Failed to convert label to json format', key)
continue
self.data[key] = value
# check here if I need to load a plugin
t = self.get('wallet_type')
l = plugin_loaders.get(t)