예제 #1
0
def test_check_json_rpc_geth():
    g1, client = is_supported_client(
        'Geth/v1.7.3-unstable-e9295163/linux-amd64/go1.9.1')
    g2, _ = is_supported_client(
        'Geth/v1.7.2-unstable-e9295163/linux-amd64/go1.9.1')
    g3, _ = is_supported_client(
        'Geth/v1.8.2-unstable-e9295163/linux-amd64/go1.9.1')
    g4, _ = is_supported_client(
        'Geth/v2.0.3-unstable-e9295163/linux-amd64/go1.9.1')
    g5, _ = is_supported_client(
        'Geth/v11.55.86-unstable-e9295163/linux-amd64/go1.9.1')
    g6, _ = is_supported_client(
        'Geth/v999.999.999-unstable-e9295163/linux-amd64/go1.9.1')
    assert client == EthClient.GETH
    assert all([g1, g2, g3, g4, g5, g6])

    b1, client = is_supported_client(
        'Geth/v1.7.1-unstable-e9295163/linux-amd64/go1.9.1')
    b2, _ = is_supported_client(
        'Geth/v0.7.1-unstable-e9295163/linux-amd64/go1.9.1')
    b3, _ = is_supported_client(
        'Geth/v0.0.0-unstable-e9295163/linux-amd64/go1.9.1')
    b4, _ = is_supported_client(
        'Geth/v0.0.0-unstable-e9295163/linux-amd64/go1.9.1')
    assert not client
    assert not any([b1, b2, b3, b4])
예제 #2
0
def test_check_json_rpc_geth():
    g1, client = is_supported_client('Geth/v1.7.3-unstable-e9295163/linux-amd64/go1.9.1')
    g2, _ = is_supported_client('Geth/v1.7.2-unstable-e9295163/linux-amd64/go1.9.1')
    g3, _ = is_supported_client('Geth/v1.8.2-unstable-e9295163/linux-amd64/go1.9.1')
    g4, _ = is_supported_client('Geth/v2.0.3-unstable-e9295163/linux-amd64/go1.9.1')
    g5, _ = is_supported_client('Geth/v11.55.86-unstable-e9295163/linux-amd64/go1.9.1')
    g6, _ = is_supported_client('Geth/v999.999.999-unstable-e9295163/linux-amd64/go1.9.1')
    assert client == EthClient.GETH
    assert all([g1, g2, g3, g4, g5, g6])

    b1, client = is_supported_client('Geth/v1.7.1-unstable-e9295163/linux-amd64/go1.9.1')
    b2, _ = is_supported_client('Geth/v0.7.1-unstable-e9295163/linux-amd64/go1.9.1')
    b3, _ = is_supported_client('Geth/v0.0.0-unstable-e9295163/linux-amd64/go1.9.1')
    b4, _ = is_supported_client('Geth/v0.0.0-unstable-e9295163/linux-amd64/go1.9.1')
    assert not client
    assert not any([b1, b2, b3, b4])
예제 #3
0
    def __init__(
        self,
        host: str,
        port: int,
        privkey: bytes,
        gasprice: int = None,
        nonce_update_interval: float = 5.0,
        nonce_offset: int = 0,
        web3: Web3 = None,
    ):

        if privkey is None or len(privkey) != 32:
            raise ValueError('Invalid private key')

        endpoint = 'http://{}:{}'.format(host, port)

        self.port = port
        self.privkey = privkey
        self.sender = privatekey_to_address(privkey)
        # Needs to be initialized to None in the beginning since JSONRPCClient
        # gets constructed before the RaidenService Object.
        self.stop_event = None

        self._nonce_offset = nonce_offset
        self._nonce_lock = Semaphore()
        self.given_gas_price = gasprice

        self._gaslimit_cache = TTLCache(maxsize=16, ttl=RPC_CACHE_TTL)
        self._gasprice_cache = TTLCache(maxsize=16, ttl=RPC_CACHE_TTL)
        self._nonce_cache = TTLCache(maxsize=16, ttl=nonce_update_interval)

        # web3
        if web3 is None:
            self.web3: Web3 = Web3(HTTPProvider(endpoint))
        else:
            self.web3 = web3
        try:
            # we use a PoA chain for smoketest, use this middleware to fix this
            self.web3.middleware_stack.inject(geth_poa_middleware, layer=0)
        except ValueError:
            # `middleware_stack.inject()` raises a value error if the same middleware is
            # injected twice. This happens with `eth-tester` setup where a single session
            # scoped web3 instance is used for all clients
            pass

        # create the connection test middleware (but only for non-tester chain)
        if not hasattr(web3, 'testing'):
            connection_test = make_connection_test_middleware(self)
            self.web3.middleware_stack.inject(connection_test, layer=0)

        supported, self.eth_node = is_supported_client(self.web3.version.node)

        if not supported:
            print(
                'You need a Byzantium enabled ethereum node. Parity >= 1.7.6 or Geth >= 1.7.2'
            )
            sys.exit(1)
