Search in sources :

Example 1 with RandomSeedDTO

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();
}
Also used : RpcClientResult(io.nuls.kernel.model.RpcClientResult) RandomSeedDTO(io.nuls.consensus.poc.rpc.model.RandomSeedDTO)

Example 2 with RandomSeedDTO

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();
}
Also used : BigInteger(java.math.BigInteger) RandomSeedDTO(io.nuls.consensus.poc.rpc.model.RandomSeedDTO) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with RandomSeedDTO

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();
}
Also used : BigInteger(java.math.BigInteger) RandomSeedDTO(io.nuls.consensus.poc.rpc.model.RandomSeedDTO) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with RandomSeedDTO

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();
}
Also used : RpcClientResult(io.nuls.kernel.model.RpcClientResult) RandomSeedDTO(io.nuls.consensus.poc.rpc.model.RandomSeedDTO)

Aggregations

RandomSeedDTO (io.nuls.consensus.poc.rpc.model.RandomSeedDTO)4 RpcClientResult (io.nuls.kernel.model.RpcClientResult)2 BigInteger (java.math.BigInteger)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2