Browse Source

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

pull/67/head
catbref 5 years ago
parent
commit
840f52ff90
  1. 2
      src/main/java/org/qora/api/resource/AdminResource.java
  2. 36
      src/main/java/org/qora/api/resource/BlocksResource.java

2
src/main/java/org/qora/api/resource/AdminResource.java

@ -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;

36
src/main/java/org/qora/api/resource/BlocksResource.java

@ -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(

Loading…
Cancel
Save