use of io.nuls.rpc.entity.TransactionDto 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());
}
}
use of io.nuls.rpc.entity.TransactionDto in project nuls by nuls-io.
the class TransactionResource method load.
@GET
@Path("/hash/{hash}")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult load(@PathParam("hash") String hash) {
RpcResult result = null;
if (StringUtils.isBlank(hash)) {
return RpcResult.getFailed(ErrorCode.NULL_PARAMETER);
}
try {
Transaction tx = ledgerService.getTx(NulsDigestData.fromDigestHex(hash));
if (tx == null) {
result = RpcResult.getFailed("not found");
} else {
result = RpcResult.getSuccess();
result.setData(new TransactionDto(tx));
}
} catch (NulsRuntimeException re) {
Log.error(re);
result = new RpcResult(false, re.getCode(), re.getMessage());
} catch (Exception e) {
Log.error(e);
result = RpcResult.getFailed(ErrorCode.SYS_UNKOWN_EXCEPTION);
}
return result;
}
Aggregations