Search in sources :

Example 1 with InfoDto

use of io.nuls.rpc.entity.InfoDto in project nuls by nuls-io.

the class NetworkMessageResource method getInfo.

@GET
@Path("/info")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getInfo() {
    RpcResult result = RpcResult.getSuccess();
    InfoDto info = new InfoDto(NulsContext.getInstance().getBestBlock().getHeader().getHeight(), NulsContext.getInstance().getNetBestBlockHeight(), TimeService.getNetTimeOffset());
    NodeGroup inGroup = networkService.getNodeGroup(NetworkConstant.NETWORK_NODE_IN_GROUP);
    NodeGroup outGroup = networkService.getNodeGroup(NetworkConstant.NETWORK_NODE_OUT_GROUP);
    int count = 0;
    for (Node node : inGroup.getNodes().values()) {
        if (node.getStatus() == Node.HANDSHAKE) {
            count += 1;
        }
    }
    info.setInCount(count);
    count = 0;
    for (Node node : outGroup.getNodes().values()) {
        if (node.getStatus() == Node.HANDSHAKE) {
            count += 1;
        }
    }
    info.setOutCount(count);
    result.setData(info);
    return result;
}
Also used : Node(io.nuls.network.entity.Node) RpcResult(io.nuls.rpc.entity.RpcResult) InfoDto(io.nuls.rpc.entity.InfoDto) NodeGroup(io.nuls.network.entity.NodeGroup) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Node (io.nuls.network.entity.Node)1 NodeGroup (io.nuls.network.entity.NodeGroup)1 InfoDto (io.nuls.rpc.entity.InfoDto)1 RpcResult (io.nuls.rpc.entity.RpcResult)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1