예제 #4
0
def test_check_json_rpc_geth():
    assert is_supported_client(
        'Geth/v1.7.3-unstable-e9295163/linux-amd64/go1.9.1')
    assert is_supported_client(
        'Geth/v1.7.2-unstable-e9295163/linux-amd64/go1.9.1')
    assert is_supported_client(
        'Geth/v1.8.2-unstable-e9295163/linux-amd64/go1.9.1')
    assert is_supported_client(
        'Geth/v2.0.3-unstable-e9295163/linux-amd64/go1.9.1')
    assert is_supported_client(
        'Geth/v11.55.86-unstable-e9295163/linux-amd64/go1.9.1')
    assert is_supported_client(
        'Geth/v999.999.999-unstable-e9295163/linux-amd64/go1.9.1')

    assert not is_supported_client(
        'Geth/v1.7.1-unstable-e9295163/linux-amd64/go1.9.1')
    assert not is_supported_client(
        'Geth/v0.7.1-unstable-e9295163/linux-amd64/go1.9.1')
    assert not is_supported_client(
        'Geth/v0.0.0-unstable-e9295163/linux-amd64/go1.9.1')
    assert not is_supported_client(
        'Geth/v0.0.0-unstable-e9295163/linux-amd64/go1.9.1')
예제 #5
0
파일: app.py 프로젝트: onyb/raiden
def _setup_web3(eth_rpc_endpoint):
    web3 = Web3(HTTPProvider(eth_rpc_endpoint))

    try:
        node_version = web3.version.node  # pylint: disable=no-member
    except ConnectTimeout:
        raise EthNodeCommunicationError("Couldn't connect to the ethereum node")

    supported, _ = is_supported_client(node_version)
    if not supported:
        click.secho(
            'You need a Byzantium enabled ethereum node. Parity >= 1.7.6 or Geth >= 1.7.2',
            fg='red',
        )
        sys.exit(1)
    return web3
예제 #6
0
def check_json_rpc(client):
    try:
        client_version = client.web3.version.node
    except (requests.exceptions.ConnectionError, EthNodeCommunicationError):
        print(
            '\n'
            'Could not contact the ethereum node through JSON-RPC.\n'
            'Please make sure that JSON-RPC is enabled for these interfaces:\n'
            '\n'
            '    eth_*, net_*, web3_*\n'
            '\n'
            'geth: https://github.com/ethereum/go-ethereum/wiki/Management-APIs\n'
        )
        sys.exit(1)
    else:
        if not is_supported_client(client_version):
            print('You need a Byzantium enabled ethereum node. Parity >= 1.7.6 or Geth >= 1.7.2')
            sys.exit(1)
예제 #7
0
    def __init__(
        self,
        web3: Web3,
        privkey: bytes,
        gasprice: int = None,
        nonce_offset: int = 0,
    ):
        if privkey is None or len(privkey) != 32:
            raise ValueError('Invalid private key')

        monkey_patch_web3(web3, self)

        try:
            version = web3.version.node
        except ConnectTimeout:
            raise EthNodeCommunicationError('couldnt reach the ethereum node')

        _, eth_node = is_supported_client(version)

        sender = privatekey_to_address(privkey)
        transaction_count = web3.eth.getTransactionCount(
            to_checksum_address(sender), 'pending')
        _available_nonce = transaction_count + nonce_offset

        self.eth_node = eth_node
        self.given_gas_price = gasprice
        self.privkey = privkey
        self.sender = sender
        # Needs to be initialized to None in the beginning since JSONRPCClient
        # gets constructed before the RaidenService Object.
        self.stop_event = None
        self.web3 = web3

        self._gaslimit_cache = TTLCache(maxsize=16, ttl=RPC_CACHE_TTL)
        self._gasprice_cache = TTLCache(maxsize=16, ttl=RPC_CACHE_TTL)
        self._available_nonce = _available_nonce
        self._nonce_lock = Semaphore()
        self._nonce_offset = nonce_offset

        log.debug(
            'JSONRPCClient created',
            sender=pex(self.sender),
            available_nonce=_available_nonce,
        )
