Search in sources :

Example 1 with BlockHeader

use of io.nuls.core.chain.entity.BlockHeader in project nuls by nuls-io.

the class BlockServiceImpl method getBlockHeader.

@Override
public BlockHeader getBlockHeader(NulsDigestData hash) throws NulsException {
    String hashHex = hash.getDigestHex();
    BlockHeader header = blockManager.getBlockHeader(hashHex);
    if (null == header) {
        header = blockStorageService.getBlockHeader(hashHex);
    }
    return header;
}
Also used : BlockHeader(io.nuls.core.chain.entity.BlockHeader)

Example 2 with BlockHeader

use of io.nuls.core.chain.entity.BlockHeader 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);
}
Also used : BlockHeader(io.nuls.core.chain.entity.BlockHeader) BlockHeaderPo(io.nuls.db.entity.BlockHeaderPo)

Example 3 with BlockHeader

use of io.nuls.core.chain.entity.BlockHeader 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;
}
Also used : ArrayList(java.util.ArrayList) NulsException(io.nuls.core.exception.NulsException) Transaction(io.nuls.core.chain.entity.Transaction) NulsException(io.nuls.core.exception.NulsException) Block(io.nuls.core.chain.entity.Block) ArrayList(java.util.ArrayList) List(java.util.List) BlockHeader(io.nuls.core.chain.entity.BlockHeader) BlockHeaderPo(io.nuls.db.entity.BlockHeaderPo)

Example 4 with BlockHeader

use of io.nuls.core.chain.entity.BlockHeader 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);
}
Also used : Block(io.nuls.core.chain.entity.Block) BlockHeader(io.nuls.core.chain.entity.BlockHeader) BlockHeaderPo(io.nuls.db.entity.BlockHeaderPo)

Example 5 with BlockHeader

use of io.nuls.core.chain.entity.BlockHeader in project nuls by nuls-io.

the class BlockStorageService method getBlock.

public Block getBlock(String hash) throws Exception {
    Block block = blockCacheManager.getBlock(hash);
    if (null != block) {
        return block;
    }
    BlockHeader header = getBlockHeader(hash);
    if (null == header) {
        return null;
    }
    List<Transaction> txList = null;
    try {
        txList = ledgerService.getTxList(header.getHeight());
    } catch (Exception e) {
        Log.error(e);
    }
    if (txList.size() != header.getTxCount()) {
        System.out.println();
    }
    return fillBlock(header, txList);
}
Also used : Transaction(io.nuls.core.chain.entity.Transaction) Block(io.nuls.core.chain.entity.Block) BlockHeader(io.nuls.core.chain.entity.BlockHeader) NulsException(io.nuls.core.exception.NulsException)

Aggregations

BlockHeader (io.nuls.core.chain.entity.BlockHeader)19 Block (io.nuls.core.chain.entity.Block)11 NulsException (io.nuls.core.exception.NulsException)6 Transaction (io.nuls.core.chain.entity.Transaction)5 BlockHeaderPo (io.nuls.db.entity.BlockHeaderPo)4 ArrayList (java.util.ArrayList)3 BlockRoundData (io.nuls.consensus.entity.block.BlockRoundData)2 NulsDigestData (io.nuls.core.chain.entity.NulsDigestData)2 ValidateResult (io.nuls.core.validate.ValidateResult)2 BlockDto (io.nuls.rpc.entity.BlockDto)2 RpcResult (io.nuls.rpc.entity.RpcResult)2 BlockHashResponse (io.nuls.consensus.entity.BlockHashResponse)1 GetSmallBlockParam (io.nuls.consensus.entity.GetSmallBlockParam)1 BestCorrectBlock (io.nuls.consensus.entity.block.BestCorrectBlock)1 PocMeetingRound (io.nuls.consensus.entity.meeting.PocMeetingRound)1 BlockHeaderEvent (io.nuls.consensus.event.BlockHeaderEvent)1 GetBlockHeaderEvent (io.nuls.consensus.event.GetBlockHeaderEvent)1 GetSmallBlockRequest (io.nuls.consensus.event.GetSmallBlockRequest)1 BlockInfo (io.nuls.consensus.utils.BlockInfo)1 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)1