use of io.nuls.core.dto.Page in project nuls by nuls-io.
the class BlockResource method getBlocks.
@GET
@Path("/list")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getBlocks(@QueryParam("pageNumber") int pageNumber, @QueryParam("pageSize") int pageSize) {
if (pageNumber < 0 || pageSize < 0) {
return RpcResult.getFailed(ErrorCode.PARAMETER_ERROR);
}
if (pageNumber == 0) {
pageNumber = 1;
}
if (pageSize == 0) {
pageSize = 10;
}
Page<BlockHeaderPo> page = blockService.getBlockHeaderList(pageNumber, pageSize);
Page<BlockDto> dtoPage = new Page<>(page);
List<BlockDto> dtoList = new ArrayList<>();
long reward = 0;
for (BlockHeaderPo header : page.getList()) {
reward = ledgerService.getBlockReward(header.getHeight());
dtoList.add(new BlockDto(header, reward, 0));
}
dtoPage.setList(dtoList);
return RpcResult.getSuccess().setData(dtoPage);
}
use of io.nuls.core.dto.Page in project nuls by nuls-io.
the class BlockResource method getBlocksByAddress.
@GET
@Path("/list/address")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getBlocksByAddress(@QueryParam("address") String address, @QueryParam("type") int type, @QueryParam("pageNumber") int pageNumber, @QueryParam("pageSize") int pageSize) {
if (type < 1 || type > 2 || pageNumber < 0 || pageSize < 0 || !Address.validAddress(address)) {
return RpcResult.getFailed(ErrorCode.PARAMETER_ERROR);
}
if (pageNumber == 0) {
pageNumber = 1;
}
if (pageSize == 0) {
pageSize = 10;
}
Page<BlockHeaderPo> page = blockService.getBlockHeaderList(address, type, pageNumber, pageSize);
Page<BlockDto> dtoPage = new Page<>(page);
List<BlockDto> dtoList = new ArrayList<>();
long reward = 0;
for (BlockHeaderPo header : page.getList()) {
reward = ledgerService.getBlockReward(header.getHeight());
dtoList.add(new BlockDto(header, reward, 0));
}
dtoPage.setList(dtoList);
return RpcResult.getSuccess().setData(dtoPage);
}
use of io.nuls.core.dto.Page 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.core.dto.Page in project nuls by nuls-io.
the class UtxoLedgerServiceImpl method getTxList.
@Override
public Page<Transaction> getTxList(Long height, int type, int pageNum, int pageSize) throws Exception {
Page<TransactionPo> poPage = txDao.getTxs(height, type, pageNum, pageSize);
Page<Transaction> txPage = new Page<>(poPage);
List<Transaction> txList = new ArrayList<>();
for (TransactionPo po : poPage.getList()) {
txList.add(UtxoTransferTool.toTransaction(po));
}
txPage.setList(txList);
return txPage;
}
use of io.nuls.core.dto.Page in project nuls by nuls-io.
the class BlockDaoImpl method getBlockListByAddress.
@Override
public Page<BlockHeaderPo> getBlockListByAddress(String nodeAddress, int type, int pageNumber, int pageSize) {
Searchable searchable = new Searchable();
if (type == 1) {
searchable.addCondition("a.agent_address", SearchOperator.eq, nodeAddress);
} else {
searchable.addCondition("a.packing_address", SearchOperator.eq, nodeAddress);
}
PageHelper.startPage(pageNumber, pageSize);
PageHelper.orderBy("b.height desc");
List<BlockHeaderPo> blockList = getMapper().getBlockByAddress(searchable);
PageInfo<BlockHeaderPo> pageInfo = new PageInfo<>(blockList);
Page<BlockHeaderPo> page = new Page<>();
page.setTotal(pageInfo.getTotal());
page.setPageNumber(pageNumber);
page.setPageSize(pageSize);
page.setPages(pageInfo.getPages());
page.setList(blockList);
return page;
}
Aggregations