Factor out settings to cic-base

This commit is contained in:
lash 2022-04-24 15:03:21 +00:00
parent 266c1595d2
commit 09af7896c0
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 12 additions and 84 deletions

View File

@ -1,3 +1,4 @@
# external imports
from stateness.redis import RedisMonitor

View File

@ -5,10 +5,11 @@ import datetime
import importlib
# external imports
import cic_eth.cli
from chainsyncer.error import SyncDone
from chainsyncer.driver.chain_interface import ChainInterfaceDriver
# cic_eth legacy imports
import cic_eth.cli
# local imports
#from cic_tracker.cache import SyncTimeRedisCache
@ -46,7 +47,6 @@ args_override = {
config.add(args.until, '_UNTIL', True)
def main():
settings = CICTrackerSettings()
settings.process(config)

View File

@ -4,23 +4,13 @@ import importlib
import os
# external imports
from chainlib.chain import ChainSpec
from chainlib.eth.address import is_checksum_address
from chainlib.eth.block import block_latest
from cic_eth.registry import (
connect as connect_registry,
connect_declarator,
connect_token_registry,
)
from cic_eth.db import dsn_from_config
from cic_eth.db.models.base import SessionBase
from cic_eth_registry.error import UnknownContractError
import cic_eth.cli
from hexathon import (
to_int as hex_to_int,
strip_0x,
)
from cic_eth_registry import CICRegistry
from cic_base import CICSettings
from cic_sync_filter.callback import CallbackFilter
# local imports
from cic_tracker.chain import EthChainInterface
@ -32,69 +22,15 @@ from cic_tracker.callback import (
logg = logging.getLogger(__name__)
class CICTrackerSettings:
class CICTrackerSettings(CICSettings):
def __init__(self):
self.o = {}
self.registry = None
self.get = self.o.get
def process_common(self, config):
self.o['CHAIN_SPEC'] = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
rpc = cic_eth.cli.RPC.from_config(config)
self.o['RPC'] = rpc.get_default()
def process_celery(self, config):
cic_eth.cli.CeleryApp.from_config(config)
def process_database(self, config):
dsn = dsn_from_config(config)
SessionBase.connect(dsn, pool_size=16, debug=config.true('DATABASE_DEBUG'))
def process_trusted_addresses(self, config):
trusted_addresses_src = config.get('CIC_TRUST_ADDRESS')
if trusted_addresses_src == None:
raise InitializationError('At least one trusted address must be declared in CIC_TRUST_ADDRESS')
trusted_addresses = trusted_addresses_src.split(',')
for i, address in enumerate(trusted_addresses):
if not config.get('_UNSAFE'):
if not is_checksum_address(address):
raise ValueError('address {} at position {} is not a valid checksum address'.format(address, i))
else:
trusted_addresses[i] = to_checksum_address(address)
logg.info('using trusted address {}'.format(address))
self.o['TRUSTED_ADDRESSES'] = trusted_addresses
def process_registry(self, config):
registry = None
try:
registry = connect_registry(self.o['RPC'], self.o['CHAIN_SPEC'], config.get('CIC_REGISTRY_ADDRESS'))
except UnknownContractError as e:
pass
if registry == None:
raise InitializationError('Registry contract connection failed for {}: {}'.format(config.get('CIC_REGISTRY_ADDRESS'), e))
connect_declarator(self.o['RPC'], self.o['CHAIN_SPEC'], self.o['TRUSTED_ADDRESSES'])
connect_token_registry(self.o['RPC'], self.o['CHAIN_SPEC'])
self.o['CIC_REGISTRY'] = CICRegistry(self.o['CHAIN_SPEC'], self.o['RPC'])
def process_callback_filters(self, config):
def process_sync_callback_filters(self, config):
self.o['CALLBACK_FILTERS'] = []
for cb in config.get('TASKS_TRANSFER_CALLBACKS', '').split(','):
task_split = cb.split(':')
if len(task_split) > 1:
task_queue = task_split[0]
callback_filter = CallbackFilter(chain_spec, task_split[1], task_queue)
callback_filter = CallbackFilter(self.o['CHAIN_SPEC'], task_split[1], self.o['CELERY_QUEUE'])
self.o['CALLBACK_FILTERS'].append(callback_filter)
@ -169,22 +105,15 @@ class CICTrackerSettings:
self.o['SYNC_STORE'].register(m)
def process_sync(self, config):
def process(self, config):
super(CICTrackerSettings, self).process(config)
self.process_sync_range(config)
self.process_sync_interface(config)
self.process_sync_store(config)
self.process_sync_callback_filters(config)
self.process_sync_filters(config)
def process(self, config):
self.process_common(config)
self.process_celery(config)
self.process_database(config)
self.process_trusted_addresses(config)
self.process_registry(config)
self.process_sync(config)
def __str__(self):
ks = list(self.o.keys())
ks.sort()

View File

@ -1,6 +1,4 @@
chainsyncer[rocksdb]~=0.3.2
chainlib-eth~=0.1.0
celery~=4.4.7
cic-eth-registry~=0.6.9
chainqueue~=0.0.6rc9
cic-sync-filter~=0.13.0
cic-base[legacy]~=0.13.0