Search in sources :

Example 11 with BlockHeaderPo

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);
}
Also used : SmallBlock(io.nuls.protocol.model.SmallBlock) BlockHeaderPo(io.nuls.protocol.storage.po.BlockHeaderPo)

Example 12 with BlockHeaderPo

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);
}
Also used : SmallBlock(io.nuls.protocol.model.SmallBlock) BlockHeaderPo(io.nuls.protocol.storage.po.BlockHeaderPo)

Example 13 with BlockHeaderPo

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);
}
Also used : SmallBlock(io.nuls.protocol.model.SmallBlock) BlockHeaderPo(io.nuls.protocol.storage.po.BlockHeaderPo)

Example 14 with BlockHeaderPo

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);
}
Also used : VarInt(io.nuls.kernel.utils.VarInt) IOException(java.io.IOException) BlockHeaderPo(io.nuls.protocol.storage.po.BlockHeaderPo)

Example 15 with BlockHeaderPo

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);
}
Also used : BlockHeaderPo(io.nuls.protocol.storage.po.BlockHeaderPo)

Aggregations

BlockHeaderPo (io.nuls.protocol.storage.po.BlockHeaderPo)15 SmallBlock (io.nuls.protocol.model.SmallBlock)6 NulsException (io.nuls.kernel.exception.NulsException)2 NulsDigestData (io.nuls.kernel.model.NulsDigestData)2 ArrayList (java.util.ArrayList)2 ContractResult (io.nuls.contract.dto.ContractResult)1 LevelDbModuleBootstrap (io.nuls.db.module.impl.LevelDbModuleBootstrap)1 MicroKernelBootstrap (io.nuls.kernel.MicroKernelBootstrap)1 BlockSignature (io.nuls.kernel.script.BlockSignature)1 VarInt (io.nuls.kernel.utils.VarInt)1 BlockHeaderStorageService (io.nuls.protocol.storage.service.BlockHeaderStorageService)1 IOException (java.io.IOException)1 Before (org.junit.Before)1