more robust install wizard
authorThomasV <thomasv@gitorious>
Mon, 28 Apr 2014 15:30:48 +0000 (17:30 +0200)
committerThomasV <thomasv@gitorious>
Mon, 28 Apr 2014 15:30:48 +0000 (17:30 +0200)
gui/qt/__init__.py
gui/qt/installwizard.py
lib/wallet.py

index c3c7da7..b2bb524 100644 (file)
@@ -151,24 +151,20 @@ class ElectrumGui:
     def main(self, url):
 
         storage = WalletStorage(self.config)
-        if not storage.file_exists:
-            import installwizard
-            wizard = installwizard.InstallWizard(self.config, self.network, storage)
-            wallet = wizard.run()
-            if not wallet: 
-                exit()
+        if storage.file_exists:
+            wallet = Wallet(storage)
+            action = wallet.get_action()
+        else:
+            action = 'new'
 
-        elif storage.get('wallet_type') in ['2of3'] and storage.get('seed') is None:
+        if action is not None:
             import installwizard
             wizard = installwizard.InstallWizard(self.config, self.network, storage)
-            wallet = wizard.run(action= 'create2of3')
+            wallet = wizard.run(action)
             if not wallet: 
                 exit()
-
         else:
-            wallet = Wallet(storage)
             wallet.start_threads(self.network)
-            
 
         # init tray
         self.dark_icon = self.config.get("dark_icon", False)
index 314af07..2fe9b3a 100644 (file)
@@ -275,9 +275,9 @@ class InstallWizard(QDialog):
             return '2of3'
 
 
-    def run(self, action = None):
+    def run(self, action):
 
-        if action is None:
+        if action == 'new':
             action = self.restore_or_create()
 
         if action is None: 
@@ -289,32 +289,53 @@ class InstallWizard(QDialog):
                 return 
 
             if t == '2of3':
-                run_hook('create_cold_seed', self.storage, self)
+                action = 'create_cold'
+        
+
+        if action in ['create', 'create_cold', 'create_hot', 'create_remote']:
+            wallet = Wallet(self.storage)
+
+        if action == 'create':
+            seed = wallet.make_seed()
+            if not self.show_seed(seed, None):
+                return
+            if not self.verify_seed(seed, None):
                 return
+            password = self.password_dialog()
+            wallet.add_seed(seed, password)
+            wallet.create_accounts(password)
+            # generate first addresses offline
+            self.waiting_dialog(wallet.synchronize)
 
 
-        if action in ['create', 'create2of3']:
+        if action == 'create_cold':
+            run_hook('create_cold_seed', self.storage, self)
+            return
 
-            wallet = Wallet(self.storage)
+
+        if action == 'create_hot':
+            msg = _('You are about to create the hot seed of a multisig wallet')
+            if not self.question(msg):
+                return
             seed = wallet.make_seed()
-            sid = 'hot' if action == 'create2of3' else None
-            if not self.show_seed(seed, sid):
+            if not self.show_seed(seed, 'hot'):
                 return
-            if not self.verify_seed(seed, sid):
+            if not self.verify_seed(seed, 'hot'):
                 return
             password = self.password_dialog()
             wallet.add_seed(seed, password)
+            action = 'create_remote'
 
-            if action == 'create2of3':
-                run_hook('create_third_key', wallet, self)
-                if not wallet.master_public_keys.get("remote/"):
-                    return
 
-            wallet.create_accounts(password)
-            # generate first addresses offline
+        if action == 'create_remote':
+            run_hook('create_remote_key', wallet, self)
+            if not wallet.master_public_keys.get("remote/"):
+                return
+            wallet.create_account()
             self.waiting_dialog(wallet.synchronize)
 
-        elif action == 'restore':
+
+        if action == 'restore':
             t = self.choose_wallet_type()
             if not t: 
                 return
@@ -362,9 +383,6 @@ class InstallWizard(QDialog):
                 raise
 
 
-
-
-        else: raise
                 
         #if not self.config.get('server'):
         if self.network:
index 5aae676..bc94861 100644 (file)
@@ -237,6 +237,10 @@ class NewWallet:
                 for tx2 in self.transactions.values():
                     tx2.add_extra_addresses({h:tx})
 
+
+    def get_action(self):
+        pass
+
             
     def can_create_accounts(self):
         return not self.is_watching_only()
@@ -1482,7 +1486,7 @@ class Wallet_2of2(NewWallet):
     def can_create_accounts(self):
         return False
 
-    def make_account(self, account_id, password):
+    def create_account(self, account_id):
         """Creates and saves the master keys, but does not save the account"""
         xpub1 = self.master_public_keys.get("m/")
         xpub2 = self.master_public_keys.get("cold/")
@@ -1495,17 +1499,6 @@ class Wallet_2of2(NewWallet):
         return {'hot':xpub1, 'cold':xpub2}
 
 
-    def add_cold_seed(self, cold_seed, password):
-        seed_version, cold_seed = self.prepare_seed(cold_seed)
-        hex_seed = mnemonic_to_seed(cold_seed,'').encode('hex')
-        xpriv, xpub = bip32_root(hex_seed)
-
-        if password: 
-            cold_seed = pw_encode( cold_seed, password)
-        self.storage.put('cold_seed', cold_seed, True)
-
-        self.add_master_public_key('cold/', xpub)
-        self.add_master_private_key('cold/', xpriv, password)
 
 
 class Wallet_2of3(Wallet_2of2):
@@ -1514,7 +1507,7 @@ class Wallet_2of3(Wallet_2of2):
         NewWallet.__init__(self, storage)
         self.storage.put('wallet_type', '2of3', True)
 
-    def create_accounts(self, password):
+    def create_account(self):
         xpub1 = self.master_public_keys.get("m/")
         xpub2 = self.master_public_keys.get("cold/")
         xpub3 = self.master_public_keys.get("remote/")
@@ -1527,6 +1520,17 @@ class Wallet_2of3(Wallet_2of2):
         xpub3 = self.master_public_keys.get("remote/")
         return {'hot':xpub1, 'cold':xpub2, 'remote':xpub3}
 
+    def get_action(self):
+        xpub1 = self.master_public_keys.get("m/")
+        xpub2 = self.master_public_keys.get("cold/")
+        xpub3 = self.master_public_keys.get("remote/")
+        if xpub2 is None:
+            return 'create_cold'
+        if xpub1 is None:
+            return 'create_hot'
+        if xpub3 is None:
+            return 'create_remote'
+
 
 class WalletSynchronizer(threading.Thread):