Exemple #1
0
def _sanitize_limit_and_offset(limit: int = None,
                               offset: int = None) -> Tuple[int, int]:
    if limit is not None and (not isinstance(limit, int) or limit < 0):
        raise InvalidNumberInput("limit must be a positive integer")

    if offset is not None and (not isinstance(offset, int) or offset < 0):
        raise InvalidNumberInput("offset must be a positive integer")

    limit = -1 if limit is None else limit
    offset = 0 if offset is None else offset
    return limit, offset
Exemple #2
0
def _sanitize_limit_and_offset(
        limit: Optional[int] = None,
        offset: Optional[int] = None) -> Tuple[int, int]:
    if limit is not None and limit < 0:  # pragma: no unittest
        raise InvalidNumberInput("limit must be a positive integer")

    if offset is not None and offset < 0:  # pragma: no unittest
        raise InvalidNumberInput("offset must be a positive integer")

    limit = -1 if limit is None else limit
    offset = 0 if offset is None else offset
    return limit, offset
Exemple #3
0
    def _get_table_data(self, limit: int = None):

        if limit is not None and (not isinstance(limit, int) or limit < 0):
            raise InvalidNumberInput('limit must be a positive integer')

        limit = -1 if limit is None else limit

        base_query = '''

            SELECT
                log_time, 
                data
            FROM
                state_events
            WHERE
                json_extract(state_events.data,
                '$._type') IN ({})	
            LIMIT ?	

        '''

        payments_received = self._get_payments_event(base_query, limit, 1)
        payments_sent = self._get_payments_event(base_query, limit, 3)

        result = {
            "payments_received": payments_received,
            "payments_sent": payments_sent
        }

        return result
Exemple #4
0
    def _query_payments_events(self,
                               token_network_identifier,
                               our_address,
                               initiator_address,
                               target_address,
                               from_date,
                               to_date,
                               event_type: int = None,
                               limit: int = None,
                               offset: int = None):

        if limit is not None and (not isinstance(limit, int) or limit < 0):
            raise InvalidNumberInput('limit must be a positive integer')

        if offset is not None and (not isinstance(offset, int) or offset < 0):
            raise InvalidNumberInput('offset must be a positive integer')

        limit = -1 if limit is None else limit
        offset = 0 if offset is None else offset

        query = self._get_query_with_values(token_network_identifier,
                                            our_address,
                                            initiator_address,
                                            target_address,
                                            event_type,
                                            from_date,
                                            to_date,
                                            limit,
                                            offset)

        cursor = self.conn.cursor()

        print(query[0])
        print(query[1])

        cursor.execute(
            query[0],
            query[1],
        )

        return cursor.fetchall()
Exemple #5
0
    def _query_events(self, limit: int = None, offset: int = None):
        if limit is not None and (not isinstance(limit, int) or limit < 0):
            raise InvalidNumberInput('limit must be a positive integer')

        if offset is not None and (not isinstance(offset, int) or offset < 0):
            raise InvalidNumberInput('offset must be a positive integer')

        limit = -1 if limit is None else limit
        offset = 0 if offset is None else offset

        cursor = self.conn.cursor()

        cursor.execute(
            '''
            SELECT data, log_time FROM state_events
                ORDER BY identifier ASC LIMIT ? OFFSET ?
            ''',
            (limit, offset),
        )

        return cursor.fetchall()