callback.py (902B)
1 # standard imports 2 import logging 3 4 logg = logging.getLogger(__name__) 5 6 7 class BlockCallbackFilter: 8 9 def __init__(self): 10 self.filters = [] 11 12 13 def register(self, fltr): 14 self.filters.append(fltr) 15 16 17 def filter(self, conn, block): 18 for fltr in self.filters: 19 fltr.filter(conn, block) 20 21 22 def state_change_callback(k, old_state, new_state): 23 logg.log(logging.STATETRACE, 'state change: {} {} -> {}'.format(k, old_state, new_state)) 24 25 26 def filter_change_callback(k, old_state, new_state): 27 logg.log(logging.STATETRACE, 'filter change: {} {} -> {}'.format(k, old_state, new_state)) 28 29 30 def pre_callback(conn): 31 logg.debug('starting sync loop iteration') 32 33 34 def post_callback(conn): 35 logg.debug('ending sync loop iteration') 36 37 38 def block_callback(conn, block): 39 logg.info('processing {} {}'.format(block, datetime.datetime.fromtimestamp(block.timestamp)))