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;
}
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;
}
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);
}
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;
}
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());
}
}
Aggregations