chaind-eth

Queue server for ethereum
Log | Files | Refs | README | LICENSE

commit ccabbc8ecc4c67d9fa7c0816d3daa633ce273766
parent dbf4108d6265116b90a0fcef2e6beb4f88c0bbcc
Author: nolash <dev@holbrook.no>
Date:   Thu,  3 Jun 2021 14:49:32 +0200

Factor out commons to chaind package

Diffstat:
Mchaind_eth/runnable/server.py | 33++++++++++++---------------------
Mrequirements.txt | 6+-----
2 files changed, 13 insertions(+), 26 deletions(-)

diff --git a/chaind_eth/runnable/server.py b/chaind_eth/runnable/server.py @@ -1,5 +1,4 @@ # standard imports -import syslog import sys import time import socket @@ -11,12 +10,8 @@ import argparse import uuid # external imports +from chaind import Environment import confini -from xdg.BaseDirectory import ( - xdg_data_dirs, - get_runtime_dir, - load_first_config, - ) from hexathon import strip_0x from chainlib.chain import ChainSpec from chainlib.eth.connection import EthHTTPConnection @@ -29,19 +24,15 @@ from chainqueue.adapters.eth import EthAdapter logging.basicConfig(level=logging.WARNING) logg = logging.getLogger() -default_config_dir = load_first_config('chainqueue') -config_dir = os.environ.get('CONFINI_DIR', default_config_dir) - -default_runtime_dir = os.path.join(get_runtime_dir(), 'chainqueue') -default_data_dir = os.path.join(xdg_data_dirs[0], 'chainqueue') +env = Environment(domain='eth', env=os.environ) argparser = argparse.ArgumentParser('chainqueue transaction submission and trigger server') -argparser.add_argument('-c', '--config', dest='c', type=str, default=config_dir, help='configuration directory') +argparser.add_argument('-c', '--config', dest='c', type=str, default=env.config_dir, help='configuration directory') argparser.add_argument('-p', type=str, help='rpc endpoint') argparser.add_argument('-i', type=str, help='chain spec') -argparser.add_argument('--runtime-dir', dest='runtime_dir', type=str, default=default_runtime_dir, help='runtime directory') -argparser.add_argument('--data-dir', dest='data_dir', type=str, default=default_data_dir, help='data directory') -argparser.add_argument('--session-id', dest='session_id', type=str, default=str(uuid.uuid4()), help='session id to use for session') +argparser.add_argument('--runtime-dir', dest='runtime_dir', type=str, default=env.runtime_dir, help='runtime directory') +argparser.add_argument('--data-dir', dest='data_dir', type=str, default=env.data_dir, help='data directory') +argparser.add_argument('--session-id', dest='session_id', type=str, default=env.session, help='session id to use for session') argparser.add_argument('-v', action='store_true', help='be verbose') argparser.add_argument('-vv', action='store_true', help='be very verbose') args = argparser.parse_args(sys.argv[1:]) @@ -58,7 +49,7 @@ args_override = { 'SESSION_RUNTIME_DIR': getattr(args, 'runtime_dir'), 'SESSION_CHAIN_SPEC': getattr(args, 'i'), 'RPC_ENDPOINT': getattr(args, 'p'), - 'PATH_DATA': getattr(args, 'data_dir'), + 'SESSION_DATA_DIR': getattr(args, 'data_dir'), } config.dict_override(args_override, 'cli args') config.add(getattr(args, 'session_id'), '_SESSION_ID', True) @@ -68,9 +59,9 @@ if not config.get('SESSION_SOCKET_PATH'): config.add(socket_path, 'SESSION_SOCKET_PATH', True) if config.get('DATABASE_ENGINE') == 'sqlite': - config.add(os.path.join(config.get('PATH_DATA'), config.get('DATABASE_NAME')), 'DATABASE_NAME', True) + config.add(os.path.join(config.get('SESSION_DATA_DIR'), config.get('DATABASE_NAME')), 'DATABASE_NAME', True) - +config.censor('PASSWORD', 'DATABASE') logg.debug('config loaded:\n{}'.format(config)) @@ -78,7 +69,7 @@ logg.debug('config loaded:\n{}'.format(config)) try: os.stat(config.get('DATABASE_NAME')) except FileNotFoundError: - sys.stderr.write('database file {} not found. please run database migration script first'.format(config.get('DATABASE_NAME'))) + sys.stderr.write('database file {} not found. please run database migration script first\n'.format(config.get('DATABASE_NAME'))) sys.exit(1) @@ -102,9 +93,9 @@ class SessionController: return self.dead = True if signo != None: - syslog.syslog('closing on {}'.format(signo)) + logg.info('closing on {}'.format(signo)) else: - syslog.syslog('explicit shutdown') + logg.info('explicit shutdown') sockname = self.srv.getsockname() self.srv.close() try: diff --git a/requirements.txt b/requirements.txt @@ -1,6 +1,2 @@ -chainlib>0.0.2,<=0.0.3 -chainqueue>0.0.1,<=.0.0.2 -chainsyncer>0.0.1,<=0.0.2 -confini>0.3.5,<=0.3.6 -pyxdg~=0.26 +chaind<=0.0.1,>=0.0.1a2 hexathon~=0.0.1a7