use of io.nuls.core.chain.entity.BlockHeader in project nuls by nuls-io.
the class BlockServiceImpl method getBlockHeader.
@Override
public BlockHeader getBlockHeader(NulsDigestData hash) throws NulsException {
String hashHex = hash.getDigestHex();
BlockHeader header = blockManager.getBlockHeader(hashHex);
if (null == header) {
header = blockStorageService.getBlockHeader(hashHex);
}
return header;
}
use of io.nuls.core.chain.entity.BlockHeader in project nuls by nuls-io.
the class BlockStorageService method getBlockHeader.
public BlockHeader getBlockHeader(long height) throws NulsException {
BlockHeader header = blockCacheManager.getBlockHeader(height);
if (null != header) {
return header;
}
BlockHeaderPo po = this.headerDao.getHeader(height);
return ConsensusTool.fromPojo(po);
}
use of io.nuls.core.chain.entity.BlockHeader in project nuls by nuls-io.
the class BlockStorageService method getBlockList.
public List<Block> getBlockList(long startHeight, long endHeight) throws NulsException {
List<Block> blockList = new ArrayList<>();
List<BlockHeaderPo> poList = headerDao.getHeaderList(startHeight, endHeight);
List<Long> heightList = new ArrayList<>();
if (!poList.isEmpty()) {
List<Transaction> txList = null;
try {
txList = ledgerService.getTxList(startHeight, endHeight);
} catch (Exception e) {
Log.error(e);
}
Map<Long, List<Transaction>> txListGroup = txListGrouping(txList);
for (BlockHeaderPo po : poList) {
BlockHeader header = null;
try {
header = ConsensusTool.fromPojo(po);
} catch (NulsException e) {
throw e;
}
heightList.add(header.getHeight());
blockList.add(fillBlock(header, txListGroup.get(header.getHeight())));
}
}
if ((endHeight - startHeight + 1) > blockList.size()) {
for (long i = startHeight; i <= endHeight; i++) {
if (heightList.contains(i)) {
continue;
}
try {
blockList.add(this.getBlock(i));
} catch (Exception e) {
Log.error(e);
}
}
}
return blockList;
}
use of io.nuls.core.chain.entity.BlockHeader in project nuls by nuls-io.
the class BlockStorageService method getBlockHeader.
public BlockHeader getBlockHeader(String hash) throws NulsException {
BlockHeader header = blockCacheManager.getBlockHeader(hash);
if (null != header) {
return header;
}
Block block = blockCacheManager.getBlock(hash);
if (null != block) {
return block.getHeader();
}
BlockHeaderPo po = this.headerDao.getHeader(hash);
return ConsensusTool.fromPojo(po);
}
use of io.nuls.core.chain.entity.BlockHeader in project nuls by nuls-io.
the class BlockStorageService method getBlock.
public Block getBlock(String hash) throws Exception {
Block block = blockCacheManager.getBlock(hash);
if (null != block) {
return block;
}
BlockHeader header = getBlockHeader(hash);
if (null == header) {
return null;
}
List<Transaction> txList = null;
try {
txList = ledgerService.getTxList(header.getHeight());
} catch (Exception e) {
Log.error(e);
}
if (txList.size() != header.getTxCount()) {
System.out.println();
}
return fillBlock(header, txList);
}
Aggregations