forked from Qortal/qortal
Added API call GET /blocks/timestamp/{timestamp} and increase timeout on POST /admin/forcesync from 5s to 30s
This commit is contained in:
parent
2621e04025
commit
840f52ff90
@ -447,7 +447,7 @@ public class AdminResource {
|
|||||||
|
|
||||||
// Try to grab blockchain lock
|
// Try to grab blockchain lock
|
||||||
ReentrantLock blockchainLock = Controller.getInstance().getBlockchainLock();
|
ReentrantLock blockchainLock = Controller.getInstance().getBlockchainLock();
|
||||||
if (!blockchainLock.tryLock(5000, TimeUnit.MILLISECONDS))
|
if (!blockchainLock.tryLock(30000, TimeUnit.MILLISECONDS))
|
||||||
return SynchronizationResult.NO_BLOCKCHAIN_LOCK.name();
|
return SynchronizationResult.NO_BLOCKCHAIN_LOCK.name();
|
||||||
|
|
||||||
SynchronizationResult syncResult;
|
SynchronizationResult syncResult;
|
||||||
|
@ -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
|
@GET
|
||||||
@Path("/range/{height}")
|
@Path("/range/{height}")
|
||||||
@Operation(
|
@Operation(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user