Search in sources :

Example 11 with RpcResult

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

the class PocConsensusResource method getAgentListByDepositAddress.

@GET
@Path("/agent/address/{address}")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getAgentListByDepositAddress(@QueryParam("pageNumber") Integer pageNumber, @QueryParam("pageSize") Integer pageSize, @PathParam("address") String address) {
    RpcResult result = RpcResult.getSuccess();
    if (null == pageNumber || pageNumber == 0) {
        pageNumber = 1;
    }
    if (null == pageSize || pageSize == 0) {
        pageSize = 10;
    }
    if (pageNumber < 0 || pageSize < 0 || pageSize > 100) {
        return RpcResult.getFailed(ErrorCode.PARAMETER_ERROR);
    }
    // Page<AgentInfo> listPage = new Page<>();
    // if (temp == 1) {
    // listPage.setPageNumber(pageNumber);
    // listPage.setPageSize(pageSize);
    // listPage.setTotal(pageSize * 3);
    // listPage.setPages(3);
    // List<AgentInfo> list = new ArrayList<>();
    // for (int i = 0; i < pageSize; i++) {
    // AgentInfo item = new AgentInfo();
    // item.setCommissionRate(15);
    // item.setCreditRatio(0.9);
    // item.setStatus(2);
    // item.setAgentId(StringUtils.getNewUUID());
    // item.setMemberCount(3 + pageNumber);
    // item.setOwndeposit(Na.parseNuls(50000 + pageNumber));
    // item.setTotalDeposit(Na.parseNuls(300000 + pageNumber));
    // item.setIntroduction("哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈" + pageNumber);
    // item.setAgentAddress("2CYdNLysoMbPRc4Q5YsVreT99Q61ZSg");
    // item.setAgentName("超级节点" + i + pageNumber);
    // item.setStartTime(System.currentTimeMillis());
    // item.setPackedCount(11234 + i * pageNumber);
    // item.setReward(Na.parseNuls(1120 * i + pageNumber));
    // list.add(item);
    // }
    // listPage.setList(list);
    // result.setData(listPage);
    // return result;
    // }
    Page<Map<String, Object>> list = this.consensusService.getAgentList(null, address, null, null, pageNumber, pageSize);
    result.setData(list);
    return result;
}
Also used : RpcResult(io.nuls.rpc.entity.RpcResult) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with RpcResult

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

the class PocConsensusResource method queryDepositListByAgentAddress.

@GET
@Path("/deposit/agent/{agentAddress}")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult queryDepositListByAgentAddress(@PathParam("agentAddress") String agentAddress, @QueryParam("pageNumber") Integer pageNumber, @QueryParam("pageSize") Integer pageSize) {
    AssertUtil.canNotEmpty(agentAddress);
    if (null == pageNumber || pageNumber == 0) {
        pageNumber = 1;
    }
    if (null == pageSize || pageSize == 0) {
        pageSize = 10;
    }
    if (pageNumber < 0 || pageSize < 0 || pageSize > 100) {
        return RpcResult.getFailed(ErrorCode.PARAMETER_ERROR);
    }
    RpcResult result = RpcResult.getSuccess();
    // Page<DepositItem> listPage = new Page<>();
    // if (temp == 1) {
    // listPage.setPageNumber(pageNumber);
    // listPage.setPageSize(pageSize);
    // listPage.setTotal(pageSize * 3);
    // listPage.setPages(3);
    // List<DepositItem> list = new ArrayList<>();
    // for (int i = 0; i < pageSize; i++) {
    // DepositItem item = new DepositItem();
    // try {
    // item.setAddress(AccountTool.createAccount().getAddress().toString());
    // } catch (NulsException e) {
    // Log.error(e);
    // }
    // item.setAgentName("二货节点" + i);
    // item.setAmount(100000000 + i);
    // item.setDepositTime(System.currentTimeMillis());
    // item.setStatus(i / 2);
    // item.setAgentAddress(agentAddress);
    // list.add(item);
    // }
    // listPage.setList(list);
    // result.setData(listPage);
    // return result;
    // }
    Page<Map<String, Object>> page = this.consensusService.getDepositList(null, agentAddress, pageNumber, pageSize);
    result.setData(page);
    return result;
}
Also used : RpcResult(io.nuls.rpc.entity.RpcResult) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with RpcResult

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

the class PocConsensusResource method getDepositListByAddress.

