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