def _run_setup(self, **kw): form = QuickSetupForm(endpoint=kw.get("endpoint")) 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(url_or_infura_id): ethereum_rpc_provider = Infura.make(network, url_or_infura_id) else: ethereum_rpc_provider = EthereumRPCProvider(url_or_infura_id) account = Account.create() 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 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 _run_setup(self, **kw): account_file = kw.get("account_file") account = Account(account_file, passphrase=get_passphrase()) form = QuickSetupForm( meta=dict(network=self.installer_settings.network), endpoint=kw.get("endpoint")) if form.validate(): self._send_status_update( "Generating new wallet and configuration file for raiden") network = Network.get_by_name(self.installer_settings.network) infura_url_or_id = form.data["endpoint"].strip() ethereum_rpc_provider = Infura.make(network, infura_url_or_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}")
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 _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 setUp(self): assert INFURA_PROJECT_ID self.account = Account.create(TESTING_KEYSTORE_FOLDER, "test_raiden_integration") self.network = Network.get_by_name(self.__class__.NETWORK_NAME) self.infura = Infura.make(self.network, INFURA_PROJECT_ID) self.w3 = make_web3_provider(self.infura.url, self.account)
def setUp(self): assert INFURA_PROJECT_ID Account.DEFAULT_KEYSTORE_FOLDER = Path(tempfile.gettempdir()) self.account = Account.create("test_raiden_integration") self.network = Network.get_by_name(self.__class__.NETWORK_NAME) self.infura = Infura.make(self.network, INFURA_PROJECT_ID) self.w3 = make_web3_provider(self.infura.url, self.account)
def test_make_infura_provider(self): project_id = "36b457de4c103495ada08dc0658db9c3" network = Network.get_by_name("mainnet") infura = Infura.make(network, project_id) self.assertEqual( infura.url, f"https://{network.name}.infura.io:443/v3/{project_id}") self.assertEqual(infura.project_id, project_id) self.assertEqual(infura.network.name, network.name)
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_action_configuration_setup(): account = prompt_account_selection() network = prompt_network_selection() ethereum_rpc_questions = [ { "name": "will_use_infura", "type": "confirm", "default": True, "message": Messages.input_use_infura, }, { "name": "infura_project_id", "type": "input", "message": Messages.input_ethereum_infura_project_id, "when": lambda answers: answers["will_use_infura"], "filter": lambda answer: answer.strip(), "validator": InfuraProjectIdValidator, }, { "name": "ethereum_rpc_endpoint", "type": "input", "message": Messages.input_ethereum_rpc_endpoint, "when": lambda answers: not answers["will_use_infura"], }, ] ethereum_rpc_answers = validate_prompt(ethereum_rpc_questions) if ethereum_rpc_answers["will_use_infura"]: project_id = ethereum_rpc_answers["infura_project_id"] client_rpc_endpoint = Infura.make(network, project_id).url else: client_rpc_endpoint = ethereum_rpc_answers["ethereum_rpc_endpoint"] user_deposit_contract_address = get_contract_address( network.chain_id, CONTRACT_USER_DEPOSIT) config = RaidenConfigurationFile( account=account, network=network, ethereum_client_rpc_endpoint=client_rpc_endpoint, user_deposit_contract_address=user_deposit_contract_address, ) config.save() return main_prompt()
def prompt_new_ethereum_rpc_endpoint(network=None): global ETHEREUM_RPC_ENDPOINTS if network is None: network = prompt_network_selection() ethereum_rpc_questions = [ { "name": "will_use_infura", "type": "confirm", "default": True, "message": Messages.input_use_infura, }, { "name": "infura_project_id", "type": "input", "message": Messages.input_ethereum_infura_project_id, "when": lambda answers: answers["will_use_infura"], "filter": lambda answer: answer.strip(), "validator": InfuraProjectIdValidator, }, { "name": "ethereum_rpc_endpoint", "type": "input", "message": Messages.input_ethereum_rpc_endpoint, "when": lambda answers: not answers["will_use_infura"], }, ] ethereum_rpc_answers = validate_prompt(ethereum_rpc_questions) if ethereum_rpc_answers["will_use_infura"]: project_id = ethereum_rpc_answers["infura_project_id"] client_rpc_endpoint = Infura.make(network, project_id) else: client_rpc_endpoint = EthereumRPCProvider( ethereum_rpc_answers["ethereum_rpc_endpoint"]) ETHEREUM_RPC_ENDPOINTS.append(client_rpc_endpoint) return client_rpc_endpoint
def test_cannot_create_infura_provider_with_invalid_network(self): with self.assertRaises(ValueError): Infura( "https://invalidnetwork.infura.io:443/v3/36b457de4c103495ada08dc0658db9c3" )
def test_cannot_create_infura_provider_with_invalid_project_id(self): with self.assertRaises(ValueError): Infura( "https://mainnet.infura.io:443/v3/7a347de4c103495a4a88dc0658db9b2" )
from raiden_installer.raiden import RaidenClient from raiden_installer.network import FundingError, Network from raiden_installer.token_exchange import Exchange from raiden_installer.tokens import Erc20Token, Wei, TokenAmount from raiden_installer.utils import get_contract_address ETHEREUM_RPC_ENDPOINTS = [] DEFAULT_INFURA_PROJECT_ID = os.getenv("RAIDEN_INSTALLER_INFURA_PROJECT_ID") DEFAULT_NETWORK = Network.get_default() RELEASE_MAP = RaidenClient.get_all_releases() if DEFAULT_INFURA_PROJECT_ID: ETHEREUM_RPC_ENDPOINTS.append( Infura.make(DEFAULT_NETWORK, DEFAULT_INFURA_PROJECT_ID)) class Messages: action_launch_raiden = "Launch raiden" action_account_create = "Create new ethereum account" action_account_list = "List existing ethereum accounts" action_account_fund = "Add funds to account" action_configuration_setup = "Create new raiden setup" action_configuration_list = "List existing raiden setups" action_release_manager = "Install/Uninstall raiden releases" action_release_list_installed = "List installed raiden releases" action_release_update_info = "Check for updates in raiden" action_swap_kyber = "Do ETH/RDN swap on Kyber DEX (mainnet/some testnets)" action_quit = "Quit this raiden launcher" action_test = "Run semi-automated test"
def infura(): assert INFURA_PROJECT_ID return Infura.make(NETWORK, INFURA_PROJECT_ID)
def _get_web3(self): assert INFURA_PROJECT_ID network = self._get_network() infura = Infura.make(network, INFURA_PROJECT_ID) return make_web3_provider(infura.url, self.account)
def infura(self, test_account, network_name): assert INFURA_PROJECT_ID network = Network.get_by_name(network_name) return Infura.make(network, INFURA_PROJECT_ID)
def validate(self): error_message = "A Infura Project ID is a sequence of 32 hex characters long" if not Infura.is_valid_project_id(self.text): raise ValidationError(error_message)