def check_synced(blockchain_service: BlockChainService) -> None: net_id = blockchain_service.network_id try: network = ID_TO_NETWORKNAME[net_id] except (EthNodeCommunicationError, RequestException): click.secho( 'Could not determine the network the ethereum node is connected.\n' 'Because of this there is no way to determine the latest\n' 'block with an oracle, and the events from the ethereum\n' 'node cannot be trusted. Giving up.\n', fg='red', ) sys.exit(1) except KeyError: click.secho( f'Your ethereum client is connected to a non-recognized private \n' f'network with network-ID {net_id}. Since we can not check if the client \n' f'is synced please restart raiden with the --no-sync-check argument.' f'\n', fg='red', ) sys.exit(1) url = ETHERSCAN_API.format( network=network if net_id != 1 else 'api', action='eth_blockNumber', ) wait_for_sync( blockchain_service, url=url, tolerance=ORACLE_BLOCKNUMBER_DRIFT_TOLERANCE, sleep=3, )
def check_synced(blockchain_service): try: net_id = int(blockchain_service.client.call('net_version')) network = ID_TO_NETWORKNAME[net_id] except (EthNodeCommunicationError, RequestException): print( "Couldn't determine the network the ethereum node is connected.\n" "Because of this there is no way to determine the latest\n" "block with an oracle, and the events from the ethereum\n" "node cannot be trusted. Giving up.\n") sys.exit(1) except KeyError: print( 'Your ethereum client is connected to a non-recognized private \n' 'network with network-ID {}. Since we can not check if the client \n' 'is synced please restart raiden with the --no-sync-check argument.' '\n'.format(net_id)) sys.exit(1) url = ETHERSCAN_API.format( network=network, action='eth_blockNumber', ) wait_for_sync( blockchain_service, url=url, tolerance=ORACLE_BLOCKNUMBER_DRIFT_TOLERANCE, sleep=3, )
def check_synced(blockchain_service: BlockChainService) -> None: net_id = blockchain_service.network_id try: network = constants.ID_TO_NETWORKNAME[net_id] except (EthNodeCommunicationError, RequestException): print( 'Could not determine the network the ethereum node is connected.\n' 'Because of this there is no way to determine the latest\n' 'block with an oracle, and the events from the ethereum\n' 'node cannot be trusted. Giving up.\n', ) sys.exit(1) except KeyError: print( 'Your ethereum client is connected to a non-recognized private \n' 'network with network-ID {}. Since we can not check if the client \n' 'is synced please restart raiden with the --no-sync-check argument.' '\n'.format(net_id), ) sys.exit(1) url = ETHERSCAN_API.format( network=network if net_id != 1 else 'api', action='eth_blockNumber', ) wait_for_sync( blockchain_service, url=url, tolerance=ORACLE_BLOCKNUMBER_DRIFT_TOLERANCE, sleep=3, )
def check_synced(rpc_client: JSONRPCClient) -> None: network_id = ChainID(int(rpc_client.web3.version.network)) network_name = ID_TO_NETWORKNAME.get(network_id) if network_name is None: raise RaidenError( f"Your ethereum client is connected to a non-recognized private " f"network with network-ID {network_id}. Since we can not check if the " f"client is synced please restart raiden with the --no-sync-check " f"argument." ) url = ETHERSCAN_API.format( network=network_name if network_id != 1 else "api", action="eth_blockNumber" ) wait_for_sync( rpc_client=rpc_client, url=url, tolerance=ORACLE_BLOCKNUMBER_DRIFT_TOLERANCE, sleep=3 )
def check_synced(proxy_manager: ProxyManager) -> None: network_id = ChainID(int(proxy_manager.client.web3.version.network)) network_name = ID_TO_NETWORKNAME.get(network_id) if network_name is None: msg = ( f"Your ethereum client is connected to a non-recognized private " f"network with network-ID {network_id}. Since we can not check if the " f"client is synced please restart raiden with the --no-sync-check " f"argument." ) click.secho(msg, fg="red") sys.exit(1) url = ETHERSCAN_API.format( network=network_name if network_id != 1 else "api", action="eth_blockNumber" ) wait_for_sync(proxy_manager, url=url, tolerance=ORACLE_BLOCKNUMBER_DRIFT_TOLERANCE, sleep=3)
def check_synced(blockchain_service): try: net_id = int(blockchain_service.client.call('net_version')) network = ID_TO_NETWORKNAME[net_id] except: print( "Couldn't determine the network the ethereum node is connected.\n" "Because of this there is no way to determine the latest\n" "block with an oracle, and the events from the ethereum\n" "node cannot be trusted. Giving up.\n") sys.exit(1) url = ETHERSCAN_API.format( network=network, action='eth_blockNumber', ) wait_for_sync( blockchain_service, url=url, tolerance=ORACLE_BLOCKNUMBER_DRIFT_TOLERANCE, sleep=3, )
def app(address, keystore_path, eth_rpc_endpoint, registry_contract_address, discovery_contract_address, listen_address, rpccorsdomain, mapped_socket, logging, logfile, log_json, max_unresponsive_time, send_ping_time, api_address, rpc, sync_check, console, password_file, web_ui, datadir, eth_client_communication, nat): # pylint: disable=too-many-locals,too-many-branches,too-many-statements,unused-argument from raiden.app import App from raiden.network.rpc.client import BlockChainService (listen_host, listen_port) = split_endpoint(listen_address) (api_host, api_port) = split_endpoint(api_address) config = App.DEFAULT_CONFIG.copy() config['host'] = listen_host config['port'] = listen_port config['console'] = console config['rpc'] = rpc config['web_ui'] = rpc and web_ui config['api_host'] = api_host config['api_port'] = api_port if mapped_socket: config['socket'] = mapped_socket.socket config['external_ip'] = mapped_socket.external_ip config['external_port'] = mapped_socket.external_port else: config['socket'] = None config['external_ip'] = listen_host config['external_port'] = listen_port config['protocol']['nat_keepalive_retries'] = DEFAULT_NAT_KEEPALIVE_RETRIES timeout = max_unresponsive_time / DEFAULT_NAT_KEEPALIVE_RETRIES config['protocol']['nat_keepalive_timeout'] = timeout address_hex = address_encoder(address) if address else None address_hex, privatekey_bin = prompt_account(address_hex, keystore_path, password_file) privatekey_hex = privatekey_bin.encode('hex') config['privatekey_hex'] = privatekey_hex endpoint = eth_rpc_endpoint # Fallback default port if only an IP address is given rpc_port = 8545 if eth_rpc_endpoint.startswith("http://"): endpoint = eth_rpc_endpoint[len("http://"):] rpc_port = 80 elif eth_rpc_endpoint.startswith("https://"): endpoint = eth_rpc_endpoint[len("https://"):] rpc_port = 443 if ':' not in endpoint: # no port was given in url rpc_host = endpoint else: rpc_host, rpc_port = split_endpoint(endpoint) rpc_client = JSONRPCClient( privkey=privatekey_bin, host=rpc_host, port=rpc_port, print_communication=eth_client_communication, ) # this assumes the eth node is already online patch_send_transaction(rpc_client) patch_send_message(rpc_client) try: blockchain_service = BlockChainService( privatekey_bin, rpc_client, ) except ValueError as e: # ValueError exception raised if: # - The registry contract address doesn't have code, this might happen # if the connected geth process is not synced or if the wrong address # is provided (e.g. using the address from a smart contract deployed on # ropsten with a geth node connected to morden) print(e.message) sys.exit(1) if sync_check: try: net_id = int(blockchain_service.client.call('net_version')) network = ID_TO_NETWORKNAME[net_id] except: # pylint: disable=bare-except print( "Couldn't determine the network the ethereum node is connected to.\n" "Because of this there is not way to determine the latest\n" "block with an oracle, and the events from the ethereum\n" "node cannot be trusted. Giving up.\n") sys.exit(1) url = ETHERSCAN_API.format( network=network, action='eth_blockNumber', ) wait_for_sync( blockchain_service, url=url, tolerance=ORACLE_BLOCKNUMBER_DRIFT_TOLERANCE, sleep=3, ) discovery_tx_cost = GAS_PRICE * DISCOVERY_REGISTRATION_GAS while True: balance = blockchain_service.client.balance(address_hex) if discovery_tx_cost <= balance: break print('Account has insufficient funds for discovery registration.\n' 'Needed: {} ETH\n' 'Available: {} ETH.\n' 'Please deposit additional funds on this account.'.format( discovery_tx_cost / float(denoms.ether), balance / float(denoms.ether))) if not click.confirm('Try again?'): sys.exit(1) registry = blockchain_service.registry(registry_contract_address, ) discovery = ContractDiscovery( blockchain_service.node_address, blockchain_service.discovery(discovery_contract_address)) if datadir is None: # default database directory raiden_directory = os.path.join(os.path.expanduser('~'), '.raiden') else: raiden_directory = datadir if not os.path.exists(raiden_directory): os.makedirs(raiden_directory) user_db_dir = os.path.join(raiden_directory, address_hex[:8]) if not os.path.exists(user_db_dir): os.makedirs(user_db_dir) database_path = os.path.join(user_db_dir, 'log.db') config['database_path'] = database_path return App( config, blockchain_service, registry, discovery, )