2021-06-26 14:04:34 +02:00
|
|
|
# standard imports
|
|
|
|
import sys
|
|
|
|
import signal
|
|
|
|
import argparse
|
|
|
|
import confini
|
|
|
|
import logging
|
|
|
|
import os
|
2022-01-30 20:44:03 +01:00
|
|
|
import importlib
|
2022-03-30 10:11:46 +02:00
|
|
|
import uuid
|
2022-03-31 19:32:25 +02:00
|
|
|
import datetime
|
2021-06-26 14:04:34 +02:00
|
|
|
|
|
|
|
# external imports
|
2022-05-10 13:07:25 +02:00
|
|
|
import chainlib.cli
|
|
|
|
import chainsyncer.cli
|
2021-06-26 14:04:34 +02:00
|
|
|
from chainlib.chain import ChainSpec
|
|
|
|
from chainlib.eth.connection import EthHTTPConnection
|
|
|
|
from chainlib.eth.block import block_latest
|
|
|
|
from hexathon import (
|
|
|
|
strip_0x,
|
|
|
|
add_0x,
|
|
|
|
)
|
2022-04-20 19:42:11 +02:00
|
|
|
#from chainsyncer.store.fs import SyncFsStore
|
2022-03-30 10:11:46 +02:00
|
|
|
from chainsyncer.driver.chain_interface import ChainInterfaceDriver
|
|
|
|
from chainsyncer.error import SyncDone
|
2022-05-13 09:11:54 +02:00
|
|
|
from chainsyncer.data import config_dir as chainsyncer_config_dir
|
|
|
|
from chainlib.settings import ChainSettings
|
|
|
|
from chainlib.eth.settings import process_settings
|
|
|
|
from chainlib.eth.cli.arg import (
|
|
|
|
Arg,
|
|
|
|
ArgFlag,
|
|
|
|
process_args,
|
|
|
|
)
|
|
|
|
from chainlib.eth.cli.config import (
|
|
|
|
Config,
|
|
|
|
process_config,
|
|
|
|
)
|
2022-03-30 10:11:46 +02:00
|
|
|
|
2021-06-26 14:04:34 +02:00
|
|
|
# local imports
|
2022-05-10 16:21:49 +02:00
|
|
|
from eth_monitor.callback import (
|
|
|
|
pre_callback,
|
|
|
|
post_callback,
|
|
|
|
)
|
2022-05-10 13:07:25 +02:00
|
|
|
import eth_monitor.cli
|
2022-05-13 09:11:54 +02:00
|
|
|
from eth_monitor.cli.log import process_log
|
|
|
|
from eth_monitor.settings import process_settings as process_settings_local
|
2021-06-26 14:04:34 +02:00
|
|
|
|
|
|
|
logg = logging.getLogger()
|
|
|
|
|
2022-05-10 13:07:25 +02:00
|
|
|
script_dir = os.path.realpath(os.path.dirname(__file__))
|
|
|
|
config_dir = os.path.join(script_dir, '..', 'data', 'config')
|
|
|
|
|
2022-05-13 09:11:54 +02:00
|
|
|
arg_flags = ArgFlag()
|
|
|
|
arg = Arg(arg_flags)
|
|
|
|
flags = arg_flags.STD_BASE_READ | arg_flags.PROVIDER | arg_flags.CHAIN_SPEC | arg_flags.VERYVERBOSE
|
2022-05-10 13:07:25 +02:00
|
|
|
|
2022-05-13 09:11:54 +02:00
|
|
|
argparser = chainlib.eth.cli.ArgumentParser()
|
2022-04-20 19:42:11 +02:00
|
|
|
argparser.add_argument('--list-backends', dest='list_backends', action='store_true', help='List built-in store backends')
|
2022-05-13 09:11:54 +02:00
|
|
|
argparser = process_args(argparser, arg, flags)
|
|
|
|
eth_monitor.cli.process_args(argparser, arg, flags)
|
2022-05-10 13:07:25 +02:00
|
|
|
|
|
|
|
sync_flags = chainsyncer.cli.SyncFlag.RANGE | chainsyncer.cli.SyncFlag.HEAD
|
|
|
|
chainsyncer.cli.process_flags(argparser, sync_flags)
|
|
|
|
|
2021-06-26 14:04:34 +02:00
|
|
|
args = argparser.parse_args(sys.argv[1:])
|
|
|
|
|
2022-04-20 19:42:11 +02:00
|
|
|
if args.list_backends:
|
|
|
|
for v in [
|
|
|
|
'fs',
|
|
|
|
'rocksdb',
|
2022-04-26 10:32:56 +02:00
|
|
|
'mem',
|
2022-04-20 19:42:11 +02:00
|
|
|
]:
|
|
|
|
print(v)
|
|
|
|
sys.exit(0)
|
|
|
|
|
2022-05-13 09:11:54 +02:00
|
|
|
logg = process_log(args, logg)
|
2021-06-26 14:04:34 +02:00
|
|
|
|
2022-05-10 13:07:25 +02:00
|
|
|
base_config_dir = [
|
|
|
|
chainsyncer.cli.config_dir,
|
|
|
|
config_dir,
|
|
|
|
]
|
2022-05-13 09:11:54 +02:00
|
|
|
config = Config()
|
|
|
|
config.add_schema_dir(config_dir)
|
|
|
|
config.add_schema_dir(chainsyncer_config_dir)
|
|
|
|
config = process_config(config, arg, args, flags)
|
2022-05-10 13:07:25 +02:00
|
|
|
config = chainsyncer.cli.process_config(config, args, sync_flags)
|
2022-05-13 09:11:54 +02:00
|
|
|
config = eth_monitor.cli.process_config(config, args, flags)
|
2021-06-26 14:04:34 +02:00
|
|
|
|
|
|
|
|
2022-05-13 09:11:54 +02:00
|
|
|
settings = ChainSettings()
|
|
|
|
settings = process_settings(settings, config)
|
|
|
|
settings = process_settings_local(settings, config)
|
2022-05-10 13:07:25 +02:00
|
|
|
logg.debug('loaded settings:\n{}'.format(settings))
|
2021-06-26 14:04:34 +02:00
|
|
|
|
2022-01-30 15:43:53 +01:00
|
|
|
|
2022-01-30 20:44:03 +01:00
|
|
|
def main():
|
2022-05-10 13:07:25 +02:00
|
|
|
logg.info('session is {}'.format(settings.get('SESSION_ID')))
|
|
|
|
|
2022-05-10 16:21:49 +02:00
|
|
|
drv = ChainInterfaceDriver(
|
|
|
|
settings.get('SYNC_STORE'),
|
|
|
|
settings.get('SYNCER_INTERFACE'),
|
|
|
|
offset=settings.get('SYNCER_OFFSET'),
|
|
|
|
target=settings.get('SYNCER_LIMIT'),
|
|
|
|
pre_callback=pre_callback,
|
|
|
|
post_callback=post_callback,
|
2022-05-10 20:28:35 +02:00
|
|
|
block_callback=settings.get('BLOCK_HANDLER').filter,
|
2022-05-10 16:21:49 +02:00
|
|
|
)
|
2022-02-27 15:21:09 +01:00
|
|
|
|
2022-03-30 10:11:46 +02:00
|
|
|
try:
|
2022-05-13 09:11:54 +02:00
|
|
|
r = drv.run(settings.get('CONN'))
|
2022-03-30 10:11:46 +02:00
|
|
|
except SyncDone as e:
|
|
|
|
sys.stderr.write("sync {} done at block {}\n".format(drv, e))
|
2021-06-26 14:04:34 +02:00
|
|
|
|
2022-01-30 20:44:03 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|