Search in sources :

Example 1 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
 * @return 区块/block
 */
@Override
public Result<Block> getBlock(NulsDigestData hash) {
    BlockHeaderPo headerPo = blockHeaderStorageService.getBlockHeaderPo(hash);
    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 2 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 height
 *
 * @param height                 区块高度/block height
 * @param isNeedContractTransfer 是否需要把合约转账(从合约转出)交易添加到区块中/If necessary to add the contract transfer (from the contract) to the block
 * @return 区块/block
 */
@Override
public Result<Block> getBlock(long height, boolean isNeedContractTransfer) {
    BlockHeaderPo headerPo = blockHeaderStorageService.getBlockHeaderPo(height);
    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 3 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 height
 *
 * @param height 区块高度/block height
 * @return 区块/block
 */
@Override
public Result<Block> getBlock(long height) {
    BlockHeaderPo headerPo = blockHeaderStorageService.getBlockHeaderPo(height);
    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 4 with BlockHeaderPo

use of io.nuls.protocol.storage.po.BlockHeaderPo in project nuls by nuls-io.

the class BlockServiceImpl method getBlockTxHash.

@Override
public List<String> getBlockTxHash(long height) {
    BlockHeaderPo headerPo = blockHeaderStorageService.getBlockHeaderPo(height);
    List<String> list = new ArrayList<>();
    if (null != headerPo && null != headerPo.getTxHashList()) {
        for (NulsDigestData hash : headerPo.getTxHashList()) {
            list.add(hash.getDigestHex());
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) BlockHeaderPo(io.nuls.protocol.storage.po.BlockHeaderPo)

Example 5 with BlockHeaderPo

use of io.nuls.protocol.storage.po.BlockHeaderPo in project nuls by nuls-io.

the class PoConvertUtil method toBlockHeaderPo.

public static BlockHeaderPo toBlockHeaderPo(Block block) {
    BlockHeaderPo po = new BlockHeaderPo();
    po.setHash(block.getHeader().getHash());
    po.setPreHash(block.getHeader().getPreHash());
    po.setMerkleHash(block.getHeader().getMerkleHash());
    po.setTime(block.getHeader().getTime());
    po.setHeight(block.getHeader().getHeight());
    po.setTxCount(block.getHeader().getTxCount());
    po.setPackingAddress(block.getHeader().getPackingAddress());
    po.setScriptSign(block.getHeader().getBlockSignature());
    po.setExtend(block.getHeader().getExtend());
    po.setTxHashList(block.getTxHashList());
    po.setStateRoot(ContractUtil.getStateRoot(block.getHeader()));
    return po;
}
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