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({ @ApiErrors({
ApiError.REPOSITORY_ISSUE ApiError.REPOSITORY_ISSUE
}) })
public List<BlockData> getBlockRange(@PathParam("height") int height, @Parameter( public List<BlockData> getBlockRange(@PathParam("height") int height,
ref = "count" @Parameter(ref = "count") @QueryParam("count") int count,
) @QueryParam("count") int count) { @Parameter(ref = "reverse") @QueryParam("reverse") Boolean reverse,
@QueryParam("includeOnlineSignatures") Boolean includeOnlineSignatures) {
try (final Repository repository = RepositoryManager.getRepository()) { try (final Repository repository = RepositoryManager.getRepository()) {
List<BlockData> blocks = new ArrayList<>(); 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); BlockData blockData = repository.getBlockRepository().fromHeight(height);
if (blockData == null) { if (blockData == null) {
// Not found - try the archive // Not found - try the archive
@ -650,8 +653,14 @@ public class BlocksResource {
break; break;
} }
} }
if (includeOnlineSignatures == null || includeOnlineSignatures == false) {
blockData.setOnlineAccountsSignatures(null);
}
blocks.add(blockData); blocks.add(blockData);
height = shouldReverse ? height - 1 : height + 1;
i++;
} }
return blocks; return blocks;

View File

@ -84,7 +84,7 @@ public class BlockApiTests extends ApiCommon {
@Test @Test
public void testGetBlockRange() { 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)); List<Integer> testValues = Arrays.asList(null, Integer.valueOf(1));