electrum

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

commit 83b9ecac76e8f570305003aaf4635a6364bc1336
parent f4b390a79f127d0bbe5c178bd849ec87b85f1a5a
Author: ThomasV <thomasv@gitorious>
Date:   Wed, 20 Aug 2014 12:47:53 +0200

save wallet file as json

Diffstat:
Mlib/wallet.py | 16+++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/lib/wallet.py b/lib/wallet.py @@ -24,6 +24,7 @@ import threading import random import time import math +import json from util import print_msg, print_error @@ -90,15 +91,16 @@ class WalletStorage(object): except IOError: return try: - d = ast.literal_eval( data ) #parse raw data from reading wallet file - except Exception: - raise IOError("Cannot read wallet file.") - + d = json.loads(data) + except: + try: + d = ast.literal_eval(data) #parse raw data from reading wallet file + except Exception: + raise IOError("Cannot read wallet file.") self.data = d self.file_exists = True def get(self, key, default=None): - with self.lock: v = self.data.get(key) if v is None: @@ -116,9 +118,9 @@ class WalletStorage(object): self.write() def write(self): - s = repr(self.data) + s = json.dumps(self.data, indent=4, sort_keys=True) f = open(self.path,"w") - f.write( s ) + f.write(s) f.close() if 'ANDROID_DATA' not in os.environ: import stat