3
0
mirror of https://github.com/Qortal/qortal.git synced 2025-02-12 02:05:50 +00:00

Added "reverse" and "includeOnlineSignatures" params to GET /blocks/range/{height} endpoint.

This commit is contained in:
CalDescent 2023-01-18 19:04:54 +00:00
parent 9d81ea7744
commit 64529e8abf
2 changed files with 14 additions and 5 deletions

View File

@ -634,13 +634,16 @@ public class BlocksResource {
@ApiErrors({
ApiError.REPOSITORY_ISSUE
})
public List<BlockData> getBlockRange(@PathParam("height") int height, @Parameter(
ref = "count"
) @QueryParam("count") int count) {
public List<BlockData> getBlockRange(@PathParam("height") int height,
@Parameter(ref = "count") @QueryParam("count") int count,
@Parameter(ref = "reverse") @QueryParam("reverse") Boolean reverse,
@QueryParam("includeOnlineSignatures") Boolean includeOnlineSignatures) {
try (final Repository repository = RepositoryManager.getRepository()) {
List<BlockData> blocks = new ArrayList<>();
boolean shouldReverse = (reverse != null && reverse == true);
for (/* count already set */; count > 0; --count, ++height) {
int i = 0;
while (i < count) {
BlockData blockData = repository.getBlockRepository().fromHeight(height);
if (blockData == null) {
// Not found - try the archive
@ -650,8 +653,14 @@ public class BlocksResource {
break;
}
}
if (includeOnlineSignatures == null || includeOnlineSignatures == false) {
blockData.setOnlineAccountsSignatures(null);
}
blocks.add(blockData);
height = shouldReverse ? height - 1 : height + 1;
i++;
}
return blocks;

View File

@ -84,7 +84,7 @@ public class BlockApiTests extends ApiCommon {
@Test
public void testGetBlockRange() {
assertNotNull(this.blocksResource.getBlockRange(1, 1));
assertNotNull(this.blocksResource.getBlockRange(1, 1, false, false));
List<Integer> testValues = Arrays.asList(null, Integer.valueOf(1));