Search in sources :

Example 16 with BlockHeader

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);
}
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)

Example 17 with BlockHeader

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;
}
Also used : RpcResult(io.nuls.rpc.entity.RpcResult) BlockHeader(io.nuls.core.chain.entity.BlockHeader) BlockDto(io.nuls.rpc.entity.BlockDto)

Example 18 with BlockHeader

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;
}
Also used : RpcResult(io.nuls.rpc.entity.RpcResult) BlockHeader(io.nuls.core.chain.entity.BlockHeader) BlockDto(io.nuls.rpc.entity.BlockDto)

Example 19 with BlockHeader

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

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