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:
parent
9d81ea7744
commit
64529e8abf
@ -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;
|
||||||
|
@ -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));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user