URI: 
       trequest missing transactions on startup - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit e0c03d6207c39b78a1e07e78133b1c1e3324442b
   DIR parent f1d4838012414f531268d3e66ef62f7aadd3d14a
  HTML Author: ThomasV <thomasv@gitorious>
       Date:   Sun,  4 Nov 2012 16:59:50 +0100
       
       request missing transactions on startup
       
       Diffstat:
         M lib/wallet.py                       |      32 ++++++++++++++++++++++---------
       
       1 file changed, 23 insertions(+), 9 deletions(-)
       ---
   DIR diff --git a/lib/wallet.py b/lib/wallet.py
       t@@ -924,6 +924,14 @@ class WalletSynchronizer(threading.Thread):
        
            def run(self):
                requested_tx = []
       +        missing_tx = []
       +
       +        # request any missing transactions
       +        for history in self.wallet.history.values():
       +            for tx_hash, tx_height in history:
       +                if self.wallet.transactions.get(tx_hash) is None and (tx_hash, tx_height) not in missing_tx:
       +                    missing_tx.append( (tx_hash, tx_height) )
       +        print_error("missing tx", missing_tx)
        
                # wait until we are connected, in case the user is not connected
                while not self.interface.is_connected:
       t@@ -939,6 +947,12 @@ class WalletSynchronizer(threading.Thread):
                    # 1. send new requests
                    self.synchronize_wallet()
        
       +            for tx_hash, tx_height in missing_tx:
       +                if (tx_hash, tx_height) not in requested_tx:
       +                    self.interface.send([ ('blockchain.transaction.get',[tx_hash, tx_height]) ], 'synchronizer')
       +                    requested_tx.append( (tx_hash, tx_height) )
       +            missing_tx = []
       +
                    if self.was_updated:
                        self.interface.trigger_callback('updated')
                        self.was_updated = False
       t@@ -967,20 +981,20 @@ class WalletSynchronizer(threading.Thread):
                        # request transactions that we don't have 
                        for tx_hash, tx_height in hist:
                            if self.wallet.transactions.get(tx_hash) is None:
       -                        if tx_hash not in requested_tx:
       -                            self.interface.send([ ('blockchain.transaction.get',[tx_hash, tx_height]) ], 'synchronizer')
       -                            requested_tx.append(tx_hash)
       +                        if (tx_hash, tx_height) not in requested_tx and (tx_hash, tx_height) not in wanted_tx:
       +                            missing_tx.append( (tx_hash, tx_height) )
                            else:
                                self.wallet.set_tx_timestamp(tx_hash, tx_height)
        
                    elif method == 'blockchain.transaction.get':
                        tx_hash = params[0]
                        tx_height = params[1]
       -                self.receive_tx(tx_hash, tx_height, result)
       +                d = self.deserialize_tx(tx_hash, tx_height, result)
       +                self.wallet.receive_tx_callback(tx_hash, d)
                        self.wallet.set_tx_timestamp(tx_hash, tx_height)
       -                requested_tx.remove(tx_hash)
                        self.was_updated = True
       -
       +                requested_tx.remove( (tx_hash, tx_height) )
       +                print_error("received tx:", d)
        
                    elif method == 'blockchain.transaction.broadcast':
                        self.wallet.tx_result = result
       t@@ -993,12 +1007,12 @@ class WalletSynchronizer(threading.Thread):
                    else:
                        print_error("Error: Unknown message:" + method + ", " + repr(params) + ", " + repr(result) )
        
       -            if self.was_updated:
       +            if self.was_updated and not requested_tx:
                        self.interface.trigger_callback('updated')
                        self.was_updated = False
        
        
       -    def receive_tx(self, tx_hash, tx_height, raw_tx):
       +    def deserialize_tx(self, tx_hash, tx_height, raw_tx):
        
                assert tx_hash == hash_encode(Hash(raw_tx.decode('hex')))
                import deserialize
       t@@ -1006,5 +1020,5 @@ class WalletSynchronizer(threading.Thread):
                vds.write(raw_tx.decode('hex'))
                d = deserialize.parse_Transaction(vds)
                d['tx_hash'] = tx_hash
       -        self.wallet.receive_tx_callback(tx_hash, d)
       +        return d