workaround
[electrum-server.git] / backends / abe / __init__.py
index e5874b0..8a9c73b 100644 (file)
@@ -1,4 +1,4 @@
-from Abe.abe import hash_to_address, decode_check_address
+from Abe.util import hash_to_address, decode_check_address
 from Abe.DataStore import DataStore as Datastore_class
 from Abe import DataStore, readconf, BCDataStream,  deserialize, util, base58
 
@@ -53,6 +53,10 @@ class AbeStore(Datastore_class):
         inrows = self.get_tx_inputs(txid, False)
         for row in inrows:
             _hash = self.binout(row[6])
+            if not _hash:
+                print "WARNING: missing tx_in for tx", txid
+                continue
+
             address = hash_to_address(chr(0), _hash)
             if self.tx_cache.has_key(address):
                 print "cache: invalidating", address
@@ -62,6 +66,10 @@ class AbeStore(Datastore_class):
         outrows = self.get_tx_outputs(txid, False)
         for row in outrows:
             _hash = self.binout(row[6])
+            if not _hash:
+                print "WARNING: missing tx_out for tx", txid
+                continue
+
             address = hash_to_address(chr(0), _hash)
             if self.tx_cache.has_key(address):
                 print "cache: invalidating", address
@@ -72,11 +80,14 @@ class AbeStore(Datastore_class):
         try:
             if lock: self.dblock.acquire()
             ret = self.selectall(sql,params)
-            if lock: self.dblock.release()
-            return ret
         except:
             print "sql error", sql
-            return []
+            ret = []
+        finally:
+            if lock: self.dblock.release()
+
+        return ret
+            
 
     def get_tx_outputs(self, tx_id, lock=True):
         return self.safe_sql("""SELECT
@@ -370,6 +381,19 @@ class AbeStore(Datastore_class):
         return block_number
 
 
+    def catch_up(store):
+        # if there is an exception, do rollback and then re-raise the exception
+        for dircfg in store.datadirs:
+            try:
+                store.catch_up_dir(dircfg)
+            except Exception, e:
+                store.log.exception("Failed to catch up %s", dircfg)
+                store.rollback()
+                raise e
+
+
+
+
 from processor import Processor
 
 class BlockchainProcessor(Processor):
@@ -420,6 +444,7 @@ class BlockchainProcessor(Processor):
 
             if self.block_number != old_block_number:
                 old_block_number = self.block_number
+                print "block number:", self.block_number
                 self.push_response({ 'method':'blockchain.numblocks.subscribe', 'params':[self.block_number] })
 
             while True: