def _run_funding(self, configuration_file: RaidenConfigurationFile): network = Network.get_by_name(settings.network) if not network.FAUCET_AVAILABLE: self._send_error_message( f"Can not run automatic funding for {network.capitalized_name}" ) return account = configuration_file.account w3 = make_web3_provider( configuration_file.ethereum_client_rpc_endpoint, account) self._send_status_update( f"Obtaining {network.capitalized_name} ETH through faucet") network.fund(account) balance = account.wait_for_ethereum_funds( w3=w3, expected_amount=EthereumAmount(0.01)) self._send_status_update(f"Account funded with {balance.formatted}") if settings.service_token.mintable: service_token = Erc20Token.find_by_ticker( settings.service_token.ticker) self._send_status_update(f"Minting {service_token.ticker}") mint_tokens(w3, account, service_token) if settings.transfer_token.mintable: transfer_token = Erc20Token.find_by_ticker( settings.transfer_token.ticker) self._send_status_update(f"Minting {transfer_token.ticker}") mint_tokens(w3, account, transfer_token)
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 _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 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 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 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 render(self, template_name, **context_data): network = Network.get_by_name(self.installer_settings.network) required = RequiredAmounts.from_settings(self.installer_settings) context_data.update({ "network": network, "ethereum_required": required.eth, "ethereum_required_after_swap": required.eth_after_swap, "service_token_required": required.service_token, "transfer_token_required": required.transfer_token, "eip20_abi": json.dumps(EIP20_ABI), }) return super().render(template_name, **context_data)
def __init__(self, account_filename: Union[Path, str], settings: Settings, ethereum_client_rpc_endpoint: str, **kw): self.account = Account(account_filename) self.account_filename = account_filename self.settings = settings self.network = Network.get_by_name(self.settings.network) self.ethereum_client_rpc_endpoint = ethereum_client_rpc_endpoint self.accept_disclaimer = kw.get("accept_disclaimer", True) self.enable_monitoring = kw.get("enable_monitoring", self.settings.monitoring_enabled) self.routing_mode = kw.get("routing_mode", self.settings.routing_mode) self.services_version = self.settings.services_version self._initial_funding_txhash = kw.get("_initial_funding_txhash")
def setUp(self): RaidenConfigurationFile.FOLDER_PATH = TESTING_TEMP_FOLDER.joinpath( "config") self.account = Account.create(TESTING_KEYSTORE_FOLDER, passphrase="test_raiden_config") self.network = Network.get_by_name("goerli") self.settings = load_settings("demo_env") self.configuration_file = RaidenConfigurationFile( self.account.keystore_file_path, self.settings, "http://localhost:8545", )
def render(self, template_name, **context_data): configuration_file = context_data.get('configuration_file') if configuration_file: network = configuration_file.network else: network = Network.get_by_name(default_settings.network) required = RequiredAmounts.for_network(network.name) context_data.update({ "network": network, "ethereum_required": required.eth, "service_token_required": required.service_token, "transfer_token_required": required.transfer_token, "eip20_abi": json.dumps(EIP20_ABI), }) return super().render(template_name, **context_data)
def setUp(self): temp_folder_path = Path(tempfile.gettempdir()) RaidenConfigurationFile.FOLDER_PATH = temp_folder_path self.account = Account.create(passphrase="test_raiden_config") self.network = Network.get_by_name("goerli") self.ethereum_client_rpc_endpoint = "http://localhost:8545" self.configuration_file = RaidenConfigurationFile( account=self.account, network=self.network, ethereum_client_rpc_endpoint=self.ethereum_client_rpc_endpoint, ) passphrase_file = PassphraseFile(self.configuration_file.passphrase_file_path) passphrase_file.store(self.account.passphrase)
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 load(cls, file_path: Path): file_name, _ = os.path.splitext(os.path.basename(file_path)) _, _, network_name = file_name.split("-") with file_path.open() as config_file: data = toml.load(config_file) passphrase = PassphraseFile(Path(data["password-file"])).retrieve() account = Account(data["keystore-file-path"], passphrase=passphrase) return cls( account=account, ethereum_client_rpc_endpoint=data["eth-rpc-endpoint"], network=Network.get_by_name(network_name), routing_mode=data["routing-mode"], enable_monitoring=data["enable-monitoring"], )
def load(cls, file_path: Path): file_name, _ = os.path.splitext(os.path.basename(file_path)) _, _, network_name = file_name.split("-") with file_path.open() as config_file: data = toml.load(config_file) keystore_file_path = Account.find_keystore_file_path( data["address"], Path(data["keystore-path"])) return cls( account_filename=keystore_file_path, ethereum_client_rpc_endpoint=data["eth-rpc-endpoint"], network=Network.get_by_name(network_name), routing_mode=data["routing-mode"], enable_monitoring=data["enable-monitoring"], _initial_funding_txhash=data.get("_initial_funding_txhash"), )
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)
Wei, ) from raiden_installer.transactions import ( deposit_service_tokens, get_token_balance, get_token_deposit, get_total_token_owned, mint_tokens, ) from raiden_installer.utils import check_eth_node_responsivity DEBUG = "RAIDEN_INSTALLER_DEBUG" in os.environ PORT = 8080 AVAILABLE_NETWORKS = [ Network.get_by_name(n) for n in ["mainnet", "ropsten", "goerli"] ] NETWORKS_WITH_TOKEN_SWAP = [ Network.get_by_name(n) for n in ["mainnet", "ropsten", "goerli"] ] DEFAULT_NETWORK = Network.get_default() RESOURCE_FOLDER_PATH = get_resource_folder_path() class QuickSetupForm(Form): network = wtforms.HiddenField("Network", default=DEFAULT_NETWORK.name) use_rsb = wtforms.HiddenField("Use Raiden Service Bundle", default=default_settings.monitoring_enabled) endpoint = wtforms.StringField("Infura Project ID/RPC Endpoint")
def test_get_network_by_name(self): for name, cid in CHAIN_ID_MAPPING.items(): network = Network.get_by_name(name) self.assertEqual(network.name, name) self.assertEqual(network.chain_id, cid)
get_token_deposit, get_total_token_owned, ) from raiden_installer.utils import ( check_eth_node_responsivity, recover_ld_library_env_path, wait_for_transaction, ) DEBUG = "RAIDEN_INSTALLER_DEBUG" in os.environ RESOURCE_FOLDER_PATH = get_resource_folder_path() EIP20_ABI = ContractManager( contracts_precompiled_path()).get_contract_abi("StandardToken") AVAILABLE_NETWORKS = [Network.get_by_name(n) for n in ["mainnet", "goerli"]] PASSPHRASE: Optional[str] = None def get_passphrase() -> Optional[str]: return PASSPHRASE def set_passphrase(passphrase: Optional[str]): global PASSPHRASE PASSPHRASE = passphrase def try_unlock(account): passphrase = get_passphrase()
def _get_network(self): return Network.get_by_name(settings.network)
from raiden_installer.constants import WEB3_TIMEOUT from raiden_installer.ethereum_rpc import Infura, make_web3_provider from raiden_installer.network import Network from raiden_installer.token_exchange import ExchangeError, Uniswap from raiden_installer.tokens import Erc20Token, EthereumAmount, TokenAmount from raiden_installer.transactions import approve, get_token_balance, mint_tokens from raiden_installer.uniswap.web3 import contracts as uniswap_contracts from raiden_installer.utils import send_raw_transaction, wait_for_transaction from tests.constants import TESTING_KEYSTORE_FOLDER from tests.fixtures import create_account, test_account, test_password from tests.utils import empty_account INFURA_PROJECT_ID = os.getenv("TEST_RAIDEN_INSTALLER_INFURA_PROJECT_ID") NETWORK = Network.get_by_name("goerli") WIZ_TOKEN = Erc20Token.find_by_ticker("WIZ", NETWORK.name) GAS_LIMIT = 120_000 pytestmark = pytest.mark.skipif(not INFURA_PROJECT_ID, reason="missing configuration for infura") def fund_account(account, w3): NETWORK.fund(account) account.wait_for_ethereum_funds(w3, EthereumAmount(0.01)) def generateDeadline(w3): current_timestamp = w3.eth.getBlock('latest')['timestamp'] return current_timestamp + WEB3_TIMEOUT
def test_cannot_run_funding_on_mainnet(self): network = Network.get_by_name("mainnet") with self.assertRaises(NotImplementedError): network.fund(self.account)
def network(self): network_name = urlparse(self.url).netloc.split(".")[0] return Network.get_by_name(network_name.lower())
) from raiden_installer.transactions import ( deposit_service_tokens, get_token_balance, get_total_token_owned, get_token_deposit, mint_tokens, ) from raiden_installer.utils import check_eth_node_responsivity DEBUG = "RAIDEN_INSTALLER_DEBUG" in os.environ PORT = 8080 AVAILABLE_NETWORKS = [Network.get_by_name(n) for n in ["mainnet", "ropsten", "goerli"]] NETWORKS_WITH_TOKEN_SWAP = [Network.get_by_name(n) for n in ["mainnet", "ropsten"]] DEFAULT_NETWORK = Network.get_default() RAIDEN_CLIENT = RaidenClient.get_client() RESOURCE_FOLDER_PATH = get_resource_folder_path() class QuickSetupForm(Form): network = wtforms.HiddenField("Network", default=DEFAULT_NETWORK.name) use_rsb = wtforms.HiddenField("Use Raiden Service Bundle", default=settings.monitoring_enabled) endpoint = wtforms.StringField("Infura Project ID/RPC Endpoint") def validate_network(self, field): network_name = field.data if network_name not in [n.name for n in AVAILABLE_NETWORKS]: