예제 #1
0
def do_test_bloom(test_logs):
    """
    The logs sections is a mapping between the blooms and their corresponding logentries.
    Each logentry has the format:
    address: The address of the logentry.
    data: The data of the logentry.
    topics: The topics of the logentry, given as an array of values.
    """
    for data in test_logs:
        address = data['address']
        # Test via bloom
        b = bloom.bloom_insert(0, decode_hex(address))
        for t in data['topics']:
            b = bloom.bloom_insert(b, decode_hex(t))
        # Test via Log
        topics = [decode_int_from_hex(x) for x in data['topics']]
        log = pb.Log(decode_hex(address), topics, '')
        log_bloom = bloom.b64(bloom.bloom_from_list(log.bloomables()))
        assert encode_hex(log_bloom) == encode_hex_from_int(b)
        assert str_to_bytes(data['bloom']) == encode_hex(log_bloom)
예제 #2
0
    def _get_logs(self, topics, event_name=None):
        """
        Get logs of the events that occur.

        topics:     a list of topics to search based on
        event_name: the name of the event
        """

        # set topic to the ID if the name is specified
        if event_name == None:
            event_topic = None
        else:
            event_topic = self._get_event_id_by_name(event_name)

        # add the event type to the topics
        topics = [event_topic] + topics

        # encode topics to be sent to the eth client
        topics = [encode_api_data(topic) for topic in topics]

        # gets logs from eth client
        logs = ethclient.get_logs(
            from_block='earliest',
            address=self.address,
            topics=topics,
        )
        

        # decode logs using the ABI
        decoded_logs = []
        for log in logs:
            logobj = processblock.Log(
                log['address'][2:],
                [big_endian_to_int(decode_hex(topic[2:])) for topic in log['topics']],
                decode_hex(log['data'][2:])
            )
            decoded_log = self._contracttranslator.listen(logobj, noprint=True)
            decoded_logs.append(decoded_log)

        return decoded_logs
예제 #3
0
    def _get_logs(self, topics, event_name=None):
        """
        Get logs (events).

        topics: a list of topics to search for.
        event_name: the name of the event.
        """
        # Set the event topic to the event ID if the event name is specified.
        if event_name is None:
            event_topic = None
        else:
            event_topic = self._get_event_id_by_name(event_name)

        # Prepent the event type to the topics.
        topics = [event_topic] + topics
        # Encode topics to be sent to the Ethereum client.
        topics = [encode_api_data(topic, padding=32) for topic in topics]

        # Get logs from Ethereum client.
        logs = ethclient.get_logs(
            from_block='earliest',
            address=self.address,
            topics=topics,
        )

        # Decode logs using the contract ABI.
        decoded_logs = []
        for log in logs:
            logobj = processblock.Log(log['address'][2:], [
                big_endian_to_int(decode_hex(topic[2:]))
                for topic in log['topics']
            ], decode_hex(log['data'][2:]))
            decoded_log = self._contracttranslator.listen(logobj, noprint=True)
            decoded_logs.append(decoded_log)

        return decoded_logs