def test_can_get_by_filename(self): self.configuration_file.save() try: RaidenConfigurationFile.get_by_filename( self.configuration_file.file_name) except ValueError: self.fail("should load configuration by file name")
def _run_track_transaction(self, **kw): POLLING_INTERVAL = 10 configuration_file_name = kw.get("configuration_file_name") tx_hash = kw.get("tx_hash") time_elapsed = 0 try: configuration_file = RaidenConfigurationFile.get_by_filename( configuration_file_name) account = configuration_file.account w3 = make_web3_provider( configuration_file.ethereum_client_rpc_endpoint, account) self._send_status_update( f"Waiting for confirmation of transaction {tx_hash}") while not w3.eth.getTransactionReceipt(tx_hash): time.sleep(POLLING_INTERVAL) time_elapsed += POLLING_INTERVAL self._send_status_update( f"Not confirmed after {time_elapsed} seconds...") self._send_status_update("Transaction confirmed") self._send_redirect( self.reverse_url("funding", configuration_file_name)) except Exception as exc: self._send_error_message(str(exc))
def test_track_transaction(self, ws_client, config, settings): with patch("raiden_installer.web.wait_for_transaction" ) as mock_wait_for_transaction: tx_hash_bytes = os.urandom(32) tx_hash = encode_hex(tx_hash_bytes) data = { "method": "track_transaction", "configuration_file_name": config.file_name, "tx_hash": tx_hash } ws_client.write_message(json.dumps(data)) message = json.loads((yield ws_client.read_message())) assert message["type"] == "hash" assert message["tx_hash"] == tx_hash message = json.loads((yield ws_client.read_message())) assert message["type"] == "status-update" message = json.loads((yield ws_client.read_message())) assert message["type"] == "redirect" assert message["redirect_url"] == ( f"/swap/{config.file_name}/{settings.service_token.ticker}") mock_wait_for_transaction.assert_called_once() args, _ = mock_wait_for_transaction.call_args assert tx_hash_bytes in args loaded_config = RaidenConfigurationFile.get_by_filename( config.file_name) assert loaded_config._initial_funding_txhash == None
def _run_launch(self, **kw): configuration_file_name = kw.get("configuration_file_name") configuration_file = RaidenConfigurationFile.get_by_filename( configuration_file_name) account = configuration_file.account try_unlock(account) if account.passphrase is None: self._send_error_message( "Failed to unlock account! Please reload page") return raiden_client = RaidenClient.get_client(self.installer_settings) if not raiden_client.is_installed: self._send_status_update( f"Downloading and installing raiden {raiden_client.release}") raiden_client.install() self._send_status_update("Installation complete") self._send_status_update( "Launching Raiden, this might take a couple of minutes, do not close the browser" ) with temporary_passphrase_file(get_passphrase()) as passphrase_file: if not raiden_client.is_running: raiden_client.launch(configuration_file, passphrase_file) try: raiden_client.wait_for_web_ui_ready( status_callback=lambda stat: log.info(str(stat))) self._send_task_complete("Raiden is ready!") self._send_redirect(RaidenClient.WEB_UI_INDEX_URL) except (RaidenClientError, RuntimeError) as exc: self._send_error_message( f"Raiden process failed to start: {exc}") raiden_client.kill()
def get(self, configuration_file_name, token_ticker): configuration_file = RaidenConfigurationFile.get_by_filename( configuration_file_name) w3 = make_web3_provider( configuration_file.ethereum_client_rpc_endpoint, configuration_file.account) kyber = Kyber(w3=w3) uniswap = Uniswap(w3=w3) token = Erc20Token.find_by_ticker(token_ticker, configuration_file.network.name) network = configuration_file.network settings = network_settings[network.name] swap_amounts = SwapAmounts.from_settings(settings) if token_ticker == settings.service_token.ticker: swap_amount_1 = swap_amounts.service_token_1 swap_amount_2 = swap_amounts.service_token_2 swap_amount_3 = swap_amounts.service_token_3 elif token_ticker == settings.transfer_token.ticker: swap_amount_1 = swap_amounts.transfer_token_1 swap_amount_2 = swap_amounts.transfer_token_2 swap_amount_3 = swap_amounts.transfer_token_3 self.render( "swap.html", configuration_file=configuration_file, kyber=kyber, uniswap=uniswap, token=token, swap_amount_1=swap_amount_1, swap_amount_2=swap_amount_2, swap_amount_3=swap_amount_3, )
def get(self, configuration_file_name): # Returns the highest estimate of ETH needed to get required service token amount configuration_file = RaidenConfigurationFile.get_by_filename( configuration_file_name) account = configuration_file.account w3 = make_web3_provider( configuration_file.ethereum_client_rpc_endpoint, account) required = RequiredAmounts.for_network(configuration_file.network.name) kyber = Kyber(w3=w3) uniswap = Uniswap(w3=w3) highest_cost = 0 for exchange in (kyber, uniswap): exchange_costs = exchange.calculate_transaction_costs( required.service_token, account) if not exchange_costs: continue total_cost = exchange_costs["total"].as_wei highest_cost = max(highest_cost, total_cost) estimated_cost = EthereumAmount(Wei(highest_cost)) self.render_json({ "dex_swap_RDN": { "as_wei": estimated_cost.as_wei, "formatted": estimated_cost.formatted, } })
def post(self, configuration_file_name): configuration_file = RaidenConfigurationFile.get_by_filename( configuration_file_name) account = configuration_file.account try_unlock(account) w3 = make_web3_provider( configuration_file.ethereum_client_rpc_endpoint, account) ex_currency_amt = json_decode(self.request.body) exchange = Exchange.get_by_name(ex_currency_amt["exchange"])(w3=w3) currency = Erc20Token.find_by_ticker(ex_currency_amt["currency"], configuration_file.network) token_amount = TokenAmount(ex_currency_amt["target_amount"], currency) try: exchange_costs = exchange.calculate_transaction_costs( token_amount, account) total_cost = exchange_costs["total"] self.render_json({ "exchange": exchange.name, "currency": currency.ticker, "target_amount": ex_currency_amt["target_amount"], "as_wei": total_cost.as_wei, "formatted": total_cost.formatted, "utc_seconds": int(time.time()), }) except ExchangeError as ex: log.error("There was an error preparing the exchange", exc_info=ex) self.set_status( status_code=409, reason=str(ex), )
def get(self, configuration_file_name, token_ticker): configuration_file = RaidenConfigurationFile.get_by_filename( configuration_file_name) if get_passphrase() is None: self.render( "account_unlock.html", keystore_file_path=configuration_file.account. keystore_file_path, return_to=f"/swap/{configuration_file_name}/{token_ticker}", ) return w3 = make_web3_provider( configuration_file.ethereum_client_rpc_endpoint, configuration_file.account) kyber = Kyber(w3=w3) uniswap = Uniswap(w3=w3) token = Erc20Token.find_by_ticker(token_ticker, configuration_file.network.name) swap_amounts = SwapAmounts.from_settings(self.installer_settings) if token_ticker == self.installer_settings.service_token.ticker: swap_amount = swap_amounts.service_token elif token_ticker == self.installer_settings.transfer_token.ticker: swap_amount = swap_amounts.transfer_token self.render( "swap.html", configuration_file=configuration_file, kyber=kyber, uniswap=uniswap, token=token, swap_amount=swap_amount, )
def test_setup(self, ws_client, test_account, infura, network_name, patch_config_folder, settings): data = { "method": "setup", "endpoint": infura.url, "network": network_name, "account_file": str(test_account.keystore_file_path) } ws_client.write_message(json.dumps(data)) message = json.loads((yield ws_client.read_message())) assert message["type"] == "status-update" account_address = to_checksum_address(test_account.address) config_file_name = f"config-{account_address}-{settings.name}.toml" message = json.loads((yield ws_client.read_message())) assert message["type"] == "redirect" assert message["redirect_url"] == f"/account/{config_file_name}" config = RaidenConfigurationFile.get_by_filename(config_file_name) assert config.account.keystore_file_path == test_account.keystore_file_path assert config.settings == settings assert config.ethereum_client_rpc_endpoint == infura.url assert config.routing_mode == settings.routing_mode assert config.enable_monitoring == settings.monitoring_enabled config.path.unlink()
def get(self, configuration_file_name): configuration_file = RaidenConfigurationFile.get_by_filename( configuration_file_name) keystore_path = configuration_file.configuration_data["keystore-path"] filename = "" for file in glob(f"{keystore_path}/UTC--*"): file_path = Path(file) if file_path.is_file(): keystore_content = json.loads(file_path.read_text()) if (to_checksum_address(keystore_content["address"]) == configuration_file.account.address): filename = os.path.basename(file) break if PASSPHRASE is not None: self.render("account.html", configuration_file=configuration_file, keystore=filename) else: self.render( "account_unlock.html", keystore_file_path=configuration_file.account. keystore_file_path, return_to=f"/account/{configuration_file_name}", )
def test_setup_with_invalid_network(self, ws_client, test_account, infura, patch_config_folder, settings): data = { "method": "setup", "endpoint": infura.url, "network": "invalid network", "account_file": str(test_account.keystore_file_path) } ws_client.write_message(json.dumps(data)) message = json.loads((yield ws_client.read_message())) assert message["type"] == "error-message" with pytest.raises(ValueError): RaidenConfigurationFile.get_by_filename( f"config-{to_checksum_address(test_account.address)}-{settings.name}.toml" )
def get(self, configuration_file_name): configuration_file = RaidenConfigurationFile.get_by_filename(configuration_file_name) w3 = make_web3_provider( configuration_file.ethereum_client_rpc_endpoint, configuration_file.account ) current_balance = configuration_file.account.get_ethereum_balance(w3) self.render("launch.html", configuration_file=configuration_file, balance=current_balance)
def _run_launch(self, **kw): configuration_file_name = kw.get("configuration_file_name") configuration_file = RaidenConfigurationFile.get_by_filename( configuration_file_name) network_name = configuration_file.network.name raiden_client = RaidenClient.get_client(network_name) required = RequiredAmounts.for_network(network_name) if not raiden_client.is_installed: self._send_status_update( f"Downloading and installing raiden {raiden_client.release}") raiden_client.install() self._send_status_update("Installation complete") account = configuration_file.account w3 = make_web3_provider( configuration_file.ethereum_client_rpc_endpoint, account) service_token = Erc20Token.find_by_ticker( required.service_token.ticker, network_name) service_token_balance = get_token_balance(w3=w3, account=account, token=service_token) service_token_in_deposit = get_token_deposit(w3=w3, account=account, token=service_token) if service_token_balance.as_wei and service_token_in_deposit < required.service_token: self._send_status_update( f"Making deposit of {service_token_balance.formatted} for Raiden Services" ) deposit_service_tokens(w3=w3, account=account, token=service_token, amount=service_token_balance.as_wei) service_token_deposited = get_token_deposit(w3=w3, account=account, token=service_token) self._send_status_update( f"Amount deposited at UDC: {service_token_deposited.formatted}" ) self._send_status_update( "Launching Raiden, this might take a couple of minutes, do not close the browser" ) if not raiden_client.is_running: raiden_client.launch(configuration_file) try: raiden_client.wait_for_web_ui_ready( status_callback=lambda stat: log.info(str(stat))) self._send_task_complete("Raiden is ready!") self._send_redirect(raiden_client.WEB_UI_INDEX_URL) except (RaidenClientError, RuntimeError) as exc: self._send_error_message(f"Raiden process failed to start: {exc}") raiden_client.kill()
def post(self, configuration_file_name): configuration_file = RaidenConfigurationFile.get_by_filename(configuration_file_name) form = FundingOptionsForm(self.request.arguments) if form.validate(): next_view = {"no-action": "launch", "run-swap": "swap-options"}[ form.data["funding_option"] ] return self.redirect(self.reverse_url(next_view, configuration_file.file_name)) else: self.render("funding_select_method.html", configuration_file=configuration_file)
def get(self, configuration_file_name): configuration_file = RaidenConfigurationFile.get_by_filename( configuration_file_name) account = configuration_file.account try_unlock(account) web3 = make_web3_provider( configuration_file.ethereum_client_rpc_endpoint, account) self.render_json({ "gas_price": web3.eth.generateGasPrice(), "block_number": web3.eth.blockNumber, "utc_seconds": int(time.time()), })
def _run_launch(self, **kw): configuration_file_name = kw.get("configuration_file_name") configuration_file = RaidenConfigurationFile.get_by_filename( configuration_file_name) if not RAIDEN_CLIENT.is_installed: self._send_status_update( f"Downloading and installing raiden {RAIDEN_CLIENT.release}") RAIDEN_CLIENT.install() self._send_status_update("Installation complete") account = configuration_file.account w3 = make_web3_provider( configuration_file.ethereum_client_rpc_endpoint, account) service_token = Erc20Token.find_by_ticker( settings.service_token.ticker) service_token_balance = get_token_balance(w3=w3, account=account, token=service_token) service_token_in_deposit = get_token_deposit(w3=w3, account=account, token=service_token) if service_token_balance.as_wei and service_token_in_deposit < SERVICE_TOKEN_REQUIRED: self._send_status_update( f"Making deposit of {service_token_balance.formatted} for Raiden Services" ) deposit_service_tokens(w3=w3, account=account, token=service_token, amount=service_token_balance.as_wei) service_token_deposited = get_token_deposit(w3=w3, account=account, token=service_token) self._send_status_update( f"Amount deposited at UDC: {service_token_deposited.formatted}" ) self._send_status_update( "Launching Raiden, this might take a couple of minutes, do not close the browser" ) if not RAIDEN_CLIENT.is_running: RAIDEN_CLIENT.launch(configuration_file) try: RAIDEN_CLIENT.wait_for_web_ui_ready() self._send_task_complete("Raiden is ready!") self._send_redirect(RAIDEN_CLIENT.WEB_UI_INDEX_URL) except (RaidenClientError, RuntimeError) as exc: self._send_error_message(f"Raiden process failed to start: {exc}") RAIDEN_CLIENT.kill()
def _run_track_transaction(self, **kw): configuration_file_name = kw.get("configuration_file_name") tx_hash = kw.get("tx_hash") time_start = time.time() try: configuration_file = RaidenConfigurationFile.get_by_filename( configuration_file_name) configuration_file._initial_funding_txhash = tx_hash configuration_file.save() account = configuration_file.account w3 = make_web3_provider( configuration_file.ethereum_client_rpc_endpoint, account) self._send_txhash_message( ["Waiting for confirmation of transaction"], tx_hash=tx_hash) transaction_found = False while (not transaction_found) and (time.time() - time_start < WEB3_TIMEOUT): try: tx_receipt = w3.eth.waitForTransactionReceipt( decode_hex(tx_hash), timeout=WEB3_TIMEOUT) assert tx_receipt.get("blockNumber", 0) > 0 transaction_found = True except TimeExhausted: pass if not transaction_found: self._send_status_update([ f"Not confirmed after {int(time.time() - time_start)} seconds!" ], icon="error") self._send_txhash_message( "Funding took too long! " "Click the link below and restart the wizard, " "once it was confirmed:", tx_hash=tx_hash, ) time.sleep(10) sys.exit(1) else: configuration_file._initial_funding_txhash = None configuration_file.save() self._send_status_update("Transaction confirmed") service_token = configuration_file.settings.service_token self._send_redirect( self.reverse_url("swap", configuration_file.file_name, service_token.ticker)) except Exception as exc: self._send_error_message(str(exc))
def _run_udc_deposit(self, **kw): try: configuration_file_name = kw.get("configuration_file_name") configuration_file = RaidenConfigurationFile.get_by_filename( configuration_file_name) except (ValueError, KeyError, TypeError) as exc: self._send_error_message(f"Invalid request: {exc}") return try: settings = self.installer_settings required = RequiredAmounts.from_settings(settings) swap_amounts = SwapAmounts.from_settings(settings) service_token = Erc20Token.find_by_ticker( required.service_token.ticker, settings.network) account = configuration_file.account try_unlock(account) w3 = make_web3_provider( configuration_file.ethereum_client_rpc_endpoint, account) service_token_balance = get_token_balance(w3, account, service_token) service_token_deposited = get_token_deposit( w3, account, service_token) if service_token_deposited < required.service_token: swap_amount = swap_amounts.service_token if service_token_balance >= swap_amount: deposit = swap_amount - service_token_deposited else: deposit = service_token_balance self._deposit_to_udc(w3, account, service_token, deposit) else: self._send_status_update( f"Service token deposited at UDC: {service_token_deposited.formatted} is enough" ) time.sleep(5) transfer_token = Erc20Token.find_by_ticker( required.transfer_token.ticker, settings.network) transfer_token_balance = get_token_balance(w3, account, transfer_token) self._redirect_transfer_swap(configuration_file, transfer_token_balance, required) except (json.decoder.JSONDecodeError, KeyError, ExchangeError, ValueError) as exc: self._redirect_after_swap_error(exc, configuration_file.file_name, service_token.ticker)
def get(self, exchange_name, configuration_file_name, token_ticker): exchange_class = Exchange.get_by_name(exchange_name) configuration_file = RaidenConfigurationFile.get_by_filename(configuration_file_name) w3 = make_web3_provider( configuration_file.ethereum_client_rpc_endpoint, configuration_file.account ) self.render( "swap.html", exchange=exchange_class(w3=w3), configuration_file=configuration_file, balance=configuration_file.account.get_ethereum_balance(w3), token=Erc20Token.find_by_ticker(token_ticker), )
def get(self, configuration_file_name): configuration_file = RaidenConfigurationFile.get_by_filename( configuration_file_name) network = configuration_file.network.name account = configuration_file.account try_unlock(account) w3 = make_web3_provider( configuration_file.ethereum_client_rpc_endpoint, account) required = RequiredAmounts.for_network(network) service_token = Erc20Token.find_by_ticker( required.service_token.ticker, network) transfer_token = Erc20Token.find_by_ticker( required.transfer_token.ticker, network) service_token_balance = get_total_token_owned( w3=w3, account=configuration_file.account, token=service_token) transfer_token_balance = get_token_balance( w3=w3, account=configuration_file.account, token=transfer_token) eth_balance = configuration_file.account.get_ethereum_balance(w3) def serialize_balance(balance_amount): return ({ "as_wei": balance_amount.as_wei, "formatted": balance_amount.formatted } if balance_amount else None) self.render_json({ "url": self.reverse_url("api-configuration-detail", configuration_file.file_name), "file_name": configuration_file.file_name, "account_page_url": self.reverse_url("account", configuration_file.file_name), "account": configuration_file.account.address, "network": configuration_file.network.name, "balance": { "ETH": serialize_balance(eth_balance), "service_token": serialize_balance(service_token_balance), "transfer_token": serialize_balance(transfer_token_balance), }, "_initial_funding_txhash": configuration_file._initial_funding_txhash, })
def get(self, configuration_file_name, token_ticker): configuration_file = RaidenConfigurationFile.get_by_filename(configuration_file_name) w3 = make_web3_provider( configuration_file.ethereum_client_rpc_endpoint, configuration_file.account ) kyber = Kyber(w3=w3) uniswap = Uniswap(w3=w3) token = Erc20Token.find_by_ticker(token_ticker) self.render( "swap_options.html", configuration_file=configuration_file, kyber=kyber, uniswap=uniswap, token=token, )
def get(self, configuration_file_name): configuration_file = RaidenConfigurationFile.get_by_filename( configuration_file_name) keystore_path = configuration_file.configuration_data["keystore-path"] filename = "" for file in glob(f"{keystore_path}/UTC--*"): file_path = Path(file) if file_path.is_file(): keystore_content = json.loads(file_path.read_text()) if (to_checksum_address(keystore_content["address"]) == configuration_file.account.address): filename = os.path.basename(file) break self.render("account.html", configuration_file=configuration_file, keystore=filename)
def get(self, configuration_file_name): configuration_file = RaidenConfigurationFile.get_by_filename( configuration_file_name) keystore_path = configuration_file.configuration_data["keystore-path"] filename = "" for file in glob(f"{keystore_path}/UTC--*"): file_path = Path(file) if file_path.is_file(): keystore_content = json.loads(file_path.read_text()) if (to_checksum_address(keystore_content["address"]) == configuration_file.account.address): filename = os.path.basename(file) break w3 = make_web3_provider( configuration_file.ethereum_client_rpc_endpoint, configuration_file.account) required = RequiredAmounts.for_network(configuration_file.network.name) eth_balance = configuration_file.account.get_ethereum_balance(w3) log.info(f"Checking balance {eth_balance} > {required.eth}") if eth_balance < required.eth: log.info( f"funding tx {configuration_file._initial_funding_txhash}") if configuration_file._initial_funding_txhash is not None: return self.render( "account.html", configuration_file=configuration_file, keystore=filename, ) else: configuration_file._initial_funding_txhash = None configuration_file.save() if PASSPHRASE is not None: self.render("account.html", configuration_file=configuration_file, keystore=filename) else: self.render( "account_unlock.html", keystore_file_path=configuration_file.account. keystore_file_path, return_to=f"/account/{configuration_file_name}", )
def get(self, configuration_file_name): configuration_file = RaidenConfigurationFile.get_by_filename( configuration_file_name) account = configuration_file.account w3 = make_web3_provider( configuration_file.ethereum_client_rpc_endpoint, account) service_token = Erc20Token.find_by_ticker( SERVICE_TOKEN_REQUIRED.ticker) transfer_token = Erc20Token.find_by_ticker( TRANSFER_TOKEN_REQUIRED.ticker) service_token_balance = get_total_token_owned( w3=w3, account=configuration_file.account, token=service_token) transfer_token_balance = get_token_balance( w3=w3, account=configuration_file.account, token=transfer_token) eth_balance = configuration_file.account.get_ethereum_balance(w3) def serialize_balance(balance_amount): return ({ "as_wei": balance_amount.as_wei, "formatted": balance_amount.formatted } if balance_amount else None) self.render_json({ "url": self.reverse_url("api-configuration-detail", configuration_file.file_name), "file_name": configuration_file.file_name, "account_page_url": self.reverse_url("account", configuration_file.file_name), "funding_page_url": self.reverse_url("funding", configuration_file.file_name), "account": configuration_file.account.address, "network": configuration_file.network.name, "balance": { "ETH": serialize_balance(eth_balance), "service_token": serialize_balance(service_token_balance), "transfer_token": serialize_balance(transfer_token_balance), }, })
def get(self, configuration_file_name): configuration_file = RaidenConfigurationFile.get_by_filename( configuration_file_name) w3 = make_web3_provider( configuration_file.ethereum_client_rpc_endpoint, configuration_file.account) current_balance = configuration_file.account.get_ethereum_balance(w3) if PASSPHRASE is not None: self.render("launch.html", configuration_file=configuration_file, balance=current_balance) else: self.render( "account_unlock.html", keystore_file_path=configuration_file.account. keystore_file_path, return_to=f"/launch/{configuration_file_name}", )
def _run_track_transaction(self, **kw): try: configuration_file_name = kw.get("configuration_file_name") tx_hash = kw.get("tx_hash") configuration_file = RaidenConfigurationFile.get_by_filename( configuration_file_name) except Exception as exc: self._send_error_message(str(exc)) return configuration_file._initial_funding_txhash = tx_hash configuration_file.save() account = configuration_file.account w3 = make_web3_provider( configuration_file.ethereum_client_rpc_endpoint, account) self._send_txhash_message(["Waiting for confirmation of transaction"], tx_hash=tx_hash) try: wait_for_transaction(w3, decode_hex(tx_hash)) except TransactionTimeoutError: self._send_status_update( [f"Not confirmed after {WEB3_TIMEOUT} seconds!"], icon="error") self._send_txhash_message( "Funding took too long! " "Click the link below and restart the wizard, " "once it was confirmed:", tx_hash=tx_hash, ) time.sleep(10) sys.exit(1) else: configuration_file._initial_funding_txhash = None configuration_file.save() self._send_status_update("Transaction confirmed") service_token = configuration_file.settings.service_token self._send_redirect( self.reverse_url("swap", configuration_file.file_name, service_token.ticker))
def get(self, configuration_file_name): configuration_file = RaidenConfigurationFile.get_by_filename( configuration_file_name) if get_passphrase() is None: self.render( "account_unlock.html", keystore_file_path=configuration_file.account. keystore_file_path, return_to=f"/account/{configuration_file_name}", ) return keystore_path = configuration_file.configuration_data["keystore-path"] filename = "" for file in glob(f"{keystore_path}/UTC--*"): file_path = Path(file) if file_path.is_file(): keystore_content = json.loads(file_path.read_text()) if (to_canonical_address(keystore_content["address"]) == configuration_file.account.address): filename = os.path.basename(file) break w3 = make_web3_provider( configuration_file.ethereum_client_rpc_endpoint, configuration_file.account) required = RequiredAmounts.from_settings(self.installer_settings) eth_balance = configuration_file.account.get_ethereum_balance(w3) log.info(f"funding tx {configuration_file._initial_funding_txhash}") log.info(f"Checking balance {eth_balance} >= {required.eth}") if eth_balance >= required.eth: configuration_file._initial_funding_txhash = None configuration_file.save() self.render( "account.html", configuration_file=configuration_file, keystore=filename, ramp_api_key=RAMP_API_KEY, )
def post(self, configuration_file_name): configuration_file = RaidenConfigurationFile.get_by_filename( configuration_file_name) account = configuration_file.account w3 = make_web3_provider( configuration_file.ethereum_client_rpc_endpoint, account) ex_currency_amt = json_decode(self.request.body) exchange = Exchange.get_by_name(ex_currency_amt["exchange"])(w3=w3) currency = Erc20Token.find_by_ticker(ex_currency_amt["currency"], configuration_file.network) token_amount = TokenAmount(ex_currency_amt["target_amount"], currency) exchange_costs = exchange.calculate_transaction_costs( token_amount, account) total_cost = exchange_costs["total"] self.render_json({ "exchange": exchange.name, "currency": currency.ticker, "target_amount": ex_currency_amt["target_amount"], "as_wei": total_cost.as_wei, "formatted": total_cost.formatted, "utc_seconds": int(time.time()), })
def _run_launch(self, **kw): configuration_file_name = kw.get("configuration_file_name") configuration_file = RaidenConfigurationFile.get_by_filename( configuration_file_name) network_name = configuration_file.network.name raiden_client = RaidenClient.get_client(network_name) if not raiden_client.is_installed: self._send_status_update( f"Downloading and installing raiden {raiden_client.release}") raiden_client.install() self._send_status_update("Installation complete") account = configuration_file.account try_unlock(account) if account.passphrase is None: return self.render( "account_unlock.html", keystore_file_path=account.keystore_file_path, return_to=f"/launch/{configuration_file_name}", ) self._send_status_update( "Launching Raiden, this might take a couple of minutes, do not close the browser" ) with temporary_passphrase_file(PASSPHRASE) as passphrase_file: if not raiden_client.is_running: raiden_client.launch(configuration_file, passphrase_file) try: raiden_client.wait_for_web_ui_ready( status_callback=lambda stat: log.info(str(stat))) self._send_task_complete("Raiden is ready!") self._send_redirect(raiden_client.WEB_UI_INDEX_URL) except (RaidenClientError, RuntimeError) as exc: self._send_error_message( f"Raiden process failed to start: {exc}") raiden_client.kill()
def _run_track_transaction(self, **kw): POLLING_INTERVAL = 10 configuration_file_name = kw.get("configuration_file_name") tx_hash = kw.get("tx_hash") time_elapsed = 0 try: configuration_file = RaidenConfigurationFile.get_by_filename( configuration_file_name) account = configuration_file.account w3 = make_web3_provider( configuration_file.ethereum_client_rpc_endpoint, account) self._send_txhash_message( ["Waiting for confirmation of transaction"], tx_hash=tx_hash) transaction_found = False iteration_cycle = 0 while not transaction_found and iteration_cycle < 30: try: w3.eth.getTransactionReceipt(tx_hash) transaction_found = True except Exception: time.sleep(2) while not w3.eth.getTransactionReceipt(tx_hash): time.sleep(POLLING_INTERVAL) time_elapsed += POLLING_INTERVAL self._send_status_update( f"Not confirmed after {time_elapsed} seconds...") self._send_status_update("Transaction confirmed") service_token = configuration_file.settings.service_token self._send_redirect( self.reverse_url("swap", configuration_file.file_name, service_token.ticker)) except Exception as exc: self._send_error_message(str(exc))