예제 #8
0
파일: app.py 프로젝트: hackaugusto/raiden
def _setup_web3(eth_rpc_endpoint):
    web3 = Web3(HTTPProvider(eth_rpc_endpoint))

    try:
        node_version = web3.version.node  # pylint: disable=no-member
    except ConnectTimeout:
        raise EthNodeCommunicationError("Couldn't connect to the ethereum node")
    except ValueError:
        raise EthNodeInterfaceError(
            'The underlying ethereum node does not have the web3 rpc interface '
            'enabled. Please run it with --rpcapi eth,net,web3,txpool for geth '
            'and --jsonrpc-apis=eth,net,web3,parity for parity.',
        )

    supported, _ = is_supported_client(node_version)
    if not supported:
        click.secho(
            'You need a Byzantium enabled ethereum node. Parity >= 1.7.6 or Geth >= 1.7.2',
            fg='red',
        )
        sys.exit(1)
    return web3
예제 #9
0
    def __init__(
        self,
        web3: Web3,
        privkey: bytes,
        gas_price_strategy: Callable = rpc_gas_price_strategy,
        nonce_offset: int = 0,
    ):
        if privkey is None or len(privkey) != 32:
            raise ValueError('Invalid private key')

        monkey_patch_web3(web3, self, gas_price_strategy)

        try:
            version = web3.version.node
        except ConnectTimeout:
            raise EthNodeCommunicationError('couldnt reach the ethereum node')

        _, eth_node = is_supported_client(version)

        sender = privatekey_to_address(privkey)
        transaction_count = web3.eth.getTransactionCount(
            to_checksum_address(sender), 'pending')
        _available_nonce = transaction_count + nonce_offset

        self.eth_node = eth_node
        self.privkey = privkey
        self.sender = sender
        self.web3 = web3

        self._gasprice_cache = TTLCache(maxsize=16, ttl=RPC_CACHE_TTL)
        self._available_nonce = _available_nonce
        self._nonce_lock = Semaphore()
        self._nonce_offset = nonce_offset

        log.debug(
            'JSONRPCClient created',
            sender=pex(self.sender),
            available_nonce=_available_nonce,
        )
예제 #10
0
def _setup_web3(eth_rpc_endpoint):
    web3 = Web3(HTTPProvider(eth_rpc_endpoint))

    try:
        node_version = web3.version.node  # pylint: disable=no-member
    except ConnectTimeout:
        raise EthNodeCommunicationError(
            "Couldn't connect to the ethereum node")
    except ValueError:
        raise EthNodeInterfaceError(
            'The underlying ethereum node does not have the web3 rpc interface '
            'enabled. Please run it with --rpcapi eth,net,web3,txpool for geth '
            'and --jsonrpc-apis=eth,net,web3,parity for parity.', )

    supported, _ = is_supported_client(node_version)
    if not supported:
        click.secho(
            'You need a Byzantium enabled ethereum node. Parity >= 1.7.6 or Geth >= 1.7.2',
            fg='red',
        )
        sys.exit(1)
    return web3
