teloscan icon indicating copy to clipboard operation
teloscan copied to clipboard

Add rages check on export page

Open Viterbo opened this issue 11 months ago • 0 comments

Overview

Add the four range checks that the indexer performs for the export endpoint and prevent the user from exporting if they are not met.

Fixed here: https://github.com/telosnetwork/teloscan/pull/1001

Indexer checks are here: https://github.com/telosnetwork/teloscan-indexer/blob/master/src/main/java/net/telos/indexer/api/resource/ExportResource.java#L57-L78

protected void validateRanges(Long blockStart, Long blockEnd, Long timestampStart, Long timestampEnd) throws BadRequestException {
    boolean hasCompleteBlockRange = isCompleteRange(blockStart, blockEnd);
    boolean hasCompleteTimestampRange = isCompleteRange(timestampStart, timestampEnd);
    boolean hasPartialBlockRange = isPartialRange(blockStart, blockEnd);
    boolean hasPartialTimestampRange = isPartialRange(timestampStart, timestampEnd);

    if (!hasCompleteBlockRange && !hasCompleteTimestampRange) {
        throw new BadRequestException("Need either a complete block range or a complete timestamp range to export transactions.");
    }

    if (hasPartialBlockRange && hasPartialTimestampRange) {
        throw new BadRequestException("Cannot have both block and timestamp ranges.");
    }

    if (hasCompleteBlockRange && blockEnd - blockStart > ONE_YEAR_BLOCKS) {
        throw new BadRequestException("Block range must be less than " + ONE_YEAR_BLOCKS + " blocks.");
    }

    if (hasCompleteTimestampRange && timestampEnd - timestampStart > ONE_YEAR_MS) {
        throw new BadRequestException("Timestamp range must be less than one year.");
    }
}

Viterbo avatar Feb 07 '25 15:02 Viterbo