URI: 
       tMerge pull request #1266 from kyuupichan/fast_freezing - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 6cb5ba43145a84beb1f4e52198482c8fd4a48f4a
   DIR parent d6f4b57d64566484e7edf0a40c5e555875462178
  HTML Author: ThomasV <electrumdev@gmail.com>
       Date:   Sun, 31 May 2015 06:44:17 +0200
       
       Merge pull request #1266 from kyuupichan/fast_freezing
       
       Speed up freezing and unfreezing of many addresses
       Diffstat:
         M gui/gtk.py                          |       7 ++-----
         M gui/qt/main_window.py               |      13 ++++---------
         M lib/commands.py                     |       4 ++--
         M lib/wallet.py                       |      25 ++++++++++---------------
       
       4 files changed, 18 insertions(+), 31 deletions(-)
       ---
   DIR diff --git a/gui/gtk.py b/gui/gtk.py
       t@@ -1079,10 +1079,7 @@ class ElectrumWindow:
                        path, col = treeview.get_cursor()
                        if path:
                            address = liststore.get_value( liststore.get_iter(path), 0)
       -                    if address in wallet.frozen_addresses:
       -                        wallet.unfreeze(address)
       -                    else:
       -                        wallet.freeze(address)
       +                    wallet.set_frozen_state([address], not wallet.is_frozen(address))
                            self.update_receiving_tab()
                    button.connect("clicked", freeze_address, treeview, liststore, self.wallet)
                    button.show()
       t@@ -1151,7 +1148,7 @@ class ElectrumWindow:
                    if address in self.wallet.imported_keys.keys():
                        Type = "I"
                    c, u, x = self.wallet.get_addr_balance(address)
       -            if address in self.wallet.frozen_addresses: Type = Type + "F"
       +            if self.wallet.is_frozen(address): Type = Type + "F"
                    label = self.wallet.labels.get(address)
                    h = self.wallet.history.get(address,[])
                    n = len(h)
   DIR diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py
       t@@ -1291,13 +1291,8 @@ class ElectrumWindow(QMainWindow):
                run_hook('do_clear')
        
        
       -    def set_addrs_frozen(self,addrs,freeze):
       -        for addr in addrs:
       -            if not addr: continue
       -            if addr in self.wallet.frozen_addresses and not freeze:
       -                self.wallet.unfreeze(addr)
       -            elif addr not in self.wallet.frozen_addresses and freeze:
       -                self.wallet.freeze(addr)
       +    def set_frozen_state(self, addrs, freeze):
       +        self.wallet.set_frozen_state(addrs, freeze)
                self.update_address_tab()
                self.update_fee(False)
        
       t@@ -1416,9 +1411,9 @@ class ElectrumWindow(QMainWindow):
                        menu.addAction(_("View on block explorer"), lambda: webbrowser.open(addr_URL))
        
                if any(addr not in self.wallet.frozen_addresses for addr in addrs):
       -            menu.addAction(_("Freeze"), lambda: self.set_addrs_frozen(addrs, True))
       +            menu.addAction(_("Freeze"), lambda: self.set_frozen_state(addrs, True))
                if any(addr in self.wallet.frozen_addresses for addr in addrs):
       -            menu.addAction(_("Unfreeze"), lambda: self.set_addrs_frozen(addrs, False))
       +            menu.addAction(_("Unfreeze"), lambda: self.set_frozen_state(addrs, False))
        
                def can_send(addr):
                    return addr not in self.wallet.frozen_addresses and self.wallet.get_addr_balance(addr) != (0, 0)
   DIR diff --git a/lib/commands.py b/lib/commands.py
       t@@ -322,10 +322,10 @@ class Commands:
                return {'address':address, 'redeemScript':redeem_script}
        
            def freeze(self,addr):
       -        return self.wallet.freeze(addr)
       +        return self.wallet.set_frozen_state([addr], True)
        
            def unfreeze(self,addr):
       -        return self.wallet.unfreeze(addr)
       +        return self.wallet.set_frozen_state([addr], False)
        
            def getprivatekeys(self, addr):
                return self.wallet.get_private_key(addr, self.password)
   DIR diff --git a/lib/wallet.py b/lib/wallet.py
       t@@ -149,7 +149,7 @@ class Abstract_Wallet(object):
                self.use_encryption        = storage.get('use_encryption', False)
                self.seed                  = storage.get('seed', '')               # encrypted
                self.labels                = storage.get('labels', {})
       -        self.frozen_addresses      = storage.get('frozen_addresses',[])
       +        self.frozen_addresses      = set(storage.get('frozen_addresses',[]))
                self.stored_height         = storage.get('stored_height', 0)       # last known height (for offline mode)
        
                self.history               = storage.get('addr_history',{})        # address -> list(txid, height)
       t@@ -1016,21 +1016,16 @@ class Abstract_Wallet(object):
            def is_frozen(self, addr):
                return addr in self.frozen_addresses
        
       -    def freeze(self,addr):
       -        if self.is_mine(addr) and self.is_frozen(addr):
       -            self.frozen_addresses.append(addr)
       -            self.storage.put('frozen_addresses', self.frozen_addresses, True)
       -            return True
       -        else:
       -            return False
       -
       -    def unfreeze(self,addr):
       -        if self.is_mine(addr) and self.is_frozen(addr):
       -            self.frozen_addresses.remove(addr)
       -            self.storage.put('frozen_addresses', self.frozen_addresses, True)
       +    def set_frozen_state(self, addrs, freeze):
       +        '''Set frozen state of the addresses to FREEZE, True or False'''
       +        if all(self.is_mine(addr) for addr in addrs):
       +            if freeze:
       +                self.frozen_addresses |= set(addrs)
       +            else:
       +                self.frozen_addresses -= set(addrs)
       +            self.storage.put('frozen_addresses', list(self.frozen_addresses), True)
                    return True
       -        else:
       -            return False
       +        return False
        
            def set_verifier(self, verifier):
                self.verifier = verifier