def validate_endpoint(self, field): data = field.data.strip() parsed_url = urlparse(data) is_valid_url = bool(parsed_url.scheme) and bool(parsed_url.netloc) if not (Infura.is_valid_project_id_or_endpoint(data) or is_valid_url): raise wtforms.ValidationError("Not a valid URL nor Infura Project ID")
def validate_endpoint(self, field): data = field.data.strip() if not Infura.is_valid_project_id_or_endpoint(data): raise wtforms.ValidationError( "Not a valid Infura URL nor Infura Project ID") if not (Infura.is_valid_project_id(data) or search(self.meta.network, data)): raise wtforms.ValidationError( f"Infura URL for wrong network, expected {self.meta.network}")
def test_infura_is_valid_project_id_or_endpoint(self): valid = [ "goerli.infura.io/v3/a7a347de4c103495a4a88dc0658db9b2", "36b457de4c103495ada08dc0658db9c3", "ropsten.infura.io/v3/8dc0658db9c34c103495a4a8b145e83a", "ropsten.infura.io/v4/8dc0658db9c34c103495a4a8b145e83a", ] invalid = [ "not-infura.net/a7a347de4c103495a4a88dc0658db9b2", "7a347de4c103495a4a88dc0658db9b2", "a7a347de4c103495a4a88dc0658db9b2444", "a7a347de4c103495a4a88gc044658db9b2", "goerli.infura.io/v3/a7a347de4c103495a4a88dc065gdb9b2", "goerli.infura.io/v3/a7a347de4c103495a4a88dc044658db9b2", "goerli.infura.io/v3/a7a34c103495a4a88dc044658db9b2", ] for project_id in valid: self.assertTrue(Infura.is_valid_project_id_or_endpoint(project_id)) for project_id in invalid: self.assertFalse( Infura.is_valid_project_id_or_endpoint(project_id))
def _run_setup(self, **kw): account_file = kw.get("account_file") account = Account(account_file) passphrase_path = RaidenConfigurationFile.FOLDER_PATH.joinpath( f"{account.address}.passphrase.txt") passphrase_file = PassphraseFile(passphrase_path) passphrase = passphrase_file.retrieve() account.passphrase = passphrase form = QuickSetupForm(endpoint=kw.get("endpoint"), network=kw.get("network")) if form.validate(): self._send_status_update( "Generating new wallet and configuration file for raiden") network = Network.get_by_name(form.data["network"]) url_or_infura_id = form.data["endpoint"].strip() if Infura.is_valid_project_id_or_endpoint(url_or_infura_id): ethereum_rpc_provider = Infura.make(network, url_or_infura_id) else: ethereum_rpc_provider = EthereumRPCProvider(url_or_infura_id) try: check_eth_node_responsivity(ethereum_rpc_provider.url) except ValueError as e: self._send_error_message(f"Ethereum node unavailable: {e}.") return conf_file = RaidenConfigurationFile( account, network, ethereum_rpc_provider.url, routing_mode="pfs" if form.data["use_rsb"] else "local", enable_monitoring=form.data["use_rsb"], ) conf_file.save() if network.FAUCET_AVAILABLE: self._run_funding(configuration_file=conf_file) self._send_redirect( self.reverse_url("launch", conf_file.file_name)) else: self._send_redirect( self.reverse_url("account", conf_file.file_name)) else: self._send_error_message( f"Failed to create account. Error: {form.errors}")
def _run_setup(self, **kw): account_file = kw.get("account_file") account = Account(account_file, passphrase=get_passphrase()) form = QuickSetupForm(endpoint=kw.get("endpoint"), network=kw.get("network")) if form.validate(): self._send_status_update( "Generating new wallet and configuration file for raiden") network = Network.get_by_name(form.data["network"]) url_or_infura_id = form.data["endpoint"].strip() if Infura.is_valid_project_id_or_endpoint(url_or_infura_id): ethereum_rpc_provider = Infura.make(network, url_or_infura_id) else: ethereum_rpc_provider = EthereumRPCProvider(url_or_infura_id) try: check_eth_node_responsivity(ethereum_rpc_provider.url) except ValueError as e: self._send_error_message(f"Ethereum node unavailable: {e}.") return conf_file = RaidenConfigurationFile( account.keystore_file_path, self.installer_settings, ethereum_rpc_provider.url, routing_mode=self.installer_settings.routing_mode, enable_monitoring=self.installer_settings.monitoring_enabled, ) conf_file.save() self._send_redirect( self.reverse_url("account", conf_file.file_name)) else: self._send_error_message( f"Failed to create account. Error: {form.errors}")