URI: 
       tsimplify the create/restore procedure - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit d2c91d9a0f30370a1392d3e4c06b54b9ca981b1d
   DIR parent 9a9e7c1b7c5788b4f3eead413c9b2163df5280e5
  HTML Author: ThomasV <thomasv@gitorious>
       Date:   Tue, 20 Nov 2012 21:36:06 +0100
       
       simplify the create/restore procedure
       
       Diffstat:
         M electrum                            |      19 ++++++++++++-------
         M lib/gui.py                          |      33 ++++++++-----------------------
         M lib/gui_android.py                  |      11 ++++-------
         M lib/gui_qt.py                       |      30 +++++++++++-------------------
         M lib/wallet.py                       |      24 ++++++++++--------------
       
       5 files changed, 45 insertions(+), 72 deletions(-)
       ---
   DIR diff --git a/electrum b/electrum
       t@@ -209,6 +209,8 @@ if __name__ == '__main__':
                if not found:
                    a = gui.restore_or_create()
                    if not a: exit()
       +            # select a server.
       +            s = gui.network_dialog()
        
                    if a =='create':
                        wallet.new_seed(None)
       t@@ -217,12 +219,13 @@ if __name__ == '__main__':
                        # ask for seed and gap.
                        if not gui.seed_dialog(): exit()
                        wallet.init_mpk( wallet.seed )
       -            
       -            # select a server.
       -            s = gui.network_dialog()
       -            if s is None:
       -                gui.create_wallet()
        
       +            # generate the first addresses
       +            wallet.synchronize()
       +            # display seed
       +            gui.show_seed()
       +            gui.password_dialog()
       +            wallet.save()
        
                verifier = WalletVerifier(interface, config)
                wallet.set_verifier(verifier)
       t@@ -230,14 +233,16 @@ if __name__ == '__main__':
        
                if not found and a == 'restore' and s is not None:
                    try:
       -                ok = gui.restore_wallet()
       +                keep_it = gui.restore_wallet()
       +                wallet.fill_addressbook()
                    except:
                        import traceback
                        traceback.print_exc(file=sys.stdout)
                        exit()
        
       -            if not ok: exit()
       +            if not keep_it: exit()
        
       +        wallet.save()
                verifier.start()
                gui.main(url)
                wallet.save()
   DIR diff --git a/lib/gui.py b/lib/gui.py
       t@@ -1253,24 +1253,16 @@ class ElectrumGui():
                return restore_create_dialog(self.wallet)
        
            def seed_dialog(self):
       -        # ask for seed and gap.
                return run_recovery_dialog( self.wallet )
        
            def network_dialog(self):
                return run_network_dialog( self.wallet, parent=None )
        
       -    def create_wallet(self):
       -        wallet = self.wallet
       -        wallet.new_seed(None)
       -        # generate first key
       -        wallet.init_mpk( wallet.seed )
       -        wallet.synchronize()
       -        #wallet.up_to_date_event.clear()
       -        #wallet.update()
       -        # run a dialog indicating the seed, ask the user to remember it
       -        show_seed_dialog(wallet, None, None)
       -        #ask for password
       -        change_password_dialog(wallet, None, None)
       +    def show_seed(self):
       +        show_seed_dialog(self.wallet, None, None)
       +
       +    def password_dialog(self):
       +        change_password_dialog(self.wallet, None, None)
        
            def restore_wallet(self):
                wallet = self.wallet
       t@@ -1281,26 +1273,17 @@ class ElectrumGui():
                    buttons = gtk.BUTTONS_CANCEL, 
                    message_format = "Please wait..."  )
                dialog.show()
       -        wallet.save()
        
                def recover_thread( wallet, dialog ):
       -            wallet.init_mpk( wallet.seed ) # not encrypted at this point
       -            wallet.up_to_date_event.clear()
       -            wallet.update()
       -
       -            if wallet.is_found():
       -                # history and addressbook
       -                wallet.update_tx_history()
       -                wallet.fill_addressbook()
       -                print "Recovery successful"
       -
       +            while not wallet.is_up_to_date(): 
       +                time.sleep(0.1)
                    gobject.idle_add( dialog.destroy )
        
                thread.start_new_thread( recover_thread, ( wallet, dialog ) )
                r = dialog.run()
                dialog.destroy()
                if r==gtk.RESPONSE_CANCEL: return False
       -        if not wallet.is_found:
       +        if not wallet.is_found():
                    show_message("No transactions found for this seed")
        
                wallet.save()
   DIR diff --git a/lib/gui_android.py b/lib/gui_android.py
       t@@ -954,15 +954,13 @@ class ElectrumGui:
                pass
        
                
       -    def create_wallet(self):
       -
       -        # generate the first addresses
       -        wallet.synchronize()
       -        # run a dialog indicating the seed, ask the user to remember it
       +    def show_seed(self):
                modal_dialog('Your seed is:', wallet.seed)
                modal_dialog('Mnemonic code:', ' '.join(mnemonic_encode(wallet.seed)) )
       +
       +
       +    def password_dialog(self):
                change_password_dialog()
       -        wallet.save()
        
        
            def restore_wallet(self):
       t@@ -971,7 +969,6 @@ class ElectrumGui:
                droid.dialogCreateSpinnerProgress("Electrum", msg)
                droid.dialogShow()
        
       -
                wallet.up_to_date_event.clear()
                wallet.up_to_date = False
                wallet.interface.poke('synchronizer')
   DIR diff --git a/lib/gui_qt.py b/lib/gui_qt.py
       t@@ -295,7 +295,7 @@ class ElectrumWindow(QMainWindow):
                self.statusBar().showMessage(text)
                self.status_button.setIcon( icon )
        
       -        if self.wallet.up_to_date:
       +        if self.wallet.up_to_date or not self.wallet.interface.is_connected:
                    self.textbox.setText( self.wallet.banner )
                    self.update_history_tab()
                    self.update_receive_tab()
       t@@ -1552,15 +1552,13 @@ class ElectrumGui:
            def network_dialog(self):
                return ElectrumWindow.network_dialog( self.wallet, parent=None )
                
       -    def create_wallet(self):
       -        wallet = self.wallet
       -        # generate the first addresses
       -        wallet.synchronize()
       -        # run a dialog indicating the seed, ask the user to remember it
       -        ElectrumWindow.show_seed_dialog(wallet)
       -        # ask for password
       -        ElectrumWindow.change_password_dialog(wallet)
       -        wallet.save()
       +
       +    def show_seed(self):
       +        ElectrumWindow.show_seed_dialog(self.wallet)
       +
       +
       +    def password_dialog(self):
       +        ElectrumWindow.change_password_dialog(self.wallet)
        
        
            def restore_wallet(self):
       t@@ -1570,23 +1568,17 @@ class ElectrumGui:
                    waiting = lambda: False if wallet.interface.is_connected else "connecting...\n"
                    waiting_dialog(waiting)
        
       -        waiting = lambda: False if wallet.up_to_date else "Please wait...\nAddresses generated: %d\nKilobytes received: %.1f"\
       +        waiting = lambda: False if wallet.is_up_to_date() else "Please wait...\nAddresses generated: %d\nKilobytes received: %.1f"\
                    %(len(wallet.all_addresses()), wallet.interface.bytes_received/1024.)
        
       -        wallet.up_to_date_event.clear()
       -        wallet.up_to_date = False
       +        wallet.set_up_to_date(False)
                wallet.interface.poke('synchronizer')
                waiting_dialog(waiting)
                if wallet.is_found():
       -            # history and addressbook
       -            wallet.fill_addressbook()
       -            print "Recovery successful"
       -            wallet.save()
       +            print_error( "Recovery successful" )
                else:
                    QMessageBox.information(None, _('Error'), _("No transactions found for this seed"), _('OK'))
       -            return False
        
       -        wallet.save()
                return True
        
            def main(self,url):
   DIR diff --git a/lib/wallet.py b/lib/wallet.py
       t@@ -87,8 +87,7 @@ class Wallet:
                # there is a difference between wallet.up_to_date and interface.is_up_to_date()
                # interface.is_up_to_date() returns true when all requests have been answered and processed
                # wallet.up_to_date is true when the wallet is synchronized (stronger requirement)
       -        self.up_to_date_event = threading.Event()
       -        self.up_to_date_event.clear()
       +        
                self.up_to_date = False
                self.lock = threading.Lock()
                self.tx_event = threading.Event()
       t@@ -100,9 +99,11 @@ class Wallet:
                    self.update_tx_outputs(tx_hash)
        
        
       -    def init_up_to_date(self):
       -        self.up_to_date_event.clear()
       -        self.up_to_date = False
       +    def set_up_to_date(self,b):
       +        with self.lock: self.up_to_date = b
       +
       +    def is_up_to_date(self):
       +        with self.lock: return self.up_to_date
        
        
            def import_key(self, keypair, password):
       t@@ -920,10 +921,6 @@ class Wallet:
                return address, amount, label, message, signature, identity, url
        
        
       -    def update(self):
       -        self.interface.poke('synchronizer')
       -        self.up_to_date_event.wait(10000000000)
       -
        
            def freeze(self,addr):
                if addr in self.all_addresses() and addr not in self.frozen_addresses:
       t@@ -1086,7 +1083,7 @@ class WalletSynchronizer(threading.Thread):
                self.wallet = wallet
                self.interface = self.wallet.interface
                self.interface.register_channel('synchronizer')
       -        self.wallet.interface.register_callback('connected', self.wallet.init_up_to_date)
       +        self.wallet.interface.register_callback('connected', lambda: self.wallet.set_up_to_date(False))
                self.wallet.interface.register_callback('connected', lambda: self.interface.send([('server.banner',[])],'synchronizer') )
                self.was_updated = True
        
       t@@ -1098,14 +1095,13 @@ class WalletSynchronizer(threading.Thread):
                    return
                    
                if not self.interface.is_up_to_date('synchronizer'):
       -            if self.wallet.up_to_date:
       -                self.wallet.up_to_date = False
       +            if self.wallet.is_up_to_date():
       +                self.wallet.set_up_to_date(False)
                        self.was_updated = True
                    return
        
       -        self.wallet.up_to_date = True
       +        self.wallet.set_up_to_date(True)
                self.was_updated = True
       -        self.wallet.up_to_date_event.set()
        
            
            def subscribe_to_addresses(self, addresses):