def _address_rxp(self, addr): """ Create a regex string for addresses, that matches several representations: - with(out) '0x' prefix - `pex` version This function takes care of maintaining additional lookup keys for substring matches. In case the given string is no address, it returns the original string. """ try: addr = to_checksum_address(addr) rxp = '(?:0x)?' + pex(address_checksum_and_decode(addr)) + f'(?:{addr.lower()[10:]})?' self._extra_keys[pex(address_checksum_and_decode(addr))] = addr.lower() self._extra_keys[addr[2:].lower()] = addr.lower() except ValueError: rxp = addr return rxp
def _address_rxp(self, addr): """ Create a regex string for addresses, that matches several representations: - with(out) '0x' prefix - `pex` version This function takes care of maintaining additional lookup keys for substring matches. In case the given string is no address, it returns the original string. """ try: addr = to_checksum_address(addr) rxp = '(?:0x)?' + pex(address_checksum_and_decode(addr)) + f'(?:{addr.lower()[10:]})?' self._extra_keys[pex(address_checksum_and_decode(addr))] = addr.lower() self._extra_keys[addr[2:].lower()] = addr.lower() except ValueError: rxp = addr return rxp
def convert(self, value, param, ctx): try: return address_checksum_and_decode(value) except InvalidAddress as e: self.fail(str(e))
def convert(self, value, param, ctx): try: return address_checksum_and_decode(value) except InvalidAddress as e: self.fail(str(e))
def convert(self, value, param, ctx): # pylint: disable=unused-argument try: return address_checksum_and_decode(value) except InvalidAddress as e: self.fail(str(e))
def run(ctx, **kwargs): # pylint: disable=too-many-locals,too-many-branches,too-many-statements if ctx.invoked_subcommand is not None: # Pass parsed args on to subcommands. ctx.obj = kwargs return print('Welcome to Raiden, version {}!'.format(get_system_spec()['raiden'])) from raiden.ui.console import Console from raiden.api.python import RaidenAPI if kwargs['config_file']: try: config_file = toml.load(kwargs['config_file']) optionname_to_default = { param.name: param.get_default(ctx) for param in run.params } addr_options = { param.name for param in run.params if param.type == ADDRESS_TYPE } for option_name, option_value in config_file.items(): option_name = option_name.replace('-', '_') if option_name in addr_options: option_value = address_checksum_and_decode(option_value) if (option_name not in kwargs or option_name not in optionname_to_default or kwargs[option_name] == optionname_to_default[option_name]): kwargs[option_name] = option_value except TypeError: print('Invalid config file') sys.exit(1) except toml.TomlDecodeError: print('Error occurs while decoding config file') sys.exit(1) configure_logging( kwargs['log_config'], log_json=kwargs['log_json'], log_file=kwargs['log_file'], ) # TODO: # - Ask for confirmation to quit if there are any locked transfers that did # not timeout. def _run_app(): # this catches exceptions raised when waiting for the stalecheck to complete try: app_ = ctx.invoke(app, **kwargs) except EthNodeCommunicationError: sys.exit(1) domain_list = [] if kwargs['rpccorsdomain']: if ',' in kwargs['rpccorsdomain']: for domain in kwargs['rpccorsdomain'].split(','): domain_list.append(str(domain)) else: domain_list.append(str(kwargs['rpccorsdomain'])) api_server = None if ctx.params['rpc']: raiden_api = RaidenAPI(app_.raiden) rest_api = RestAPI(raiden_api) api_server = APIServer( rest_api, cors_domain_list=domain_list, web_ui=ctx.params['web_ui'], eth_rpc_endpoint=ctx.params['eth_rpc_endpoint'], ) (api_host, api_port) = split_endpoint(kwargs['api_address']) try: api_server.start(api_host, api_port) except APIServerPortInUseError: print( 'ERROR: API Address %s:%s is in use. ' 'Use --api-address <host:port> to specify port to listen on.' % (api_host, api_port), ) sys.exit(1) print( 'The Raiden API RPC server is now running at http://{}:{}/.\n\n' 'See the Raiden documentation for all available endpoints at\n' 'http://raiden-network.readthedocs.io/en/stable/rest_api.html'. format( api_host, api_port, ), ) if ctx.params['console']: console = Console(app_) console.start() # wait for interrupt event = gevent.event.Event() gevent.signal(signal.SIGQUIT, event.set) gevent.signal(signal.SIGTERM, event.set) gevent.signal(signal.SIGINT, event.set) event.wait() print('Signal received. Shutting down ...') if api_server: api_server.stop() return app_ # TODO: # - Ask for confirmation to quit if there are any locked transfers that did # not timeout. if kwargs['transport'] == 'udp': (listen_host, listen_port) = split_endpoint(kwargs['listen_address']) try: with SocketFactory(listen_host, listen_port, strategy=kwargs['nat']) as mapped_socket: kwargs['mapped_socket'] = mapped_socket app_ = _run_app() except RaidenServicePortInUseError: print( 'ERROR: Address %s:%s is in use. ' 'Use --listen-address <host:port> to specify port to listen on.' % (listen_host, listen_port), ) sys.exit(1) elif kwargs['transport'] == 'matrix': print('WARNING: The Matrix transport is experimental') kwargs['mapped_socket'] = None app_ = _run_app() else: # Shouldn't happen raise RuntimeError(f"Invalid transport type '{kwargs['transport']}'") app_.stop(leave_channels=False)