From e339cbbf708d8bf8fb61180b3665e1e7d58e2329 Mon Sep 17 00:00:00 2001 From: nolash Date: Wed, 30 Jun 2021 12:26:47 +0200 Subject: [PATCH] Move generic chain interface construction to cic-base --- .../cic_cache/runnable/daemons/tracker.py | 18 +-------- .../cic_eth/runnable/daemons/tracker.py | 18 +-------- apps/cic-eth/requirements.txt | 2 +- apps/data-seeding/cic_eth/import_balance.py | 39 +------------------ apps/data-seeding/eth/import_balance.py | 39 +------------------ apps/data-seeding/requirements.txt | 2 +- 6 files changed, 6 insertions(+), 112 deletions(-) diff --git a/apps/cic-cache/cic_cache/runnable/daemons/tracker.py b/apps/cic-cache/cic_cache/runnable/daemons/tracker.py index ce69b14b..ec03f6b7 100644 --- a/apps/cic-cache/cic_cache/runnable/daemons/tracker.py +++ b/apps/cic-cache/cic_cache/runnable/daemons/tracker.py @@ -16,6 +16,7 @@ import cic_base.config import cic_base.log import cic_base.argparse import cic_base.rpc +from cic_base.eth.syncer import chain_interface from cic_eth_registry import CICRegistry from cic_eth_registry.error import UnknownContractError from chainlib.chain import ChainSpec @@ -23,14 +24,7 @@ from chainlib.eth.constant import ZERO_ADDRESS from chainlib.connection import RPCConnection from chainlib.eth.block import ( block_latest, - block_by_number, - Block, ) -from chainlib.eth.tx import ( - receipt, - Tx, - ) -from chainlib.interface import ChainInterface from hexathon import ( strip_0x, ) @@ -88,16 +82,6 @@ def register_filter_tags(filters, session): session.rollback() logg.debug('already have tag name "{}" domain "{}"'.format(tag[0], tag[1])) -class EthChainInterface(ChainInterface): - - def __init__(self): - self._tx_receipt = receipt - self._block_by_number = block_by_number - self._block_from_src = Block.from_src - self._src_normalize = Tx.src_normalize - -chain_interface = EthChainInterface() - def main(): # Connect to blockchain with chainlib diff --git a/apps/cic-eth/cic_eth/runnable/daemons/tracker.py b/apps/cic-eth/cic_eth/runnable/daemons/tracker.py index c44cce0b..0a977825 100644 --- a/apps/cic-eth/cic_eth/runnable/daemons/tracker.py +++ b/apps/cic-eth/cic_eth/runnable/daemons/tracker.py @@ -15,20 +15,14 @@ import cic_base.config import cic_base.log import cic_base.argparse import cic_base.rpc +from cic_base.eth.syncer import chain_interface from cic_eth_registry.error import UnknownContractError from chainlib.chain import ChainSpec from chainlib.eth.constant import ZERO_ADDRESS from chainlib.connection import RPCConnection from chainlib.eth.block import ( block_latest, - block_by_number, - Block, ) -from chainlib.eth.tx import ( - receipt, - Tx, - ) -from chainlib.interface import ChainInterface from hexathon import ( strip_0x, ) @@ -85,16 +79,6 @@ chain_spec = ChainSpec.from_chain_str(config.get('CIC_CHAIN_SPEC')) cic_base.rpc.setup(chain_spec, config.get('ETH_PROVIDER')) -class EthChainInterface(ChainInterface): - - def __init__(self): - self._tx_receipt = receipt - self._block_by_number = block_by_number - self._block_from_src = Block.from_src - self._src_normalize = Tx.src_normalize - -chain_interface = EthChainInterface() - def main(): # connect to celery diff --git a/apps/cic-eth/requirements.txt b/apps/cic-eth/requirements.txt index 66e49c2a..45655432 100644 --- a/apps/cic-eth/requirements.txt +++ b/apps/cic-eth/requirements.txt @@ -1,4 +1,4 @@ -cic-base~=0.1.3a2 +cic-base~=0.1.3a3 celery==4.4.7 crypto-dev-signer~=0.4.14b6 confini~=0.3.6rc3 diff --git a/apps/data-seeding/cic_eth/import_balance.py b/apps/data-seeding/cic_eth/import_balance.py index cb0a48e6..99e8eef4 100644 --- a/apps/data-seeding/cic_eth/import_balance.py +++ b/apps/data-seeding/cic_eth/import_balance.py @@ -22,14 +22,7 @@ from chainsyncer.driver.head import HeadSyncer from chainlib.eth.connection import EthHTTPConnection from chainlib.eth.block import ( block_latest, - block_by_number, - Block, ) -from chainlib.eth.tx import ( - receipt, - Tx, - ) -from chainlib.interface import ChainInterface from chainlib.hash import keccak256_string_to_hex from chainlib.eth.address import to_checksum_address from chainlib.eth.gas import OverrideGasOracle @@ -43,6 +36,7 @@ from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer from crypto_dev_signer.keystore.dict import DictKeystore from cic_types.models.person import Person from eth_erc20 import ERC20 +from cic_base.eth.syncer import chain_interface logging.basicConfig(level=logging.WARNING) @@ -115,16 +109,6 @@ user_dir = args.user_dir # user_out_dir from import_users.py token_symbol = args.token_symbol -class EthChainInterface(ChainInterface): - - def __init__(self): - self._tx_receipt = receipt - self._block_by_number = block_by_number - self._block_from_src = Block.from_src - self._src_normalize = Tx.src_normalize - -chain_interface = EthChainInterface() - class Handler: @@ -201,27 +185,6 @@ class Handler: # logg.error('key record not found in imports: {}'.format(e).ljust(200)) -#class BlockGetter: -# -# def __init__(self, conn, gas_oracle, nonce_oracle, chain_spec): -# self.conn = conn -# self.tx_factory = ERC20(signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle, chain_id=chain_id) -# -# -# def get(self, n): -# o = block_by_number(n) -# r = self.conn.do(o) -# b = None -# try: -# b = Block(r) -# except TypeError as e: -# if r == None: -# logg.debug('block not found {}'.format(n)) -# else: -# logg.error('block retrieve error {}'.format(e)) -# return b - - def progress_callback(block_number, tx_index): sys.stdout.write(str(block_number).ljust(200) + "\n") diff --git a/apps/data-seeding/eth/import_balance.py b/apps/data-seeding/eth/import_balance.py index afabc16c..2d436a66 100644 --- a/apps/data-seeding/eth/import_balance.py +++ b/apps/data-seeding/eth/import_balance.py @@ -22,14 +22,7 @@ from chainsyncer.driver.head import HeadSyncer from chainlib.eth.connection import EthHTTPConnection from chainlib.eth.block import ( block_latest, - block_by_number, - Block, ) -from chainlib.eth.tx import ( - receipt, - Tx, - ) -from chainlib.interface import ChainInterface from chainlib.hash import keccak256_string_to_hex from chainlib.eth.address import to_checksum_address from chainlib.eth.gas import OverrideGasOracle @@ -42,6 +35,7 @@ from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer from crypto_dev_signer.keystore.dict import DictKeystore from cic_types.models.person import Person from eth_erc20 import ERC20 +from cic_base.eth.syncer import chain_interface logging.basicConfig(level=logging.WARNING) @@ -113,16 +107,6 @@ user_dir = args.user_dir # user_out_dir from import_users.py token_symbol = args.token_symbol -class EthChainInterface(ChainInterface): - - def __init__(self): - self._tx_receipt = receipt - self._block_by_number = block_by_number - self._block_from_src = Block.from_src - self._src_normalize = Tx.src_normalize - -chain_interface = EthChainInterface() - class Handler: @@ -199,27 +183,6 @@ class Handler: # logg.error('key record not found in imports: {}'.format(e).ljust(200)) -#class BlockGetter: -# -# def __init__(self, conn, gas_oracle, nonce_oracle, chain_spec): -# self.conn = conn -# self.tx_factory = ERC20(signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle, chain_id=chain_id) -# -# -# def get(self, n): -# o = block_by_number(n) -# r = self.conn.do(o) -# b = None -# try: -# b = Block(r) -# except TypeError as e: -# if r == None: -# logg.debug('block not found {}'.format(n)) -# else: -# logg.error('block retrieve error {}'.format(e)) -# return b - - def progress_callback(block_number, tx_index): sys.stdout.write(str(block_number).ljust(200) + "\n") diff --git a/apps/data-seeding/requirements.txt b/apps/data-seeding/requirements.txt index b09bb5d6..0ccea988 100644 --- a/apps/data-seeding/requirements.txt +++ b/apps/data-seeding/requirements.txt @@ -1,4 +1,4 @@ -cic-base[full_graph]==0.1.3a2 +cic-base[full_graph]==0.1.3a3 sarafu-faucet==0.0.4a1 cic-eth==0.11.1a1 cic-types==0.1.0a13