예제 #11
0
파일: client.py 프로젝트: AlphaX-IBS/raiden
    def __init__(
            self,
            host: str,
            port: int,
            privkey: bytes,
            gasprice: int = None,
            nonce_update_interval: float = 5.0,
            nonce_offset: int = 0,
            web3: Web3 = None,
    ):

        if privkey is None or len(privkey) != 32:
            raise ValueError('Invalid private key')

        endpoint = 'http://{}:{}'.format(host, port)

        self.port = port
        self.privkey = privkey
        self.sender = privatekey_to_address(privkey)
        # Needs to be initialized to None in the beginning since JSONRPCClient
        # gets constructed before the RaidenService Object.
        self.stop_event = None

        self.nonce_last_update = 0
        self.nonce_available_value = None
        self.nonce_lock = Semaphore()
        self.nonce_update_interval = nonce_update_interval
        self.nonce_offset = nonce_offset
        self.given_gas_price = gasprice

        cache = cachetools.TTLCache(
            maxsize=1,
            ttl=RPC_CACHE_TTL,
        )
        cache_wrapper = cachetools.cached(cache=cache)
        self.gaslimit = cache_wrapper(self._gaslimit)
        cache = cachetools.TTLCache(
            maxsize=1,
            ttl=RPC_CACHE_TTL,
        )
        cache_wrapper = cachetools.cached(cache=cache)
        self.gasprice = cache_wrapper(self._gasprice)

        # web3
        if web3 is None:
            self.web3: Web3 = Web3(HTTPProvider(endpoint))
        else:
            self.web3 = web3
        try:
            # we use a PoA chain for smoketest, use this middleware to fix this
            self.web3.middleware_stack.inject(geth_poa_middleware, layer=0)
        except ValueError:
            # `middleware_stack.inject()` raises a value error if the same middleware is
            # injected twice. This happens with `eth-tester` setup where a single session
            # scoped web3 instance is used for all clients
            pass

        # create the connection test middleware (but only for non-tester chain)
        if not hasattr(web3, 'testing'):
            connection_test = make_connection_test_middleware(self)
            self.web3.middleware_stack.inject(connection_test, layer=0)

        supported, self.eth_node = is_supported_client(self.web3.version.node)

        if not supported:
            print('You need a Byzantium enabled ethereum node. Parity >= 1.7.6 or Geth >= 1.7.2')
            sys.exit(1)
