basic.py (1245B)
1 # standard imports 2 import logging 3 4 # external imports 5 from chainlib.interface import ChainInterface 6 from chainlib.eth.block import ( 7 block_latest, 8 block_by_number, 9 Block, 10 ) 11 from chainlib.eth.tx import ( 12 receipt, 13 Tx, 14 ) 15 from chainlib.eth.connection import ( 16 EthHTTPConnection, 17 ) 18 from chainsyncer.driver.chain_interface import ChainInterfaceDriver 19 from chainsyncer.store.mem import SyncMemStore 20 from chainsyncer.filter import SyncFilter 21 22 logging.basicConfig(level=logging.INFO) 23 logg = logging.getLogger() 24 25 26 class EthChainInterface(ChainInterface): 27 28 def __init__(self): 29 self._block_latest = block_latest 30 self._block_by_number = block_by_number 31 self._block_from_src = Block.from_src 32 self._tx_receipt = receipt 33 self._src_normalize = Tx.src_normalize 34 35 36 class BasicFilter(SyncFilter): 37 38 def filter(self, conn, block, tx): 39 logg.info('tx {}'.format(tx)) 40 41 42 ifc = EthChainInterface() 43 store = SyncMemStore() 44 store.register(BasicFilter()) 45 conn = EthHTTPConnection(url='http://localhost:8545') 46 47 drv = ChainInterfaceDriver( 48 store, 49 ifc, 50 offset=0, 51 target=-1, 52 ) 53 drv.run(conn)