forked from Qortal/qortal
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({
|
||||
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;
|
||||
|
@ -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));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user