예제 #12
0
def test_check_json_rpc_parity():
    g1, client = is_supported_client(
        'Parity//v1.7.6-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    g2, _ = is_supported_client(
        'Parity//v1.7.7-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    g3, _ = is_supported_client(
        'Parity//v1.8.7-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    g4, _ = is_supported_client(
        'Parity//v2.9.7-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    g5, _ = is_supported_client(
        'Parity//v23.94.75-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    g6, _ = is_supported_client(
        'Parity//v99.994.975-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    assert client == EthClient.PARITY
    assert all([g1, g2, g3, g4, g5, g6])

    b1, client = is_supported_client(
        'Parity//v1.7.5-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    b2, _ = is_supported_client(
        'Parity//v1.5.1-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    b3, _ = is_supported_client(
        'Parity//v0.7.1-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    b4, _ = is_supported_client(
        'Parity//v0.8.7-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    b5, _ = is_supported_client(
        'Parity//v0.0.0-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    assert not client
    assert not any([b1, b2, b3, b4, b5])
예제 #13
0
def run_app(
    address,
    keystore_path,
    gas_price,
    eth_rpc_endpoint,
    registry_contract_address,
    secret_registry_contract_address,
    discovery_contract_address,
    listen_address,
    mapped_socket,
    max_unresponsive_time,
    api_address,
    rpc,
    sync_check,
    console,
    password_file,
    web_ui,
    datadir,
    transport,
    matrix_server,
    network_id,
    extra_config=None,
    **kwargs,
):
    # pylint: disable=too-many-locals,too-many-branches,too-many-statements,unused-argument

    from raiden.app import App

    if transport == 'udp' and not mapped_socket:
        raise RuntimeError('Missing socket')

    address_hex = to_normalized_address(address) if address else None
    address_hex, privatekey_bin = prompt_account(address_hex, keystore_path,
                                                 password_file)
    address = to_canonical_address(address_hex)

    (listen_host, listen_port) = split_endpoint(listen_address)
    (api_host, api_port) = split_endpoint(api_address)

    if datadir is None:
        datadir = os.path.join(os.path.expanduser('~'), '.raiden')

    config = deepcopy(App.DEFAULT_CONFIG)
    if extra_config:
        merge_dict(config, extra_config)

    config['transport']['udp']['host'] = listen_host
    config['transport']['udp']['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['transport']['udp']['external_ip'] = mapped_socket.external_ip
        config['transport']['udp'][
            'external_port'] = mapped_socket.external_port
    config['transport_type'] = transport
    config['transport']['matrix']['server'] = matrix_server
    config['transport']['udp'][
        'nat_keepalive_retries'] = DEFAULT_NAT_KEEPALIVE_RETRIES
    timeout = max_unresponsive_time / DEFAULT_NAT_KEEPALIVE_RETRIES
    config['transport']['udp']['nat_keepalive_timeout'] = timeout

    privatekey_hex = hexlify(privatekey_bin)
    config['privatekey_hex'] = privatekey_hex

    parsed_eth_rpc_endpoint = urlparse(eth_rpc_endpoint)
    if not parsed_eth_rpc_endpoint.scheme:
        eth_rpc_endpoint = f'http://{eth_rpc_endpoint}'

    web3 = Web3(HTTPProvider(eth_rpc_endpoint))

    try:
        node_version = web3.version.node  # pylint: disable=no-member
    except ConnectTimeout:
        raise EthNodeCommunicationError(
            "Couldn't connect to the ethereum node")

    supported, _ = is_supported_client(node_version)
    if not supported:
        print(
            'You need a Byzantium enabled ethereum node. Parity >= 1.7.6 or Geth >= 1.7.2'
        )
        sys.exit(1)

    rpc_client = JSONRPCClient(
        web3,
        privatekey_bin,
        gasprice=gas_price,
    )

    blockchain_service = BlockChainService(privatekey_bin, rpc_client)

    net_id = blockchain_service.network_id
    if net_id != network_id:
        if network_id in constants.ID_TO_NETWORKNAME and net_id in constants.ID_TO_NETWORKNAME:
            print((
                "The chosen ethereum network '{}' differs from the ethereum client '{}'. "
                'Please update your settings.').format(
                    constants.ID_TO_NETWORKNAME[network_id],
                    constants.ID_TO_NETWORKNAME[net_id]))
        else:
            print((
                "The chosen ethereum network id '{}' differs from the ethereum client '{}'. "
                'Please update your settings.').format(network_id, net_id))
        sys.exit(1)

    config['chain_id'] = network_id

    if sync_check:
        check_synced(blockchain_service)

    database_path = os.path.join(datadir, 'netid_%s' % net_id, address_hex[:8],
                                 'log.db')
    config['database_path'] = database_path
    print(
        '\nYou are connected to the \'{}\' network and the DB path is: {}'.
        format(
            constants.ID_TO_NETWORKNAME.get(net_id) or net_id,
            database_path,
        ), )

    contract_addresses_given = (registry_contract_address is not None and
                                secret_registry_contract_address is not None
                                and discovery_contract_address is not None)
    contract_addresses_known = net_id in constants.ID_TO_NETWORK_CONFIG

    if not contract_addresses_given and not contract_addresses_known:
        print((
            "There are known contract addresses for network id '{}'. Please provide "
            'them in the command line or the configuration file.'
        ).format(net_id))
        sys.exit(1)

    contract_addresses = constants.ID_TO_NETWORK_CONFIG.get(net_id, dict())

    try:
        token_network_registry = blockchain_service.token_network_registry(
            registry_contract_address
            or contract_addresses[CONTRACT_TOKEN_NETWORK_REGISTRY], )
    except ContractVersionMismatch:
        handle_contract_version_mismatch('token network registry',
                                         registry_contract_address)
    except AddressWithoutCode:
        handle_contract_no_code('token network registry',
                                registry_contract_address)
    except AddressWrongContract:
        handle_contract_wrong_address('token network registry',
                                      registry_contract_address)

    try:
        secret_registry = blockchain_service.secret_registry(
            secret_registry_contract_address
            or contract_addresses[CONTRACT_SECRET_REGISTRY], )
    except ContractVersionMismatch:
        handle_contract_version_mismatch('secret registry',
                                         secret_registry_contract_address)
    except AddressWithoutCode:
        handle_contract_no_code('secret registry',
                                secret_registry_contract_address)
    except AddressWrongContract:
        handle_contract_wrong_address('secret registry',
                                      secret_registry_contract_address)

    discovery = None
    if transport == 'udp':
        check_discovery_registration_gas(blockchain_service, address)
        try:
            dicovery_proxy = blockchain_service.discovery(
                discovery_contract_address
                or contract_addresses[CONTRACT_ENDPOINT_REGISTRY], )
            discovery = ContractDiscovery(
                blockchain_service.node_address,
                dicovery_proxy,
            )
        except ContractVersionMismatch:
            handle_contract_version_mismatch('discovery',
                                             discovery_contract_address)
        except AddressWithoutCode:
            handle_contract_no_code('discovery', discovery_contract_address)
        except AddressWrongContract:
            handle_contract_wrong_address('discovery',
                                          discovery_contract_address)

        throttle_policy = TokenBucket(
            config['transport']['udp']['throttle_capacity'],
            config['transport']['udp']['throttle_fill_rate'],
        )

        transport = UDPTransport(
            discovery,
            mapped_socket.socket,
            throttle_policy,
            config['transport']['udp'],
        )
    elif transport == 'matrix':
        try:
            transport = MatrixTransport(config['transport']['matrix'])
        except RaidenError as ex:
            click.secho(f'FATAL: {ex}', fg='red')
            sys.exit(1)
    else:
        raise RuntimeError(f'Unknown transport type "{transport}" given')

    try:
        chain_config = constants.ID_TO_NETWORK_CONFIG.get(net_id, {})
        start_block = chain_config.get(constants.START_QUERY_BLOCK_KEY, 0)
        raiden_app = App(
            config=config,
            chain=blockchain_service,
            query_start_block=start_block,
            default_registry=token_network_registry,
            default_secret_registry=secret_registry,
            transport=transport,
            discovery=discovery,
        )
    except RaidenError as e:
        click.secho(f'FATAL: {e}', fg='red')
        sys.exit(1)

    try:
        raiden_app.start()
    except filelock.Timeout:
        name_or_id = constants.ID_TO_NETWORKNAME.get(network_id, network_id)
        print(
            f'FATAL: Another Raiden instance already running for account {address_hex} on '
            f'network id {name_or_id}', )
        sys.exit(1)

    return raiden_app
예제 #14
0
파일: client.py 프로젝트: wx7063/raiden
    def __init__(
        self,
        web3: Web3,
        privkey: bytes,
        gas_price_strategy: typing.Callable = rpc_gas_price_strategy,
        block_num_confirmations: int = 0,
        uses_infura=False,
    ):
        if privkey is None or len(privkey) != 32:
            raise ValueError('Invalid private key')

        if block_num_confirmations < 0:
            raise ValueError('Number of confirmations has to be positive', )

        monkey_patch_web3(web3, gas_price_strategy)

        try:
            version = web3.version.node
        except ConnectTimeout:
            raise EthNodeCommunicationError('couldnt reach the ethereum node')

        _, eth_node = is_supported_client(version)

        address = privatekey_to_address(privkey)
        address_checksumed = to_checksum_address(address)

        if uses_infura:
            warnings.warn(
                'Infura does not provide an API to '
                'recover the latest used nonce. This may cause the Raiden node '
                'to error on restarts.\n'
                'The error will manifest while there is a pending transaction '
                'from a previous execution in the Ethereum\'s client pool. When '
                'Raiden restarts the same transaction with the same nonce will '
                'be retried and *rejected*, because the nonce is already used.',
            )
            # The first valid nonce is 0, therefore the count is already the next
            # available nonce
            available_nonce = web3.eth.getTransactionCount(
                address_checksumed, 'pending')

        elif eth_node == constants.EthClient.PARITY:
            parity_assert_rpc_interfaces(web3)
            available_nonce = parity_discover_next_available_nonce(
                web3,
                address_checksumed,
            )

        elif eth_node == constants.EthClient.GETH:
            geth_assert_rpc_interfaces(web3)
            available_nonce = geth_discover_next_available_nonce(
                web3,
                address_checksumed,
            )

        else:
            raise EthNodeInterfaceError(
                f'Unsupported Ethereum client {version}')

        self.eth_node = eth_node
        self.privkey = privkey
        self.address = address
        self.web3 = web3
        self.default_block_num_confirmations = block_num_confirmations

        self._available_nonce = available_nonce
        self._nonce_lock = Semaphore()

        log.debug(
            'JSONRPCClient created',
            node=pex(self.address),
            available_nonce=available_nonce,
            client=version,
        )
예제 #15
0
def test_check_json_rpc_parity():
    g1, client = is_supported_client(
        'Parity//v1.7.6-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    g2, _ = is_supported_client(
        'Parity//v1.7.7-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    g3, _ = is_supported_client(
        'Parity//v1.8.7-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    g4, _ = is_supported_client(
        'Parity//v2.9.7-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    g5, _ = is_supported_client(
        'Parity//v23.94.75-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    g6, _ = is_supported_client(
        'Parity//v99.994.975-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    assert client == EthClient.PARITY
    assert all([g1, g2, g3, g4, g5, g6])

    b1, client = is_supported_client(
        'Parity//v1.7.5-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    b2, _ = is_supported_client(
        'Parity//v1.5.1-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    b3, _ = is_supported_client(
        'Parity//v0.7.1-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    b4, _ = is_supported_client(
        'Parity//v0.8.7-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    b5, _ = is_supported_client(
        'Parity//v0.0.0-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    assert not client
    assert not any([b1, b2, b3, b4, b5])
예제 #16
0
def test_check_json_rpc_parity():
    assert is_supported_client(
        'Parity//v1.7.6-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    assert is_supported_client(
        'Parity//v1.7.7-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    assert is_supported_client(
        'Parity//v1.8.7-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    assert is_supported_client(
        'Parity//v2.9.7-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    assert is_supported_client(
        'Parity//v23.94.75-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    assert is_supported_client(
        'Parity//v99.994.975-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )

    assert not is_supported_client(
        'Parity//v1.7.5-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    assert not is_supported_client(
        'Parity//v1.5.1-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    assert not is_supported_client(
        'Parity//v0.7.1-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    assert not is_supported_client(
        'Parity//v0.8.7-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
    assert not is_supported_client(
        'Parity//v0.0.0-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0',
    )
예제 #17
0
    def __init__(
            self,
            web3: Web3,
            privkey: bytes,
            gas_price_strategy: Callable = rpc_gas_price_strategy,
            block_num_confirmations: int = 0,
            uses_infura=False,
    ):
        if privkey is None or len(privkey) != 32:
            raise ValueError('Invalid private key')

        if block_num_confirmations < 0:
            raise ValueError(
                'Number of confirmations has to be positive',
            )

        monkey_patch_web3(web3, gas_price_strategy)

        try:
            version = web3.version.node
        except ConnectTimeout:
            raise EthNodeCommunicationError('couldnt reach the ethereum node')

        _, eth_node = is_supported_client(version)

        address = privatekey_to_address(privkey)
        address_checksumed = to_checksum_address(address)

        if uses_infura:
            warnings.warn(
                'Infura does not provide an API to '
                'recover the latest used nonce. This may cause the Raiden node '
                'to error on restarts.\n'
                'The error will manifest while there is a pending transaction '
                'from a previous execution in the Ethereum\'s client pool. When '
                'Raiden restarts the same transaction with the same nonce will '
                'be retried and *rejected*, because the nonce is already used.',
            )
            # The first valid nonce is 0, therefore the count is already the next
            # available nonce
            available_nonce = web3.eth.getTransactionCount(address_checksumed, 'pending')

        elif eth_node == constants.EthClient.PARITY:
            parity_assert_rpc_interfaces(web3)
            available_nonce = parity_discover_next_available_nonce(
                web3,
                address_checksumed,
            )

        elif eth_node == constants.EthClient.GETH:
            geth_assert_rpc_interfaces(web3)
            available_nonce = geth_discover_next_available_nonce(
                web3,
                address_checksumed,
            )

        else:
            raise EthNodeInterfaceError(f'Unsupported Ethereum client {version}')

        self.eth_node = eth_node
        self.privkey = privkey
        self.address = address
        self.web3 = web3
        self.default_block_num_confirmations = block_num_confirmations

        self._available_nonce = available_nonce
        self._nonce_lock = Semaphore()

        log.debug(
            'JSONRPCClient created',
            node=pex(self.address),
            available_nonce=available_nonce,
            client=version,
        )