Search in sources :

Example 1 with SeekSpecified

use of org.hyperledger.fabric.protos.orderer.Ab.SeekSpecified in project fabric-sdk-java by hyperledger.

the class Channel method getBlockByNumber.

private Block getBlockByNumber(final long number) throws TransactionException {
    logger.trace(format("getConfigurationBlock for channel %s", name));
    try {
        logger.trace(format("Last config index is %d", number));
        SeekSpecified seekSpecified = SeekSpecified.newBuilder().setNumber(number).build();
        SeekPosition seekPosition = SeekPosition.newBuilder().setSpecified(seekSpecified).build();
        SeekInfo seekInfo = SeekInfo.newBuilder().setStart(seekPosition).setStop(seekPosition).setBehavior(SeekInfo.SeekBehavior.BLOCK_UNTIL_READY).build();
        ArrayList<DeliverResponse> deliverResponses = new ArrayList<>();
        seekBlock(seekInfo, deliverResponses, getRandomOrderer());
        DeliverResponse blockresp = deliverResponses.get(1);
        Block retBlock = blockresp.getBlock();
        if (retBlock == null) {
            throw new TransactionException(format("newest block for channel %s fetch bad deliver returned null:", name));
        }
        int dataCount = retBlock.getData().getDataCount();
        if (dataCount < 1) {
            throw new TransactionException(format("Bad config block data count %d", dataCount));
        }
        logger.trace(format("Received  block for channel %s, block no:%d, transaction count: %d", name, retBlock.getHeader().getNumber(), retBlock.getData().getDataCount()));
        return retBlock;
    } catch (TransactionException e) {
        logger.error(e.getMessage(), e);
        throw e;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new TransactionException(e);
    }
}
Also used : SeekInfo(org.hyperledger.fabric.protos.orderer.Ab.SeekInfo) TransactionException(org.hyperledger.fabric.sdk.exception.TransactionException) SeekPosition(org.hyperledger.fabric.protos.orderer.Ab.SeekPosition) SeekSpecified(org.hyperledger.fabric.protos.orderer.Ab.SeekSpecified) ArrayList(java.util.ArrayList) Block(org.hyperledger.fabric.protos.common.Common.Block) DeliverResponse(org.hyperledger.fabric.protos.orderer.Ab.DeliverResponse) EventHubException(org.hyperledger.fabric.sdk.exception.EventHubException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) InvalidArgumentException(org.hyperledger.fabric.sdk.exception.InvalidArgumentException) TransactionException(org.hyperledger.fabric.sdk.exception.TransactionException) TransactionEventException(org.hyperledger.fabric.sdk.exception.TransactionEventException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) StatusRuntimeException(io.grpc.StatusRuntimeException) CryptoException(org.hyperledger.fabric.sdk.exception.CryptoException) TimeoutException(java.util.concurrent.TimeoutException) ProposalException(org.hyperledger.fabric.sdk.exception.ProposalException)

Example 2 with SeekSpecified

use of org.hyperledger.fabric.protos.orderer.Ab.SeekSpecified in project fabric-sdk-java by hyperledger.

the class Channel method getGenesisBlock.

private Block getGenesisBlock(Orderer orderer) throws TransactionException {
    try {
        if (genesisBlock != null) {
            logger.debug(format("Channel %s getGenesisBlock already present", name));
        } else {
            final long start = System.currentTimeMillis();
            SeekSpecified seekSpecified = SeekSpecified.newBuilder().setNumber(0).build();
            SeekPosition seekPosition = SeekPosition.newBuilder().setSpecified(seekSpecified).build();
            SeekSpecified seekStopSpecified = SeekSpecified.newBuilder().setNumber(0).build();
            SeekPosition seekStopPosition = SeekPosition.newBuilder().setSpecified(seekStopSpecified).build();
            SeekInfo seekInfo = SeekInfo.newBuilder().setStart(seekPosition).setStop(seekStopPosition).setBehavior(SeekInfo.SeekBehavior.BLOCK_UNTIL_READY).build();
            ArrayList<DeliverResponse> deliverResponses = new ArrayList<>();
            seekBlock(seekInfo, deliverResponses, orderer);
            DeliverResponse blockresp = deliverResponses.get(1);
            Block configBlock = blockresp.getBlock();
            if (configBlock == null) {
                throw new TransactionException(format("In getGenesisBlock newest block for channel %s fetch bad deliver returned null:", name));
            }
            int dataCount = configBlock.getData().getDataCount();
            if (dataCount < 1) {
                throw new TransactionException(format("In getGenesisBlock bad config block data count %d", dataCount));
            }
            genesisBlock = blockresp.getBlock();
        }
    } catch (TransactionException e) {
        logger.error(e.getMessage(), e);
        throw e;
    } catch (Exception e) {
        TransactionException exp = new TransactionException("getGenesisBlock " + e.getMessage(), e);
        logger.error(exp.getMessage(), exp);
        throw exp;
    }
    if (genesisBlock == null) {
        // make sure it was really set.
        TransactionException exp = new TransactionException("getGenesisBlock returned null");
        logger.error(exp.getMessage(), exp);
        throw exp;
    }
    logger.debug(format("Channel %s getGenesisBlock done.", name));
    return genesisBlock;
}
Also used : SeekInfo(org.hyperledger.fabric.protos.orderer.Ab.SeekInfo) TransactionException(org.hyperledger.fabric.sdk.exception.TransactionException) SeekPosition(org.hyperledger.fabric.protos.orderer.Ab.SeekPosition) SeekSpecified(org.hyperledger.fabric.protos.orderer.Ab.SeekSpecified) ArrayList(java.util.ArrayList) Block(org.hyperledger.fabric.protos.common.Common.Block) DeliverResponse(org.hyperledger.fabric.protos.orderer.Ab.DeliverResponse) EventHubException(org.hyperledger.fabric.sdk.exception.EventHubException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) InvalidArgumentException(org.hyperledger.fabric.sdk.exception.InvalidArgumentException) TransactionException(org.hyperledger.fabric.sdk.exception.TransactionException) TransactionEventException(org.hyperledger.fabric.sdk.exception.TransactionEventException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) StatusRuntimeException(io.grpc.StatusRuntimeException) CryptoException(org.hyperledger.fabric.sdk.exception.CryptoException) TimeoutException(java.util.concurrent.TimeoutException) ProposalException(org.hyperledger.fabric.sdk.exception.ProposalException)

Aggregations

InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 Block (org.hyperledger.fabric.protos.common.Common.Block)2 DeliverResponse (org.hyperledger.fabric.protos.orderer.Ab.DeliverResponse)2 SeekInfo (org.hyperledger.fabric.protos.orderer.Ab.SeekInfo)2 SeekPosition (org.hyperledger.fabric.protos.orderer.Ab.SeekPosition)2 SeekSpecified (org.hyperledger.fabric.protos.orderer.Ab.SeekSpecified)2 CryptoException (org.hyperledger.fabric.sdk.exception.CryptoException)2 EventHubException (org.hyperledger.fabric.sdk.exception.EventHubException)2 InvalidArgumentException (org.hyperledger.fabric.sdk.exception.InvalidArgumentException)2 ProposalException (org.hyperledger.fabric.sdk.exception.ProposalException)2 TransactionEventException (org.hyperledger.fabric.sdk.exception.TransactionEventException)2 TransactionException (org.hyperledger.fabric.sdk.exception.TransactionException)2