Processor.__init__(self)
self.shared = shared
+ self.config = config
self.up_to_date = False
self.watched_addresses = []
self.history_cache = {}
if sync or len(self.headers_data) > 40*100:
self.flush_headers()
+ with self.cache_lock:
+ chunk_index = header.get('block_height')/2016
+ if self.chunk_cache.get(chunk_index):
+ self.chunk_cache.pop(chunk_index)
+
def pop_header(self):
# we need to do this only if we have not flushed
if self.headers_data:
def get_chunk(self, i):
# store them on disk; store the current chunk in memory
- chunk = self.chunk_cache.get(i)
- if not chunk:
- chunk = self.read_chunk(i)
- self.chunk_cache[i] = chunk
+ with self.cache_lock:
+ chunk = self.chunk_cache.get(i)
+ if not chunk:
+ chunk = self.read_chunk(i)
+ self.chunk_cache[i] = chunk
+
return chunk
# re-add them to the history
self.add_to_history( prevout_addr, x.get('prevout_hash'), x.get('prevout_n'), prevout_height)
- print_log( "new hist for", hash_160_to_bc_address(prevout_addr), self.deserialize(self.batch_list[prevout_addr]) )
+ # print_log( "new hist for", hash_160_to_bc_address(prevout_addr), self.deserialize(self.batch_list[prevout_addr]) )
# write
max_len = 0
"read:%0.2f "%(t1 - t00),
"proc:%.2f "%(t2-t1),
"write:%.2f "%(t3-t2),
- "max:", max_len, max_addr)
+ "max:", max_len, hash_160_to_bc_address(max_addr))
- for addr in self.batch_list.keys(): self.invalidate_cache(addr)
+ for h160 in self.batch_list.keys():
+ addr = hash_160_to_bc_address(h160)
+ self.invalidate_cache(addr)
error = str(e) + ': ' + address
print_log( "error:", error )
- elif method == 'blockchain.address.subscribe2':
+ elif method == 'blockchain.address.unsubscribe':
try:
- address = params[0]
- result = self.get_status(address, cache_only)
- self.watch_address(address)
+ password = params[0]
+ address = params[1]
+ if password == self.config.get('server','password'):
+ self.watched_addresses.remove(address)
+ print_log('unsubscribed', address)
+ result = "ok"
+ else:
+ print_log('incorrect password')
+ result = "authentication error"
except BaseException, e:
error = str(e) + ': ' + address
print_log( "error:", error )
- elif method == 'blockchain.address.get_history2':
+ elif method == 'blockchain.address.get_history':
try:
address = params[0]
result = self.get_history( address, cache_only )
print_log( "error:", error)
elif method == 'blockchain.transaction.broadcast':
- txo = self.bitcoind('sendrawtransaction', params)
- print_log( "sent tx:", txo )
- result = txo
+ try:
+ txo = self.bitcoind('sendrawtransaction', params)
+ print_log( "sent tx:", txo )
+ result = txo
+ except BaseException, e:
+ result = str(e) # do not send an error
+ print_log( "error:", str(e), params )
elif method == 'blockchain.transaction.get_merkle':
if cache_only:
for x in tx.get('inputs'):
txi = (x.get('prevout_hash') + int_to_hex(x.get('prevout_n'), 4)).decode('hex')
try:
- addr = self.db.Get(txi)
+ h160 = self.db.Get(txi)
+ addr = hash_160_to_bc_address(h160)
except:
continue
l = self.mempool_addresses.get(tx_hash, [])
if addr in self.watched_addresses:
status = self.get_status( addr )
self.push_response({ 'id': None, 'method':'blockchain.address.subscribe', 'params':[addr, status] })
- self.push_response({ 'id': None, 'method':'blockchain.address.subscribe2', 'params':[addr, status] })
-
if not self.shared.stopped():
threading.Timer(10, self.main_iteration).start()