Ejemplo n.º 1
0
    def new_filter(self,
                   fromBlock=None,
                   toBlock=None,
                   address=None,
                   topics=None):
        """ Creates a filter object, based on filter options, to notify when
        the state changes (logs). To check if the state has changed, call
        eth_getFilterChanges.
        """

        json_data = {
            'fromBlock': block_tag_encoder(fromBlock or ''),
            'toBlock': block_tag_encoder(toBlock or ''),
        }

        if address is not None:
            json_data['address'] = address_encoder(address)

        if topics is not None:
            if not isinstance(topics, list):
                raise ValueError('topics must be a list')

            json_data['topics'] = [topic_encoder(topic) for topic in topics]

        filter_id = self.call('eth_newFilter', json_data)
        return quantity_decoder(filter_id)
Ejemplo n.º 2
0
def new_filter(
        jsonrpc_client: JSONRPCClient,
        contract_address: address,
        topics: Optional[List[int]],
        from_block: Union[str, int] = 0,
        to_block: Union[str, int] = 'latest'):
    """ Custom new filter implementation to handle bad encoding from geth rpc. """
    if isinstance(from_block, int):
        from_block = hex(from_block)

    if isinstance(to_block, int):
        to_block = hex(to_block)

    json_data = {
        'fromBlock': from_block,
        'toBlock': to_block,
        'address': address_encoder(normalize_address(contract_address)),
    }

    if topics is not None:
        json_data['topics'] = [
            topic_encoder(topic)
            for topic in topics
        ]

    return jsonrpc_client.call('eth_newFilter', json_data)
Ejemplo n.º 3
0
def get_filter_events(
        jsonrpc_client: JSONRPCClient,
        contract_address: address,
        topics: Optional[List[int]],
        from_block: Union[str, int] = 0,
        to_block: Union[str, int] = 'latest') -> List[Dict]:
    """ Get filter.

    This handles bad encoding from geth rpc.
    """
    if isinstance(from_block, int):
        from_block = hex(from_block)

    if isinstance(to_block, int):
        to_block = hex(to_block)

    json_data = {
        'fromBlock': from_block,
        'toBlock': to_block,
        'address': address_encoder(normalize_address(contract_address)),
    }

    if topics is not None:
        json_data['topics'] = [
            topic_encoder(topic)
            for topic in topics
        ]

    filter_changes = jsonrpc_client.call('eth_getLogs', json_data)

    # geth could return None
    if filter_changes is None:
        return []

    result = []
    for log_event in filter_changes:
        address = address_decoder(log_event['address'])
        data = data_decoder(log_event['data'])
        topics = [
            topic_decoder(topic)
            for topic in log_event['topics']
        ]
        block_number = log_event.get('blockNumber')
        if not block_number:
            block_number = 0
        else:
            block_number = int(block_number, 0)

        result.append({
            'topics': topics,
            'data': data,
            'address': address,
            'block_number': block_number,
        })

    return result
Ejemplo n.º 4
0
def get_filter_events(jsonrpc_client, contract_address, topics, from_block=None, to_block=None):
    """ Get filter.

    This handles bad encoding from geth rpc.
    """
    if isinstance(from_block, int):
        from_block = hex(from_block)

    if isinstance(to_block, int):
        to_block = hex(to_block)

    json_data = {
        'fromBlock': from_block or hex(0),
        'toBlock': to_block or 'latest',
        'address': address_encoder(normalize_address(contract_address)),
    }

    if topics is not None:
        json_data['topics'] = [
            topic_encoder(topic)
            for topic in topics
        ]

    filter_changes = jsonrpc_client.call('eth_getLogs', json_data)

    # geth could return None
    if filter_changes is None:
        return []

    result = []
    for log_event in filter_changes:
        address = address_decoder(log_event['address'])
        data = data_decoder(log_event['data'])
        topics = [
            topic_decoder(topic)
            for topic in log_event['topics']
        ]
        block_number = log_event.get('blockNumber')
        if not block_number:
            block_number = 0
        else:
            block_number = int(block_number, 0)

        result.append({
            'topics': topics,
            'data': data,
            'address': address,
            'block_number': block_number,
        })

    return result
