use of io.nuls.protocol.storage.po.BlockHeaderPo in project nuls by nuls-io.
the class BlockServiceImpl method getGengsisBlock.
/**
* 获取创世块(从存储中)
* Get the creation block (from storage)
*/
@Override
public Result<Block> getGengsisBlock() {
BlockHeaderPo headerPo = blockHeaderStorageService.getBlockHeaderPo(0);
if (null == headerPo) {
return Result.getFailed(ProtocolErroeCode.BLOCK_IS_NULL);
}
Block block = getBlock(headerPo);
return Result.getSuccess().setData(block);
}
use of io.nuls.protocol.storage.po.BlockHeaderPo in project nuls by nuls-io.
the class BlockServiceImpl method getBestBlock.
/**
* 获取最新的区块(从存储中)
* Get the highest block (from storage)
*/
@Override
public Result<Block> getBestBlock() {
BlockHeaderPo headerPo = blockHeaderStorageService.getBestBlockHeaderPo();
if (null == headerPo) {
return Result.getFailed(ProtocolErroeCode.BLOCK_IS_NULL);
}
Block block = getBlock(headerPo);
return Result.getSuccess().setData(block);
}
use of io.nuls.protocol.storage.po.BlockHeaderPo in project nuls by nuls-io.
the class BlockServiceImpl method getBlock.
/**
* 根据区块摘要获取区块(从存储中)
* Get the block (from storage) according to the block hash
*
* @param hash 区块摘要/block hash
* @param isNeedContractTransfer 是否需要把合约转账(从合约转出)交易添加到区块中/If necessary to add the contract transfer (from the contract) to the block
* @return 区块/block
*/
@Override
public Result<Block> getBlock(NulsDigestData hash, boolean isNeedContractTransfer) {
BlockHeaderPo headerPo = blockHeaderStorageService.getBlockHeaderPo(hash);
if (null == headerPo) {
return Result.getFailed(ProtocolErroeCode.BLOCK_IS_NULL);
}
Block block = getBlock(headerPo, isNeedContractTransfer);
return Result.getSuccess().setData(block);
}
use of io.nuls.protocol.storage.po.BlockHeaderPo in project nuls by nuls-io.
the class BlockHeaderStorageServiceImpl method removeBlockHerader.
private Result removeBlockHerader(byte[] hashBytes) {
if (null == hashBytes) {
return Result.getFailed(KernelErrorCode.NULL_PARAMETER);
}
BlockHeaderPo blockHeaderPo = getBlockHeaderPo(hashBytes);
if (null == blockHeaderPo) {
return Result.getSuccess();
}
dbService.delete(ProtocolStorageConstant.DB_NAME_BLOCK_HEADER_INDEX, new VarInt(blockHeaderPo.getHeight()).encode());
try {
dbService.put(ProtocolStorageConstant.DB_NAME_BLOCK_HEADER_INDEX, bestBlockKey, blockHeaderPo.getPreHash().serialize());
} catch (IOException e) {
Log.error(e);
}
return dbService.delete(ProtocolStorageConstant.DB_NAME_BLOCK_HEADER, hashBytes);
}
use of io.nuls.protocol.storage.po.BlockHeaderPo in project nuls by nuls-io.
the class BlockHeaderStorageServiceImplTest method getBlockPo.
public void getBlockPo() {
BlockHeaderPo po = this.service.getBlockHeaderPo(entity.getHeight());
this.testEquals(po, entity);
}
Aggregations