Search in sources :

Example 1 with NetworkInfoDto

use of io.nuls.network.rpc.model.NetworkInfoDto in project nuls by nuls-io.

the class NetworkResource method getNetworkInfo.

// private NodeCacheManager nodeCacheManager = NodeCacheManager.getInstance();
@GET
@Path("/info/")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "查询网络最新信息")
@ApiResponses(value = { @ApiResponse(code = 200, message = "success", response = NetworkInfoDto.class) })
public RpcClientResult getNetworkInfo() {
    NetworkInfoDto info = new NetworkInfoDto(NulsContext.getInstance().getBestBlock().getHeader().getHeight(), NulsContext.getInstance().getNetBestBlockHeight(), TimeService.getNetTimeOffset());
    Collection<Node> collections = networkService.getAvailableNodes();
    int inCount = 0;
    int outCount = 0;
    for (Node node : collections) {
        if (node.getType() == Node.IN) {
            inCount++;
        } else {
            outCount++;
        }
    }
    info.setInCount(inCount);
    info.setOutCount(outCount);
    info.setMastUpGrade(NulsContext.mastUpGrade);
    Result result = Result.getSuccess();
    result.setData(info);
    return result.toRpcClientResult();
}
Also used : Node(io.nuls.network.model.Node) NetworkInfoDto(io.nuls.network.rpc.model.NetworkInfoDto) RpcClientResult(io.nuls.kernel.model.RpcClientResult) Result(io.nuls.kernel.model.Result) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Result (io.nuls.kernel.model.Result)1 RpcClientResult (io.nuls.kernel.model.RpcClientResult)1 Node (io.nuls.network.model.Node)1 NetworkInfoDto (io.nuls.network.rpc.model.NetworkInfoDto)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1