electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit fe5be618db35eb8b2148865e2bdff350a062ff58
parent 59a9e4f7107b3c9ad0b1cf501135a115320d5918
Author: Azelphur <azelphur@azelphur.com>
Date:   Sun, 10 May 2015 20:28:42 +0100

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.
Diffstat:
Mlib/wallet.py | 8+++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/wallet.py b/lib/wallet.py @@ -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