Search in sources :

Example 6 with BlockHeaderPo

use of io.nuls.db.entity.BlockHeaderPo in project nuls by nuls-io.

the class ConsensusTool method toPojo.

public static final BlockHeaderPo toPojo(BlockHeader header) {
    BlockHeaderPo po = new BlockHeaderPo();
    po.setTxCount(header.getTxCount());
    po.setPreHash(header.getPreHash().getDigestHex());
    po.setMerkleHash(header.getMerkleHash().getDigestHex());
    po.setHeight(header.getHeight());
    po.setCreateTime(header.getTime());
    po.setHash(header.getHash().getDigestHex());
    po.setSize(header.getSize());
    if (null != header.getScriptSig()) {
        try {
            po.setScriptSig(header.getScriptSig().serialize());
        } catch (IOException e) {
            Log.error(e);
        }
    }
    po.setTxCount(header.getTxCount());
    po.setConsensusAddress(header.getPackingAddress());
    po.setExtend(header.getExtend());
    BlockRoundData data = new BlockRoundData();
    try {
        data.parse(header.getExtend());
    } catch (NulsException e) {
        Log.error(e);
    }
    po.setRoundIndex(data.getRoundIndex());
    return po;
}
Also used : NulsException(io.nuls.core.exception.NulsException) BlockRoundData(io.nuls.consensus.entity.block.BlockRoundData) IOException(java.io.IOException) BlockHeaderPo(io.nuls.db.entity.BlockHeaderPo)

Example 7 with BlockHeaderPo

use of io.nuls.db.entity.BlockHeaderPo in project nuls by nuls-io.

the class BlockStorageService method getBlockHeaderList.

public List<BlockHeader> getBlockHeaderList(long startHeight, long endHeight, long split) {
    List<BlockHeaderPo> strList = this.headerDao.getHashList(startHeight, endHeight, split);
    Map<Long, BlockHeader> headerMap = new HashMap<>();
    for (BlockHeaderPo po : strList) {
        BlockHeader header = new BlockHeader();
        header.setHash(NulsDigestData.fromDigestHex(po.getHash()));
        header.setHeight(po.getHeight());
        headerMap.put(po.getHeight(), header);
    }
    if ((endHeight - startHeight + 1) == headerMap.size()) {
        return new ArrayList<>(headerMap.values());
    }
    List<BlockHeader> headerList = new ArrayList<>();
    for (long i = startHeight; i <= endHeight; i++) {
        if (headerMap.containsKey(i)) {
            headerList.add(headerMap.get(i));
            continue;
        }
        BlockHeader header = blockCacheManager.getBlockHeader(i);
        if (null == header) {
            Block block = blockCacheManager.getBlock(i);
            if (null != block) {
                header = block.getHeader();
            }
        }
        if (null != header) {
            headerList.add(header);
        }
    }
    return headerList;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Block(io.nuls.core.chain.entity.Block) BlockHeader(io.nuls.core.chain.entity.BlockHeader) BlockHeaderPo(io.nuls.db.entity.BlockHeaderPo)

Example 8 with BlockHeaderPo

use of io.nuls.db.entity.BlockHeaderPo 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)

Example 9 with BlockHeaderPo

use of io.nuls.db.entity.BlockHeaderPo in project nuls by nuls-io.

the class BlockDaoImpl method getBlockHeaderList.

@Override
public Page<BlockHeaderPo> getBlockHeaderList(int pageNumber, int pageSize) {
    PageHelper.startPage(pageNumber, pageSize);
    PageHelper.orderBy("height desc");
    List<BlockHeaderPo> blockList = getMapper().selectList(new 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

BlockHeaderPo (io.nuls.db.entity.BlockHeaderPo)9 BlockHeader (io.nuls.core.chain.entity.BlockHeader)4 Page (io.nuls.core.dto.Page)4 ArrayList (java.util.ArrayList)4 Block (io.nuls.core.chain.entity.Block)3 PageInfo (com.github.pagehelper.PageInfo)2 NulsException (io.nuls.core.exception.NulsException)2 Searchable (io.nuls.db.dao.impl.mybatis.util.Searchable)2 BlockDto (io.nuls.rpc.entity.BlockDto)2 BlockRoundData (io.nuls.consensus.entity.block.BlockRoundData)1 Transaction (io.nuls.core.chain.entity.Transaction)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1