use of org.hyperledger.fabric.protos.orderer.Ab.SeekPosition in project fabric-sdk-java by hyperledger.
the class Channel method getLatestBlock.
private Block getLatestBlock(Orderer orderer) throws TransactionException {
logger.debug(format("getConfigurationBlock for channel %s", name));
SeekPosition seekPosition = SeekPosition.newBuilder().setNewest(Ab.SeekNewest.getDefaultInstance()).build();
SeekInfo seekInfo = SeekInfo.newBuilder().setStart(seekPosition).setStop(seekPosition).setBehavior(SeekInfo.SeekBehavior.BLOCK_UNTIL_READY).build();
ArrayList<DeliverResponse> deliverResponses = new ArrayList<>();
seekBlock(seekInfo, deliverResponses, orderer);
DeliverResponse blockresp = deliverResponses.get(1);
Block latestBlock = blockresp.getBlock();
if (latestBlock == null) {
throw new TransactionException(format("newest block for channel %s fetch bad deliver returned null:", name));
}
logger.trace(format("Received latest block for channel %s, block no:%d", name, latestBlock.getHeader().getNumber()));
return latestBlock;
}
use of org.hyperledger.fabric.protos.orderer.Ab.SeekPosition 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);
}
}
use of org.hyperledger.fabric.protos.orderer.Ab.SeekPosition 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;
}
Aggregations