use of io.nuls.core.chain.entity.BlockHeader in project nuls by nuls-io.
the class BlockStorageService method getBlock.
public Block getBlock(long height) throws Exception {
Block block = blockCacheManager.getBlock(height);
if (null != block && block.getTxs().size() == block.getHeader().getTxCount()) {
return block;
}
BlockHeader header = getBlockHeader(height);
if (null == header) {
return null;
}
List<Transaction> txList = null;
try {
txList = ledgerService.getTxList(height);
} catch (Exception e) {
Log.error(e);
}
if (header.getTxCount() != txList.size()) {
Log.warn("block has wrong tx size!");
}
return fillBlock(header, txList);
}
use of io.nuls.core.chain.entity.BlockHeader in project nuls by nuls-io.
the class BlockResource method getHeader.
@GET
@Path("/header/hash/{hash}")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getHeader(@PathParam("hash") String hash) throws NulsException, IOException {
RpcResult result = RpcResult.getSuccess();
BlockHeader blockHeader = blockService.getBlockHeader(hash);
if (blockHeader == null) {
return RpcResult.getFailed(ErrorCode.DATA_NOT_FOUND);
}
long reward = ledgerService.getBlockReward(blockHeader.getHeight());
long fee = ledgerService.getBlockFee(blockHeader.getHeight());
result.setData(new BlockDto(blockHeader, reward, fee));
return result;
}
use of io.nuls.core.chain.entity.BlockHeader in project nuls by nuls-io.
the class BlockResource method getHeaderByHeight.
@GET
@Path("/header/height/{height}")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getHeaderByHeight(@PathParam("height") Integer height) throws NulsException, IOException {
RpcResult result = RpcResult.getSuccess();
BlockHeader blockHeader = blockService.getBlockHeader(height);
if (blockHeader == null) {
return RpcResult.getFailed(ErrorCode.DATA_NOT_FOUND);
}
long reward = ledgerService.getBlockReward(blockHeader.getHeight());
long fee = ledgerService.getBlockFee(blockHeader.getHeight());
result.setData(new BlockDto(blockHeader, reward, fee));
return result;
}
use of io.nuls.core.chain.entity.BlockHeader in project nuls by nuls-io.
the class ConfrimingBlockCacheManager method getBlock.
public Block getBlock(String hash) {
if (null == txsCacheMap || headerCacheMap == null) {
return null;
}
BlockHeader header = headerCacheMap.get(hash);
List<Transaction> txs = txsCacheMap.get(hash);
if (null == header || null == txs || txs.isEmpty()) {
return null;
}
Block block = new Block();
block.setHeader(header);
block.setTxs(txs);
return block;
}
Aggregations