Exemplo n.º 1
0
    def get_token_network_events(
        self,
        token_address: typing.TokenAddress,
        from_block: typing.BlockSpecification = 0,
        to_block: typing.BlockSpecification = 'latest',
    ):
        if not is_binary_address(token_address):
            raise InvalidAddress(
                'Expected binary address format for token in get_token_network_events',
            )
        token_network_address = self.raiden.default_registry.get_token_network(
            token_address, )
        if token_network_address is None:
            raise UnknownTokenAddress('Token address is not known.')

        returned_events = get_token_network_events(
            self.raiden.chain,
            token_network_address,
            events=ALL_EVENTS,
            from_block=from_block,
            to_block=to_block,
        )

        for event in returned_events:
            if event.get('args'):
                event['args'] = dict(event['args'])

                # the channel_identifier is a hash
                encode_byte_values(event['args'])

            hexbytes_to_str(event)

        raiden_events = self.raiden.wal.storage.get_events_by_block(
            from_block=from_block,
            to_block=to_block,
        )

        # Here choose which raiden internal events we want to expose to the end user
        for block_number, event in raiden_events:
            if isinstance(event, EVENTS_PAYMENT_HISTORY_RELATED):
                new_event = {
                    'block_number': block_number,
                    'event': type(event).__name__,
                }
                new_event.update(event.__dict__)
                returned_events.append(new_event)

        returned_events.sort(key=lambda evt: evt.get('block_number'),
                             reverse=True)
        return returned_events
Exemplo n.º 2
0
    def get_token_network_events(self, token_address, from_block, to_block='latest'):

        if not is_binary_address(token_address):
            raise InvalidAddress(
                'Expected binary address format for token in get_token_network_events',
            )
        token_network_address = self.raiden.default_registry.get_token_network(
            token_address,
        )
        if token_network_address is None:
            raise UnknownTokenAddress('Token address is not known.')

        returned_events = get_token_network_events(
            self.raiden.chain,
            token_network_address,
            events=ALL_EVENTS,
            from_block=from_block,
            to_block=to_block,
        )

        for event in returned_events:
            if event.get('args'):
                event['args'] = dict(event['args'])

                # the channel_identifier is a hash
                encode_byte_values(event['args'])

            hexbytes_to_str(event)

        raiden_events = self.raiden.wal.storage.get_events_by_block(
            from_block=from_block,
            to_block=to_block,
        )

        # Here choose which raiden internal events we want to expose to the end user
        for block_number, event in raiden_events:
            if isinstance(event, EVENTS_EXTERNALLY_VISIBLE):
                new_event = {
                    'block_number': block_number,
                    'event': type(event).__name__,
                }
                new_event.update(event.__dict__)
                returned_events.append(new_event)

        returned_events.sort(key=lambda evt: evt.get('block_number'), reverse=True)
        return returned_events