Search in sources :

Example 1 with RpcResult

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

the class BlockResource method loadBlock.

@GET
@Path("/hash/{hash}")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult loadBlock(@PathParam("hash") String hash) {
    RpcResult result;
    if (!StringUtils.validHash(hash)) {
        return RpcResult.getFailed(ErrorCode.PARAMETER_ERROR);
    }
    Block block = blockService.getBlock(hash);
    if (block == null) {
        result = RpcResult.getFailed(ErrorCode.DATA_NOT_FOUND);
    } else {
        long reward = ledgerService.getBlockReward(block.getHeader().getHeight());
        long fee = ledgerService.getBlockFee(block.getHeader().getHeight());
        result = RpcResult.getSuccess();
        try {
            result.setData(new BlockDto(block, reward, fee));
        } catch (IOException e) {
            // todo
            e.printStackTrace();
        }
    }
    return result;
}
Also used : RpcResult(io.nuls.rpc.entity.RpcResult) Block(io.nuls.core.chain.entity.Block) IOException(java.io.IOException) BlockDto(io.nuls.rpc.entity.BlockDto)

Example 2 with RpcResult

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

the class BlockResource method getBestBlockHash.

@GET
@Path("/newest")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getBestBlockHash() throws IOException {
    RpcResult result = RpcResult.getSuccess();
    result.setData(new BlockDto(blockService.getLocalBestBlock().getHeader(), 0, 0));
    return result;
}
Also used : RpcResult(io.nuls.rpc.entity.RpcResult) BlockDto(io.nuls.rpc.entity.BlockDto)

Example 3 with RpcResult

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

the class PocConsensusResource method getAllAgentStatusList.

@GET
@Path("/agent/status")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getAllAgentStatusList() {
    RpcResult rpcResult = RpcResult.getSuccess();
    List<AgentPo> polist = agentDataService.getList();
    if (null == polist || polist.isEmpty()) {
        return rpcResult;
    }
    Map<String, Integer> statusMap = new HashMap<>();
    for (AgentPo po : polist) {
        statusMap.put(po.getAgentAddress(), po.getStatus());
    }
    return rpcResult.setData(statusMap);
}
Also used : HashMap(java.util.HashMap) RpcResult(io.nuls.rpc.entity.RpcResult) AgentPo(io.nuls.db.entity.AgentPo)

Example 4 with RpcResult

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

the class PocConsensusResource method getInfo.

@GET
@Path("/address/{address}")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getInfo(@PathParam("address") String address) {
    AssertUtil.canNotEmpty(address);
    RpcResult result = RpcResult.getSuccess();
    Map<String, Object> dataMap = consensusService.getConsensusInfo(address);
    result.setData(dataMap);
    return result;
}
Also used : RpcResult(io.nuls.rpc.entity.RpcResult)

Example 5 with RpcResult

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

the class TransactionResource method list.

@GET
@Path("/list")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult list(@QueryParam("blockHeight") Long blockHeight, @QueryParam("address") String address, @QueryParam("type") int type, @QueryParam("pageNumber") int pageNumber, @QueryParam("pageSize") int pageSize) {
    if (blockHeight == null && StringUtils.isBlank(address) && type == 0) {
        return RpcResult.getFailed(ErrorCode.PARAMETER_ERROR);
    }
    if ((blockHeight != null && blockHeight < 0) || type < 0 || pageNumber < 0 || pageSize < 0) {
        return RpcResult.getFailed(ErrorCode.PARAMETER_ERROR);
    }
    if ((pageNumber == 0 && pageSize > 0) || (pageNumber > 0 && pageSize == 0)) {
        return RpcResult.getFailed(ErrorCode.PARAMETER_ERROR);
    }
    try {
        RpcResult result = RpcResult.getSuccess();
        Page<Transaction> pages = new Page<>();
        if (StringUtils.isBlank(address)) {
            pages = ledgerService.getTxList(blockHeight, type, pageNumber, pageSize);
        } else if (Address.validAddress(address)) {
            long count = ledgerService.getTxCount(blockHeight, address, type);
            if (count < (pageNumber - 1) * pageSize) {
                Page page = new Page(pageNumber, pageSize);
                return result.setData(page);
            }
            if (pageSize > 0) {
                pages.setPageNumber(pageNumber);
                pages.setPageSize(pageSize);
            } else {
                pages.setPageNumber(pageNumber);
                pages.setPages((int) count);
            }
            pages.setTotal(count);
            if (count == 0) {
                return RpcResult.getSuccess().setData(pages);
            }
            List<Transaction> txList = ledgerService.getTxList(blockHeight, address, type, pageNumber, pageSize);
            pages.setList(txList);
        }
        Page<TransactionDto> pageDto = new Page<>(pages);
        List<TransactionDto> dtoList = new ArrayList<>();
        for (Transaction tx : pages.getList()) {
            dtoList.add(new TransactionDto(tx, address));
        }
        pageDto.setList(dtoList);
        result.setData(pageDto);
        return result;
    } catch (Exception e) {
        Log.error(e);
        return RpcResult.getFailed(e.getMessage());
    }
}
Also used : TransactionDto(io.nuls.rpc.entity.TransactionDto) Transaction(io.nuls.core.chain.entity.Transaction) RpcResult(io.nuls.rpc.entity.RpcResult) ArrayList(java.util.ArrayList) Page(io.nuls.core.dto.Page) ArrayList(java.util.ArrayList) List(java.util.List) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException)

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