@GET
@Path("/deposit/address/{address}")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getDepositListByAddress(@PathParam("address") String address, @QueryParam("pageNumber") Integer pageNumber, @QueryParam("pageSize") Integer pageSize, @QueryParam("agentAddress") String agentAddress) {
    AssertUtil.canNotEmpty(address);
    if (null == pageNumber || pageNumber == 0) {
        pageNumber = 1;
    }
    if (null == pageSize || pageSize == 0) {
        pageSize = 10;
    }
    if (pageNumber < 0 || pageSize < 0 || pageSize > 100) {
        return RpcResult.getFailed(ErrorCode.PARAMETER_ERROR);
    }
    RpcResult result = RpcResult.getSuccess();
    // Page<DepositItem> listPage = new Page<>();
    // if (temp == 1) {
    // listPage.setPageNumber(pageNumber);
    // listPage.setPageSize(pageSize);
    // listPage.setTotal(pageSize * 3);
    // listPage.setPages(3);
    // List<DepositItem> list = new ArrayList<>();
    // for (int i = 0; i < pageSize; i++) {
    // DepositItem item = new DepositItem();
    // item.setAddress(address);
    // item.setAmount(1000000000);
    // item.setDepositTime(System.currentTimeMillis());
    // item.setStatus(2);
    // item.setAgentName("二货节点" + i);
    // if (StringUtils.isNotBlank(agentAddress)) {
    // item.setAgentAddress(agentAddress);
    // } else {
    // try {
    // item.setAgentAddress(AccountTool.createAccount().getAddress().toString());
    // } catch (NulsException e) {
    // Log.error(e);
    // }
    // }
    // list.add(item);
    // }
    // listPage.setList(list);
    // result.setData(listPage);
    // return result;
    // }
    Page<Map<String, Object>> page = this.consensusService.getDepositList(address, agentAddress, pageNumber, pageSize);
    result.setData(page);
    return result;
}
Also used : RpcResult(io.nuls.rpc.entity.RpcResult) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with RpcResult

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

the class PocConsensusResource method profit.

@GET
@Path("/profit")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult profit(@QueryParam("address") String address) {
    Map<String, Object> map = new HashMap<>();
    if ((address != null && !Address.validAddress(address))) {
        return RpcResult.getFailed(ErrorCode.PARAMETER_ERROR);
    }
    if (address == null) {
        address = accountService.getDefaultAccount().getAddress().getBase58();
    }
    // get all reward
    List<UtxoOutputPo> outputList = outputDataService.getAccountOutputs(TransactionConstant.TX_TYPE_COIN_BASE, address, null, null);
    long value = 0;
    for (UtxoOutputPo output : outputList) {
        value += output.getValue();
    }
    map.put("profit", Na.valueOf(value).toDouble());
    // get last 24 hours reward
    long nowTime = TimeService.currentTimeMillis();
    nowTime = nowTime - DateUtil.DATE_TIME;
    outputList = outputDataService.getAccountOutputs(TransactionConstant.TX_TYPE_COIN_BASE, address, nowTime, null);
    value = 0;
    for (UtxoOutputPo output : outputList) {
        value += output.getValue();
    }
    map.put("lastProfit", Na.valueOf(value).toDouble());
    map.put("investment", NulsContext.INVESTMENT.toDouble());
    RpcResult rpcResult = RpcResult.getSuccess();
    rpcResult.setData(map);
    return rpcResult;
}
Also used : HashMap(java.util.HashMap) RpcResult(io.nuls.rpc.entity.RpcResult) UtxoOutputPo(io.nuls.db.entity.UtxoOutputPo)

Example 15 with RpcResult

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

the class PocConsensusResource method getWholeInfo.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Get the whole network consensus infomation!")
public RpcResult getWholeInfo() {
    RpcResult result = RpcResult.getSuccess();
    WholeNetConsensusInfoDTO dto = new WholeNetConsensusInfoDTO();
    Map<String, Object> map = this.consensusService.getConsensusInfo();
    dto.setAgentCount((Integer) map.get("agentCount"));
    dto.setRewardOfDay((Long) map.get("rewardOfDay"));
    dto.setTotalDeposit((Long) map.get("totalDeposit"));
    dto.setConsensusAccountNumber((Integer) map.get("memberCount"));
    result.setData(dto);
    return result;
}
Also used : WholeNetConsensusInfoDTO(io.nuls.rpc.resources.dto.WholeNetConsensusInfoDTO) RpcResult(io.nuls.rpc.entity.RpcResult) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

RpcResult (io.nuls.rpc.entity.RpcResult)26 HashMap (java.util.HashMap)6 BlockDto (io.nuls.rpc.entity.BlockDto)5 Result (io.nuls.core.chain.entity.Result)4 Map (java.util.Map)4 IOException (java.io.IOException)3 Block (io.nuls.core.chain.entity.Block)2 BlockHeader (io.nuls.core.chain.entity.BlockHeader)2 Transaction (io.nuls.core.chain.entity.Transaction)2 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)2 UtxoOutputPo (io.nuls.db.entity.UtxoOutputPo)2 TransactionDto (io.nuls.rpc.entity.TransactionDto)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Page (io.nuls.core.dto.Page)1 ModuleService (io.nuls.core.module.service.ModuleService)1 AgentPo (io.nuls.db.entity.AgentPo)1