import time, threading
-SQL_LIMIT=500
class AbeStore(Datastore_class):
Datastore_class.__init__(self,args)
+ self.sql_limit = int( config.get('database','limit') )
+
self.tx_cache = {}
self.bitcoind_url = 'http://%s:%s@%s:%s/' % ( config.get('bitcoind','user'), config.get('bitcoind','password'), config.get('bitcoind','host'), config.get('bitcoind','port'))
ret = self.selectall(sql,params)
except:
error = True
+ traceback.print_exc(file=sys.stdout)
finally:
if lock: self.dblock.release()
JOIN pubkey ON (pubkey.pubkey_id = prevout.pubkey_id)
WHERE pubkey.pubkey_hash = ?
AND cc.in_longest = 1
- LIMIT ? """, (dbhash,SQL_LIMIT))
+ LIMIT ? """, (dbhash,self.sql_limit))
- if len(out)==SQL_LIMIT:
+ if len(out)==self.sql_limit:
raise BaseException('limit reached')
return out
JOIN txout prevout ON (txin.txout_id = prevout.txout_id)
JOIN pubkey ON (pubkey.pubkey_id = prevout.pubkey_id)
WHERE pubkey.pubkey_hash = ?
- LIMIT ? """, (dbhash,SQL_LIMIT))
+ LIMIT ? """, (dbhash,self.sql_limit))
- if len(out)==SQL_LIMIT:
+ if len(out)==self.sql_limit:
raise BaseException('limit reached')
return out
JOIN pubkey ON (pubkey.pubkey_id = txout.pubkey_id)
WHERE pubkey.pubkey_hash = ?
AND cc.in_longest = 1
- LIMIT ? """, (dbhash,SQL_LIMIT))
+ LIMIT ? """, (dbhash,self.sql_limit))
- if len(out)==SQL_LIMIT:
+ if len(out)==self.sql_limit:
raise BaseException('limit reached')
return out
JOIN txout ON (txout.tx_id = tx.tx_id)
JOIN pubkey ON (pubkey.pubkey_id = txout.pubkey_id)
WHERE pubkey.pubkey_hash = ?
- LIMIT ? """, (dbhash,SQL_LIMIT))
+ LIMIT ? """, (dbhash,self.sql_limit))
- if len(out)==SQL_LIMIT:
+ if len(out)==self.sql_limit:
raise BaseException('limit reached')
return out
rows += self.get_address_out_rows_memorypool( dbhash )
address_has_mempool = False
- current_id = self.new_id("tx")
+ current_id = self.safe_sql("""SELECT last_value FROM tx_seq""")
+ current_id = current_id[0][0]
for row in rows:
is_in, tx_hash, tx_id, pos, value = row
else:
tx_id = store.import_tx(tx, False)
store.update_tx_cache(tx_id)
+ #print tx_hash
store.commit()
def main_iteration(store):
- try:
- store.dblock.acquire()
+ with store.dblock:
store.catch_up()
store.memorypool_update()
block_number = store.get_block_number(1)
+ return block_number
- except IOError:
- print "IOError: cannot reach bitcoind"
- block_number = 0
- except:
- traceback.print_exc(file=sys.stdout)
- block_number = 0
- finally:
- store.dblock.release()
- return block_number
def catch_up(store):
def run_store_iteration(self):
+
+ try:
+ block_number = self.store.main_iteration()
+ except:
+ traceback.print_exc(file=sys.stdout)
+ print "terminating"
+ self.shared.stop()
+
if self.shared.stopped():
print "exit timer"
return
-
- block_number = self.store.main_iteration()
+
if self.block_number != block_number:
self.block_number = block_number
print "block number:", self.block_number