Search in sources :

Example 1 with Page

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);
}
Also used : ArrayList(java.util.ArrayList) Page(io.nuls.core.dto.Page) BlockHeaderPo(io.nuls.db.entity.BlockHeaderPo) BlockDto(io.nuls.rpc.entity.BlockDto)

Example 2 with Page

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);
}
Also used : ArrayList(java.util.ArrayList) Page(io.nuls.core.dto.Page) BlockHeaderPo(io.nuls.db.entity.BlockHeaderPo) BlockDto(io.nuls.rpc.entity.BlockDto)

Example 3 with Page

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

Example 4 with Page

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;
}
Also used : TransferTransaction(io.nuls.ledger.entity.tx.TransferTransaction) AbstractCoinTransaction(io.nuls.ledger.entity.tx.AbstractCoinTransaction) LockNulsTransaction(io.nuls.ledger.entity.tx.LockNulsTransaction) ArrayList(java.util.ArrayList) Page(io.nuls.core.dto.Page) TransactionPo(io.nuls.db.entity.TransactionPo)

Example 5 with Page

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;
}
Also used : PageInfo(com.github.pagehelper.PageInfo) Page(io.nuls.core.dto.Page) Searchable(io.nuls.db.dao.impl.mybatis.util.Searchable) BlockHeaderPo(io.nuls.db.entity.BlockHeaderPo)

Aggregations

Page (io.nuls.core.dto.Page)7 BlockHeaderPo (io.nuls.db.entity.BlockHeaderPo)4 ArrayList (java.util.ArrayList)4 Searchable (io.nuls.db.dao.impl.mybatis.util.Searchable)3 PageInfo (com.github.pagehelper.PageInfo)2 TransactionPo (io.nuls.db.entity.TransactionPo)2 BlockDto (io.nuls.rpc.entity.BlockDto)2 Transaction (io.nuls.core.chain.entity.Transaction)1 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)1 AbstractCoinTransaction (io.nuls.ledger.entity.tx.AbstractCoinTransaction)1 LockNulsTransaction (io.nuls.ledger.entity.tx.LockNulsTransaction)1 TransferTransaction (io.nuls.ledger.entity.tx.TransferTransaction)1 RpcResult (io.nuls.rpc.entity.RpcResult)1 TransactionDto (io.nuls.rpc.entity.TransactionDto)1 List (java.util.List)1