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