URI: 
       taddress_synchronizer fixes - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 597295e35931f001dce80cc30937911d6b2229b0
   DIR parent 801d3113ab44789c70a896b1865a133c0af3675f
  HTML Author: SomberNight <somber.night@protonmail.com>
       Date:   Thu, 19 Jul 2018 18:16:23 +0200
       
       address_synchronizer fixes
       
       is_mine: wallet expects get_address_index to work
       imported wallets: history did not include addr keys after creation
       deterministic wallets: get_addresses() should be sorted in derivation order
       
       Diffstat:
         M electrum/address_synchronizer.py    |       4 ++++
         M electrum/wallet.py                  |      37 +++++++++++++++++++++++--------
       
       2 files changed, 32 insertions(+), 9 deletions(-)
       ---
   DIR diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py
       t@@ -67,6 +67,10 @@ class AddressSynchronizer(PrintError):
                self.unverified_tx = defaultdict(int)
                # true when synchronized
                self.up_to_date = False
       +
       +        self.load_and_cleanup()
       +
       +    def load_and_cleanup(self):
                self.load_transactions()
                self.load_local_history()
                self.check_history()
   DIR diff --git a/electrum/wallet.py b/electrum/wallet.py
       t@@ -169,6 +169,7 @@ class Abstract_Wallet(AddressSynchronizer):
        
            def __init__(self, storage):
                AddressSynchronizer.__init__(self, storage)
       +
                self.electrum_version = ELECTRUM_VERSION
                # saved fields
                self.use_change            = storage.get('use_change', True)
       t@@ -178,10 +179,6 @@ class Abstract_Wallet(AddressSynchronizer):
                self.fiat_value            = storage.get('fiat_value', {})
                self.receive_requests      = storage.get('payment_requests', {})
        
       -        self.load_keystore()
       -        self.load_addresses()
       -        self.test_addresses_sanity()
       -
                # save wallet type the first time
                if self.storage.get('wallet_type') is None:
                    self.storage.put('wallet_type', self.wallet_type)
       t@@ -192,6 +189,12 @@ class Abstract_Wallet(AddressSynchronizer):
        
                self.coin_price_cache = {}
        
       +    def load_and_cleanup(self):
       +        self.load_keystore()
       +        self.load_addresses()
       +        self.test_addresses_sanity()
       +        super().load_and_cleanup()
       +
            def diagnostic_name(self):
                return self.basename()
        
       t@@ -268,6 +271,15 @@ class Abstract_Wallet(AddressSynchronizer):
                except:
                    return
        
       +    def is_mine(self, address):
       +        if not super().is_mine(address):
       +            return False
       +        try:
       +            self.get_address_index(address)
       +        except KeyError:
       +            return False
       +        return True
       +
            def is_change(self, address):
                if not self.is_mine(address):
                    return False
       t@@ -1218,9 +1230,9 @@ class Imported_Wallet(Simple_Wallet):
                if address in self.addresses:
                    return ''
                self.addresses[address] = {}
       -        self.storage.put('addresses', self.addresses)
       -        self.storage.write()
                self.add_address(address)
       +        self.save_addresses()
       +        self.save_transactions(write=True)
                return address
        
            def delete_address(self, address):
       t@@ -1268,7 +1280,7 @@ class Imported_Wallet(Simple_Wallet):
                    else:
                        self.keystore.delete_imported_key(pubkey)
                        self.save_keystore()
       -        self.storage.put('addresses', self.addresses)
       +        self.save_addresses()
        
                self.storage.write()
        
       t@@ -1296,9 +1308,9 @@ class Imported_Wallet(Simple_Wallet):
                    raise NotImplementedError(txin_type)
                self.addresses[addr] = {'type':txin_type, 'pubkey':pubkey, 'redeem_script':redeem_script}
                self.save_keystore()
       -        self.save_addresses()
       -        self.storage.write()
                self.add_address(addr)
       +        self.save_addresses()
       +        self.save_transactions(write=True)
                return addr
        
            def get_redeem_script(self, address):
       t@@ -1337,6 +1349,13 @@ class Deterministic_Wallet(Abstract_Wallet):
            def has_seed(self):
                return self.keystore.has_seed()
        
       +    def get_addresses(self):
       +        # overloaded so that addresses are ordered based on derivation
       +        out = []
       +        out += self.get_receiving_addresses()
       +        out += self.get_change_addresses()
       +        return out
       +
            def get_receiving_addresses(self):
                return self.receiving_addresses