use of io.nuls.consensus.poc.rpc.model.RandomSeedDTO in project nuls by nuls-io.
the class VMContext method getRandomSeed.
public String getRandomSeed(long startHeight, long endHeight, String algorithm) {
RpcClientResult seedByCount = randomSeedResource.getSeedByHeight(startHeight, endHeight, algorithm);
if (seedByCount.isFailed()) {
Log.error(seedByCount.toString());
return null;
}
RandomSeedDTO dto = (RandomSeedDTO) seedByCount.getData();
return dto.getSeed();
}
use of io.nuls.consensus.poc.rpc.model.RandomSeedDTO in project nuls by nuls-io.
the class RandomSeedResource method getSeedByHeight.
@GET
@Path("/seed/height")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("根据高度区间生成一个随机种子并返回")
@ApiResponses(value = { @ApiResponse(code = 200, message = "success", response = RandomSeedDTO.class) })
public RpcClientResult getSeedByHeight(@ApiParam(name = "startHeight", value = "起始高度", required = true) @QueryParam("startHeight") long startHeight, @ApiParam(name = "endHeight", value = "截止高度", required = true) @QueryParam("endHeight") long endHeight, @ApiParam(name = "algorithm", value = "算法标识:SHA3...", required = true) @QueryParam("algorithm") String algorithm) {
if (endHeight > context.getBestHeight() || startHeight <= 0 || (endHeight - startHeight) > 1000L || StringUtils.isBlank(algorithm)) {
return Result.getFailed(KernelErrorCode.PARAMETER_ERROR).toRpcClientResult();
}
List<byte[]> list = randomSeedService.getSeeds(startHeight, endHeight);
int count = list.size();
if (list.isEmpty()) {
return Result.getFailed().toRpcClientResult();
}
byte[] seed = RandomSeedCaculator.clac(list, algorithm);
if (null == seed) {
return Result.getFailed().toRpcClientResult();
}
RandomSeedDTO dto = new RandomSeedDTO();
dto.setCount(count);
dto.setAlgorithm(algorithm);
BigInteger value = new BigInteger(seed);
dto.setSeed(value.toString());
return Result.getSuccess().setData(dto).toRpcClientResult();
}
use of io.nuls.consensus.poc.rpc.model.RandomSeedDTO in project nuls by nuls-io.
the class RandomSeedResource method getSeedByCount.
@GET
@Path("/seed/count")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("根据高度和原始种子个数生成一个随机种子并返回")
@ApiResponses(value = { @ApiResponse(code = 200, message = "success", response = RandomSeedDTO.class) })
public RpcClientResult getSeedByCount(@ApiParam(name = "height", value = "最大高度", required = true) @QueryParam("height") long height, @ApiParam(name = "count", value = "原始种子个数", required = true) @QueryParam("count") int count, @ApiParam(name = "algorithm", value = "算法标识:SHA3...", required = true) @QueryParam("algorithm") String algorithm) {
if (height > context.getBestHeight() || count > 128 || count <= 0 || StringUtils.isBlank(algorithm)) {
return Result.getFailed(KernelErrorCode.PARAMETER_ERROR).toRpcClientResult();
}
List<byte[]> list = randomSeedService.getSeeds(height, count);
if (list.size() != count) {
return Result.getFailed().toRpcClientResult();
}
byte[] seed = RandomSeedCaculator.clac(list, algorithm);
if (null == seed) {
return Result.getFailed().toRpcClientResult();
}
RandomSeedDTO dto = new RandomSeedDTO();
dto.setCount(count);
dto.setAlgorithm(algorithm);
BigInteger value = new BigInteger(seed);
dto.setSeed(value.toString());
return Result.getSuccess().setData(dto).toRpcClientResult();
}
use of io.nuls.consensus.poc.rpc.model.RandomSeedDTO in project nuls by nuls-io.
the class VMContext method getRandomSeed.
public String getRandomSeed(long endHeight, int count, String algorithm) {
RpcClientResult seedByCount = randomSeedResource.getSeedByCount(endHeight, count, algorithm);
if (seedByCount.isFailed()) {
Log.error(seedByCount.toString());
return null;
}
RandomSeedDTO dto = (RandomSeedDTO) seedByCount.getData();
return dto.getSeed();
}
Aggregations