forked from Qortal/qortal
Improvements to some /blocks API endpoints
This commit is contained in:
parent
ef43e78d54
commit
d105613e51
@ -268,9 +268,15 @@ public class BlocksResource {
|
|||||||
@ApiErrors({
|
@ApiErrors({
|
||||||
ApiError.REPOSITORY_ISSUE
|
ApiError.REPOSITORY_ISSUE
|
||||||
})
|
})
|
||||||
public BlockData getLastBlock() {
|
public BlockData getLastBlock(@QueryParam("includeOnlineSignatures") Boolean includeOnlineSignatures) {
|
||||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||||
return repository.getBlockRepository().getLastBlock();
|
BlockData blockData = repository.getBlockRepository().getLastBlock();
|
||||||
|
|
||||||
|
if (includeOnlineSignatures == null || includeOnlineSignatures == false) {
|
||||||
|
blockData.setOnlineAccountsSignatures(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return blockData;
|
||||||
} catch (DataException e) {
|
} catch (DataException e) {
|
||||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
||||||
}
|
}
|
||||||
@ -548,20 +554,25 @@ public class BlocksResource {
|
|||||||
@ApiErrors({
|
@ApiErrors({
|
||||||
ApiError.BLOCK_UNKNOWN, ApiError.REPOSITORY_ISSUE
|
ApiError.BLOCK_UNKNOWN, ApiError.REPOSITORY_ISSUE
|
||||||
})
|
})
|
||||||
public BlockData getByTimestamp(@PathParam("timestamp") long timestamp) {
|
public BlockData getByTimestamp(@PathParam("timestamp") long timestamp,
|
||||||
|
@QueryParam("includeOnlineSignatures") Boolean includeOnlineSignatures) {
|
||||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||||
BlockData blockData = null;
|
BlockData blockData = null;
|
||||||
|
|
||||||
// Try the Blocks table
|
// Try the Blocks table
|
||||||
int height = repository.getBlockRepository().getHeightFromTimestamp(timestamp);
|
int height = repository.getBlockRepository().getHeightFromTimestamp(timestamp);
|
||||||
if (height > 0) {
|
if (height > 1) {
|
||||||
// Found match in Blocks table
|
// Found match in Blocks table
|
||||||
return repository.getBlockRepository().fromHeight(height);
|
blockData = repository.getBlockRepository().fromHeight(height);
|
||||||
|
if (includeOnlineSignatures == null || includeOnlineSignatures == false) {
|
||||||
|
blockData.setOnlineAccountsSignatures(null);
|
||||||
|
}
|
||||||
|
return blockData;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not found in Blocks table, so try the archive
|
// Not found in Blocks table, so try the archive
|
||||||
height = repository.getBlockArchiveRepository().getHeightFromTimestamp(timestamp);
|
height = repository.getBlockArchiveRepository().getHeightFromTimestamp(timestamp);
|
||||||
if (height > 0) {
|
if (height > 1) {
|
||||||
// Found match in archive
|
// Found match in archive
|
||||||
blockData = repository.getBlockArchiveRepository().fromHeight(height);
|
blockData = repository.getBlockArchiveRepository().fromHeight(height);
|
||||||
}
|
}
|
||||||
@ -571,6 +582,10 @@ public class BlocksResource {
|
|||||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.BLOCK_UNKNOWN);
|
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.BLOCK_UNKNOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (includeOnlineSignatures == null || includeOnlineSignatures == false) {
|
||||||
|
blockData.setOnlineAccountsSignatures(null);
|
||||||
|
}
|
||||||
|
|
||||||
return blockData;
|
return blockData;
|
||||||
} catch (DataException e) {
|
} catch (DataException e) {
|
||||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
||||||
|
@ -77,7 +77,7 @@ public class BlockApiTests extends ApiCommon {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetBlockByTimestamp() {
|
public void testGetBlockByTimestamp() {
|
||||||
assertNotNull(this.blocksResource.getByTimestamp(System.currentTimeMillis()));
|
assertNotNull(this.blocksResource.getByTimestamp(System.currentTimeMillis(), false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user