chaintool-doc

Chaintool documentation
Log | Files | Refs | README | LICENSE

commit 82e02a06ec39bc2830f0043704789474ebcb3b76
Author: lash <dev@holbrook.no>
Date:   Sat, 13 Aug 2022 20:53:37 +0000

Basic syncer example

Diffstat:
Arequirements.txt | 2++
Asyncer/basic.py | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/requirements.txt b/requirements.txt @@ -0,0 +1,2 @@ +chainlib-eth==0.3.1 +shep==0.2.9 diff --git a/syncer/basic.py b/syncer/basic.py @@ -0,0 +1,53 @@ +# standard imports +import logging + +# external imports +from chainlib.interface import ChainInterface +from chainlib.eth.block import ( + block_latest, + block_by_number, + Block, + ) +from chainlib.eth.tx import ( + receipt, + Tx, + ) +from chainlib.eth.connection import ( + EthHTTPConnection, + ) +from chainsyncer.driver.chain_interface import ChainInterfaceDriver +from chainsyncer.store.mem import SyncMemStore +from chainsyncer.filter import SyncFilter + +logging.basicConfig(level=logging.INFO) +logg = logging.getLogger() + + +class EthChainInterface(ChainInterface): + + def __init__(self): + self._block_latest = block_latest + self._block_by_number = block_by_number + self._block_from_src = Block.from_src + self._tx_receipt = receipt + self._src_normalize = Tx.src_normalize + + +class BasicFilter(SyncFilter): + + def filter(self, conn, block, tx): + logg.info('tx {}'.format(tx)) + + +ifc = EthChainInterface() +store = SyncMemStore() +store.register(BasicFilter()) +conn = EthHTTPConnection(url='http://localhost:8545') + +drv = ChainInterfaceDriver( + store, + ifc, + offset=0, + target=-1, + ) +drv.run(conn)