WIP implement chaind-eth on chainlib 0.3.0 structure

This commit is contained in:
lash 2022-05-13 10:32:28 +00:00
parent 96f58c5f41
commit acbbebd8da
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
5 changed files with 89 additions and 35 deletions

View File

@ -4,3 +4,6 @@ runtime_dir =
id =
data_dir =
dispatch_delay = 0.01
[tx]
digest_size = 32

View File

@ -4,6 +4,7 @@ import logging
# external imports
import chainlib.cli
import chainlib.eth.cli
import chainsyncer.cli
import chaind.cli
from chaind.setup import Environment
@ -13,13 +14,32 @@ from hexathon import strip_0x
from chainsyncer.store.fs import SyncFsStore
from chainsyncer.driver.chain_interface import ChainInterfaceDriver
from chainsyncer.error import SyncDone
# local imports
from chaind.eth.settings import ChaindEthSettings
from chainlib.eth.cli.arg import (
Arg,
ArgFlag,
process_args,
)
from chainlib.eth.cli.config import (
Config,
process_config,
)
from chainsyncer.cli.arg import (
apply_arg as apply_arg_sync,
apply_flag as apply_flag_sync,
)
from chainsyncer.data import config_dir as chainsyncer_config_dir
from chaind.data import config_dir as chaind_config_dir
from chaind.cli.arg import (
apply_arg,
apply_flag,
)
from chainlib.eth.cli.log import process_log
from chaind.settings import ChaindSettings
# local imports
from chaind.eth.cache import EthCacheTx
from chaind.eth.settings import process_settings
logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger()
@ -29,33 +49,38 @@ config_dir = os.path.join(script_dir, '..', 'data', 'config')
env = Environment(domain='eth', env=os.environ)
arg_flags = chainlib.cli.argflag_std_base | chainlib.cli.Flag.CHAIN_SPEC
argparser = chainlib.cli.ArgumentParser(arg_flags)
arg_flags = ArgFlag()
arg_flags = apply_flag_sync(arg_flags)
arg_flags = apply_flag(arg_flags)
local_arg_flags = chaind.cli.argflag_local_base
chaind.cli.process_flags(argparser, local_arg_flags)
arg = Arg(arg_flags)
arg = apply_arg_sync(arg)
arg = apply_arg(arg)
sync_flags = chainsyncer.cli.SyncFlag.RANGE | chainsyncer.cli.SyncFlag.HEAD
chainsyncer.cli.process_flags(argparser, sync_flags)
flags = arg_flags.STD_BASE | arg_flags.CHAIN_SPEC | arg_flags.PROVIDER
flags = arg_flags.more(flags, arg_flags.SYNC_RANGE_EXT)
flags = arg_flags.more(flags, arg_flags.CHAIND_BASE)
argparser = chainlib.eth.cli.ArgumentParser()
argparser = process_args(argparser, arg, flags)
args = argparser.parse_args()
base_config_dir = [
chainsyncer.cli.config_dir,
chaind.cli.config_dir,
]
config = chainlib.cli.Config.from_args(args, arg_flags, base_config_dir=base_config_dir)
config = chainsyncer.cli.process_config(config, args, sync_flags)
config = chaind.cli.process_config(config, args, local_arg_flags)
logg = process_log(args, logg)
config = Config()
config.add_schema_dir(chainsyncer_config_dir)
config.add_schema_dir(chaind_config_dir)
config = process_config(config, arg, args, flags)
#config = process_config_local(config, arg, args, flags)
config.add('eth', 'CHAIND_ENGINE', False)
config.add('sync', 'CHAIND_COMPONENT', False)
logg.debug('config loaded:\n{}'.format(config))
settings = ChaindEthSettings(include_sync=True)
settings.process(config)
logg.debug('settings:\n{}'.format(settings))
settings = ChaindSettings()
settings = process_settings(settings, config)
logg.debug('settings loaded:\n{}'.format(settings))
sys.exit(0)
def main():
fltr = StateFilter(settings.get('CHAIN_SPEC'), settings.dir_for('queue'), EthCacheTx)

View File

@ -1,18 +1,44 @@
# external imports
from chainlib.eth.connection import EthHTTPConnection
from chaind.settings import ChaindSettings
from chainlib.settings import process_settings as base_process_settings
from chaind.eth.chain import EthChainInterface
from chaind.settings import *
class ChaindEthSettings(ChaindSettings):
def process_sync_interface(self, config):
self.o['SYNCER_INTERFACE'] = EthChainInterface()
def process_sync_interface(settings, config):
settings.set('SYNCER_INTERFACE', EthChainInterface())
return settings
def process_common(self, config):
super(ChaindEthSettings, self).process_common(config)
def process_common(settings, config):
rpc_provider = config.get('RPC_PROVIDER')
if rpc_provider == None:
rpc_provider = 'http://localhost:8545'
self.o['RPC'] = EthHTTPConnection(url=rpc_provider, chain_spec=self.o['CHAIN_SPEC'])
conn = EthHTTPConnection(url=rpc_provider, chain_spec=settings.get('CHAIN_SPEC'))
settings.set('RPC', conn)
return settings
def process_settings(settings, config):
settings = base_process_settings(settings, config)
settings = process_common(settings, config)
settings = process_sync_interface(settings, config)
if settings.include_queue:
settings = process_queue_backend(settings, config)
if settings.include_sync:
settings = process_sync_backend(settings, config)
settings = process_backend(settings, config)
settings = process_session(settings, config)
if settings.include_sync:
settings = process_sync(settings, config)
if settings.include_queue:
settings = process_chaind_queue(settings, config)
settings = process_dispatch(settings, config)
settings = process_token(settings, config)
settings = process_socket(settings, config)
return settings

View File

@ -1 +1 @@
eth-erc20~=0.3.1
eth-erc20~=0.3.2

View File

@ -1,5 +1,5 @@
chaind~=0.2.12
chaind~=0.2.13
hexathon~=0.1.7
chainlib-eth~=0.2.0
chainlib-eth~=0.3.0
pyxdg~=0.27
funga-eth~=0.6.1