patch by Soultaker; fix old_to_new
authorThomasV <thomasv@gitorious>
Wed, 13 Jun 2012 19:12:16 +0000 (21:12 +0200)
committerThomasV <thomasv@gitorious>
Wed, 13 Jun 2012 19:12:16 +0000 (21:12 +0200)
lib/interface.py
lib/wallet.py

index 710f7d8..0e35f62 100644 (file)
@@ -26,13 +26,23 @@ DEFAULT_TIMEOUT = 5
 DEFAULT_SERVERS = [ 'ecdsa.org:50001:t', 'electrum.novit.ro:50001:t', 'electrum.bitcoins.sk:50001:t']  # list of default servers
 
 
-def old_to_new(s):
-    s = s.replace("'blk_hash'", "'block_hash'")
-    s = s.replace("'pos'", "'index'")
-    s = s.replace("'nTime'", "'timestamp'")
-    s = s.replace("'is_in'", "'is_input'")
-    s = s.replace("'raw_scriptPubKey'","'raw_output_script'")
-    return s
+def replace_keys(obj, old_key, new_key):
+    if isinstance(obj, dict):
+        if old_key in obj:
+            obj[new_key] = obj[old_key]
+            del obj[old_key]
+        for elem in obj.itervalues():
+            replace_keys(elem, old_key, new_key)
+    elif isinstance(obj, list):
+        for elem in obj:
+            replace_keys(elem, old_key, new_key)
+
+def old_to_new(d):
+    replace_keys(d, 'blk_hash', 'block_hash')
+    replace_keys(d, 'pos', 'index')
+    replace_keys(d, 'nTime', 'timestamp')
+    replace_keys(d, 'is_in', 'is_input')
+    replace_keys(d, 'raw_scriptPubKey', 'raw_output_script')
 
 
 class Interface(threading.Thread):
index 6b15ddc..5517fd5 100644 (file)
@@ -647,9 +647,9 @@ class Wallet:
             f.close()
         except:
             return
-        data = interface.old_to_new(data)
         try:
             d = ast.literal_eval( data )
+            interface.old_to_new(d)
             self.seed_version = d.get('seed_version')
             self.master_public_key = d.get('master_public_key').decode('hex')
             self.use_encryption = d.get('use_encryption')