Ejemplo n.º 5
0
def get_filter_events(jsonrpc_client: JSONRPCClient,
                      contract_address: Address,
                      topics: Optional[List[int]],
                      from_block: Union[str, int] = 0,
                      to_block: Union[str, int] = 'latest') -> List[Dict]:
    """ Get filter.

    This handles bad encoding from geth rpc.
    """
    if isinstance(from_block, int):
        from_block = hex(from_block)

    if isinstance(to_block, int):
        to_block = hex(to_block)

    json_data = {
        'fromBlock': from_block,
        'toBlock': to_block,
        'address': address_encoder(to_canonical_address(contract_address)),
    }

    if topics is not None:
        json_data['topics'] = [topic_encoder(topic) for topic in topics]

    filter_changes = jsonrpc_client.rpccall_with_retry('eth_getLogs',
                                                       json_data)

    # geth could return None
    if filter_changes is None:
        return []

    result = []
    for log_event in filter_changes:
        address = address_decoder(log_event['address'])
        data = data_decoder(log_event['data'])
        topics = [topic_decoder(topic) for topic in log_event['topics']]
        block_number = log_event.get('blockNumber')
        if not block_number:
            block_number = 0
        else:
            block_number = int(block_number, 0)

        result.append({
            'topics': topics,
            'data': data,
            'address': address,
            'block_number': block_number,
        })

    return result
Ejemplo n.º 6
0
def new_filter(jsonrpc_client: JSONRPCClient,
               contract_address: Address,
               topics: Optional[List[int]],
               from_block: Union[str, int] = 0,
               to_block: Union[str, int] = 'latest'):
    """ Custom new filter implementation to handle bad encoding from geth rpc. """
    json_data = {
        'fromBlock': from_block,
        'toBlock': to_block,
        'address': address_encoder(to_canonical_address(contract_address)),
    }

    if topics is not None:
        json_data['topics'] = [topic_encoder(topic) for topic in topics]

    new_filter = jsonrpc_client.web3.eth.filter(json_data)
    return new_filter.filter_id
Ejemplo n.º 7
0
def get_filter_events(jsonrpc_client: JSONRPCClient,
                      contract_address: Address,
                      topics: Optional[List[int]],
                      from_block: Union[str, int] = 0,
                      to_block: Union[str, int] = 'latest') -> List[Dict]:
    """ Get filter.

    This handles bad encoding from geth rpc.
    """
    json_data = {
        'fromBlock': from_block,
        'toBlock': to_block,
        'address': address_encoder(to_canonical_address(contract_address)),
    }

    if topics is not None:
        json_data['topics'] = [topic_encoder(topic) for topic in topics]

    filter_changes = jsonrpc_client.web3.eth.getLogs(json_data)

    # geth could return None
    if filter_changes is None:
        return []

    result = []
    for log_event in filter_changes:
        address = address_decoder(log_event['address'])
        data = data_decoder(log_event['data'])
        topics = [
            topic_decoder(add_0x_prefix(encode_hex(topic)))
            for topic in log_event['topics']
        ]
        block_number = log_event.get('blockNumber', 0)

        result.append({
            'topics': topics,
            'data': data,
            'address': address,
            'block_number': block_number,
            'event_data': log_event
        })

    return result
Ejemplo n.º 8
0
def new_filter(jsonrpc_client, contract_address, topics, from_block=None, to_block=None):
    """ Custom new filter implementation to handle bad encoding from geth rpc. """
    if isinstance(from_block, int):
        from_block = hex(from_block)

    if isinstance(to_block, int):
        to_block = hex(to_block)

    json_data = {
        'fromBlock': from_block or hex(0),
        'toBlock': to_block or 'latest',
        'address': address_encoder(normalize_address(contract_address)),
    }

    if topics is not None:
        json_data['topics'] = [
            topic_encoder(topic)
            for topic in topics
        ]

    return jsonrpc_client.call('eth_newFilter', json_data)
Ejemplo n.º 9
0
def new_filter(jsonrpc_client: JSONRPCClient,
               contract_address: address,
               topics: Optional[List[int]],
               from_block: Union[str, int] = 0,
               to_block: Union[str, int] = 'latest'):
    """ Custom new filter implementation to handle bad encoding from geth rpc. """
    if isinstance(from_block, int):
        from_block = hex(from_block)

    if isinstance(to_block, int):
        to_block = hex(to_block)

    json_data = {
        'fromBlock': from_block,
        'toBlock': to_block,
        'address': address_encoder(normalize_address(contract_address)),
    }

    if topics is not None:
        json_data['topics'] = [topic_encoder(topic) for topic in topics]

    return jsonrpc_client.call('eth_newFilter', json_data)
Ejemplo n.º 10
0
    def new_filter(self, fromBlock=None, toBlock=None, address=None, topics=None):
        """ Creates a filter object, based on filter options, to notify when
        the state changes (logs). To check if the state has changed, call
        eth_getFilterChanges.
        """

        json_data = {
            'fromBlock': block_tag_encoder(fromBlock or ''),
            'toBlock': block_tag_encoder(toBlock or ''),
        }

        if address is not None:
            json_data['address'] = address_encoder(address)

        if topics is not None:
            if not isinstance(topics, list):
                raise ValueError('topics must be a list')

            json_data['topics'] = [topic_encoder(topic) for topic in topics]

        filter_id = self.call('eth_newFilter', json_data)
        return quantity_decoder(filter_id)