Added API call GET /blocks/timestamp/{timestamp} and increase timeout on POST /admin/forcesync from 5s to 30s

This commit is contained in:
catbref 2019-06-24 10:33:25 +01:00
parent 2621e04025
commit 840f52ff90
2 changed files with 37 additions and 1 deletions

View File

@ -447,7 +447,7 @@ public class AdminResource {
// Try to grab blockchain lock
ReentrantLock blockchainLock = Controller.getInstance().getBlockchainLock();
if (!blockchainLock.tryLock(5000, TimeUnit.MILLISECONDS))
if (!blockchainLock.tryLock(30000, TimeUnit.MILLISECONDS))
return SynchronizationResult.NO_BLOCKCHAIN_LOCK.name();
SynchronizationResult syncResult;

View File

@ -479,6 +479,42 @@ public class BlocksResource {
}
}
@GET
@Path("/timestamp/{timestamp}")
@Operation(
summary = "Fetch nearest block before given timestamp",
responses = {
@ApiResponse(
description = "the block",
content = @Content(
schema = @Schema(
implementation = BlockData.class
)
)
)
}
)
@ApiErrors({
ApiError.BLOCK_NO_EXISTS, ApiError.REPOSITORY_ISSUE
})
public BlockData getByTimestamp(@PathParam("timestamp") long timestamp) {
try (final Repository repository = RepositoryManager.getRepository()) {
int height = repository.getBlockRepository().getHeightFromTimestamp(timestamp);
if (height == 0)
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.BLOCK_NO_EXISTS);
BlockData blockData = repository.getBlockRepository().fromHeight(height);
if (blockData == null)
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.BLOCK_NO_EXISTS);
return blockData;
} catch (ApiException e) {
throw e;
} catch (DataException e) {
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
}
}
@GET
@Path("/range/{height}")
@Operation(