def call_with_common_options_initialized(**params: Any) -> Callable: params["private_key"] = _open_keystore(params.pop("keystore_file"), params.pop("password")) # Don't print traceback on KeyboardInterrupt gevent.get_hub().NOT_ERROR += (KeyboardInterrupt, ) try: setup_logging(log_level=params.pop("log_level"), log_json=params.pop("log_json")) if not params["state_db"]: # only RC has `chain_id`, MS and PFS have `web3` object chain_id = str( params.get("chain_id") or params["web3"].net.version) contracts_version = CONTRACTS_VERSION.replace(".", "_") filename = f"{app_name}-{chain_id}-{contracts_version}.db" data_dir = click.get_app_dir(app_name) params["state_db"] = os.path.join(data_dir, filename) # Need to delete the `chain_id` key if params.get("chain_id") is not None: del params["chain_id"] return func(**params) finally: structlog.reset_defaults()
def call_with_common_options_initialized(**params: Any) -> Callable: params["private_key"] = _open_keystore( params.pop("keystore_file"), params.pop("password") ) try: setup_logging(params.pop("log_level")) return func(**params) finally: structlog.reset_defaults()
def main( keystore_file: str, password: str, state_db: str, log_level: str, ): """Console script for request_collector. Logging can be quickly set by specifying a global log level or in a detailed way by using a log configuration file. See https://docs.python.org/3.7/library/logging.config.html#logging-config-dictschema for a detailed description of the format. """ setup_logging(log_level) with open(keystore_file, 'r') as keystore: try: private_key = Account.decrypt( keyfile_json=json.load(keystore), password=password, ) except ValueError: log.critical( 'Could not decode keyfile with given password. Please try again.' ) sys.exit(1) log.info("Starting Raiden Monitoring Request Collector") database = SharedDatabase(state_db) RequestCollector( private_key=encode_hex(private_key), state_db=database, ).listen_forever() print('Exiting...') return 0
def decorator(func: Callable) -> Callable: for option in reversed([ click.option( '--keystore-file', required=True, type=click.Path(exists=True, dir_okay=False, readable=True), help='Path to a keystore file.', ), click.password_option( '--password', help='Password to unlock the keystore file.'), click.option( '--state-db', default=os.path.join(click.get_app_dir(app_name), 'state.db'), type=str, help= 'Path to SQLite3 db which stores the application state', ), click.option( '--log-level', default='INFO', type=click.Choice( ['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG']), help= 'Print log messages of this level and more important ones', callback=lambda ctx, param, value: setup_logging(str(value) ), expose_value=False, ), ]): func = option(func) @wraps(func) def call_with_opened_keystore(**params: Any) -> Callable: params['private_key'] = _open_keystore(params.pop('keystore_file'), params.pop('password')) return func(**params) return call_with_opened_keystore
def decorator(func: Callable) -> Callable: for option in reversed( [ click.option( "--keystore-file", required=True, type=click.Path(exists=True, dir_okay=False, readable=True), help="Path to a keystore file.", ), click.password_option( "--password", confirmation_prompt=False, help="Password to unlock the keystore file.", ), click.option( "--state-db", default=os.path.join(click.get_app_dir(app_name), "state.db"), type=str, help="Path to SQLite3 db which stores the application state", ), click.option( "--log-level", default="INFO", type=click.Choice(["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"]), help="Print log messages of this level and more important ones", callback=lambda ctx, param, value: setup_logging(str(value)), expose_value=False, ), ] ): func = option(func) @wraps(func) def call_with_opened_keystore(**params: Any) -> Callable: params["private_key"] = _open_keystore( params.pop("keystore_file"), params.pop("password") ) return func(**params) return call_with_opened_keystore
def main( keystore_file: str, password: str, eth_rpc: str, registry_address: Address, monitor_contract_address: Address, user_deposit_contract_address: Address, start_block: int, confirmations: int, log_level: str, state_db: str, min_reward: int, ) -> None: setup_logging(log_level) with open(keystore_file, 'r') as keystore: try: private_key = Account.decrypt( keyfile_json=json.load(keystore), password=password, ) except ValueError as error: log.critical( 'Could not decode keyfile with given password. Please try again.', reason=str(error), ) sys.exit(1) provider = HTTPProvider(eth_rpc) web3 = Web3(provider) contract_manager = ContractManager(contracts_precompiled_path()) contract_infos = get_contract_addresses_and_start_block( chain_id=int(web3.net.version), contracts_version=None, token_network_registry_address=registry_address, monitor_contract_address=monitor_contract_address, user_deposit_contract_address=user_deposit_contract_address, start_block=start_block, ) if contract_infos is None: log.critical( 'Could not find correct contracts to use. Please check your configuration' ) sys.exit(1) else: log.info( 'Contract information', registry_address=contract_infos[CONTRACT_TOKEN_NETWORK_REGISTRY], monitor_contract_address=contract_infos[ CONTRACT_MONITORING_SERVICE], user_deposit_contract_address=contract_infos[ CONTRACT_USER_DEPOSIT], sync_start_block=contract_infos[START_BLOCK_ID], ) ms = MonitoringService( web3=web3, contract_manager=contract_manager, private_key=private_key, registry_address=contract_infos[CONTRACT_TOKEN_NETWORK_REGISTRY], monitor_contract_address=contract_infos[CONTRACT_MONITORING_SERVICE], user_deposit_contract_address=contract_infos[CONTRACT_USER_DEPOSIT], sync_start_block=contract_infos[START_BLOCK_ID], required_confirmations=confirmations, db_filename=state_db, min_reward=min_reward, ) ms.start()
def main( keystore_file: str, password: str, eth_rpc: str, registry_address: Address, user_deposit_contract_address: Address, start_block: int, confirmations: int, host: str, log_level: str, state_db: str, service_fee: int, ): """Console script for pathfinding_service. Logging can be quickly set by specifying a global log level or in a detailed way by using a log configuration file. See https://docs.python.org/3.7/library/logging.config.html#logging-config-dictschema for a detailed description of the format. """ setup_logging(log_level) log.info("Starting Raiden Pathfinding Service") contracts_version = '0.10.1' log.info(f'Using contracts version: {contracts_version}') with open(keystore_file, 'r') as keystore: try: private_key = Account.decrypt( keyfile_json=json.load(keystore), password=password, ).hex() except ValueError as error: log.critical( 'Could not decode keyfile with given password. Please try again.', reason=str(error), ) sys.exit(1) try: log.info(f'Starting Web3 client for node at {eth_rpc}') provider = HTTPProvider(eth_rpc) web3 = Web3(provider) net_version = int( web3.net.version ) # Will throw ConnectionError on bad Ethereum client except ConnectionError: log.error( 'Can not connect to the Ethereum client. Please check that it is running and that ' 'your settings are correct.', ) sys.exit(1) # Add POA middleware for geth POA chains, no/op for other chains web3.middleware_stack.inject(geth_poa_middleware, layer=0) # give web3 some time between retries before failing provider.middlewares.replace( 'http_retry_request', http_retry_with_backoff_middleware, ) contract_infos = get_contract_addresses_and_start_block( chain_id=net_version, contracts_version=contracts_version, token_network_registry_address=registry_address, # necessary so that the overwrite logic works properly monitor_contract_address='0x' + '1' * 40, user_deposit_contract_address=user_deposit_contract_address, start_block=start_block, ) if contract_infos is None: log.critical( 'Could not find correct contracts to use. Please check your configuration' ) sys.exit(1) else: log.info( 'Contract information', registry_address=contract_infos[CONTRACT_TOKEN_NETWORK_REGISTRY], user_deposit_contract_address=contract_infos[ CONTRACT_USER_DEPOSIT], sync_start_block=contract_infos[START_BLOCK_ID], ) service = None api = None try: log.info('Starting Pathfinding Service...') service = PathfindingService( web3=web3, contract_manager=contract_manager, registry_address=contract_infos[CONTRACT_TOKEN_NETWORK_REGISTRY], user_deposit_contract_address=contract_infos[ CONTRACT_USER_DEPOSIT], sync_start_block=contract_infos[START_BLOCK_ID], required_confirmations=confirmations, private_key=private_key, poll_interval=DEFAULT_POLL_INTERVALL, db_filename=state_db, service_fee=service_fee, ) api = ServiceApi(service) api.run(host=host) service.run() except (KeyboardInterrupt, SystemExit): print('Exiting...') finally: log.info('Stopping Pathfinding Service...') if api: api.stop() if service: service.stop() return 0