Java Code Examples for org.hyperledger.fabric.sdk.BlockInfo#TransactionEnvelopeInfo

The following examples show how to use org.hyperledger.fabric.sdk.BlockInfo#TransactionEnvelopeInfo . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FabricSDKWrapper.java    From WeEvent with Apache License 2.0 6 votes vote down vote up
public static List<WeEvent> getBlockChainInfo(Channel channel, Long blockNumber) throws ProposalException, InvalidArgumentException, BrokerException {
    List<WeEvent> weEventList = new ArrayList<>();
    BlockInfo returnedBlock = channel.queryBlockByNumber(blockNumber);
    for (BlockInfo.EnvelopeInfo envelopeInfo : returnedBlock.getEnvelopeInfos()) {
        if (envelopeInfo.getType() == TRANSACTION_ENVELOPE) {
            BlockInfo.TransactionEnvelopeInfo transactionEnvelopeInfo = (BlockInfo.TransactionEnvelopeInfo) envelopeInfo;
            for (BlockInfo.TransactionEnvelopeInfo.TransactionActionInfo transactionActionInfo : transactionEnvelopeInfo.getTransactionActionInfos()) {
                log.debug("chaincode input arguments count:{}", transactionActionInfo.getChaincodeInputArgsCount());
                if (transactionActionInfo.getChaincodeInputArgsCount() == WeEventConstants.DEFAULT_CHAINCODE_PARAM_COUNT && "publish".equals(new String(transactionActionInfo.getChaincodeInputArgs(0)))) {
                    WeEvent weEvent = new WeEvent();
                    weEvent.setTopic(new String(transactionActionInfo.getChaincodeInputArgs(1), UTF_8));
                    weEvent.setContent(transactionActionInfo.getChaincodeInputArgs(2));
                    weEvent.setExtensions(JsonHelper.json2Object(new String(transactionActionInfo.getChaincodeInputArgs(3)), new TypeReference<Map<String, String>>() {
                    }));
                    weEvent.setEventId(DataTypeUtils.encodeEventId(weEvent.getTopic(),
                            blockNumber.intValue(),
                            Integer.parseInt(new String(transactionActionInfo.getProposalResponsePayload()))));
                    weEventList.add(weEvent);
                    log.debug("weevent:{}", weEvent);
                }
            }
        }
    }
    return weEventList;
}
 
Example 2
Source File: ChaincodeManager.java    From fabric-net-server with Apache License 2.0 4 votes vote down vote up
private void execBlockInfo(BlockInfo blockInfo) throws InvalidArgumentException, IOException {
	final long blockNumber = blockInfo.getBlockNumber();
	log.debug("blockNumber = " + blockNumber);
	log.debug("data hash: " + Hex.encodeHexString(blockInfo.getDataHash()));
	log.debug("previous hash id: " + Hex.encodeHexString(blockInfo.getPreviousHash()));
	log.debug("calculated block hash is " + Hex.encodeHexString(SDKUtils.calculateBlockHash(blockNumber, blockInfo.getPreviousHash(), blockInfo.getDataHash())));
	
	final int envelopeCount = blockInfo.getEnvelopeCount();
	log.debug("block number " + blockNumber + " has " + envelopeCount + " envelope count:");
	
	for(EnvelopeInfo info: blockInfo.getEnvelopeInfos()) {
		final String channelId = info.getChannelId();
		log.debug("ChannelId = " + channelId);
		log.debug("Epoch = " + info.getEpoch());
		log.debug("TransactionID = " + info.getTransactionID());
		log.debug("ValidationCode = " + info.getValidationCode());
		log.debug("Timestamp = " + DateUtil.obtain().parseDateFormat(new Date(info.getTimestamp().getTime()), "yyyy年MM月dd日 HH时mm分ss秒"));
		log.debug("Type = " + info.getType());
		
		if (info.getType() == EnvelopeType.TRANSACTION_ENVELOPE) {
			BlockInfo.TransactionEnvelopeInfo txeInfo = (TransactionEnvelopeInfo) info;
			int txCount = txeInfo.getTransactionActionInfoCount();
			log.debug("Transaction number " + blockNumber + " has actions count = " + txCount);
			log.debug("Transaction number " + blockNumber + " isValid = " + txeInfo.isValid());
			log.debug("Transaction number " + blockNumber + " validation code = " + txeInfo.getValidationCode());
			
			for (int i = 0; i < txCount; i++) {
				BlockInfo.TransactionEnvelopeInfo.TransactionActionInfo txInfo = txeInfo.getTransactionActionInfo(i);
				log.debug("Transaction action " + i + " has response status " + txInfo.getResponseStatus());
                   log.debug("Transaction action " + i + " has response message bytes as string: " + printableString(new String(txInfo.getResponseMessageBytes(), "UTF-8")));
				log.debug("Transaction action " + i + " has endorsements " + txInfo.getEndorsementsCount());
				
				for (int n = 0; n < txInfo.getEndorsementsCount(); ++n) {
                       BlockInfo.EndorserInfo endorserInfo = txInfo.getEndorsementInfo(n);
                       log.debug("Endorser " + n + " signature: " + Hex.encodeHexString(endorserInfo.getSignature()));
                       log.debug("Endorser " + n + " endorser: " + new String(endorserInfo.getEndorser(), "UTF-8"));
                   }
				
                   log.debug("Transaction action " + i + " has " + txInfo.getChaincodeInputArgsCount() + " chaincode input arguments");
                   for (int z = 0; z < txInfo.getChaincodeInputArgsCount(); ++z) {
                       log.debug("Transaction action " + i + " has chaincode input argument " + z + "is: " + printableString(new String(txInfo.getChaincodeInputArgs(z), "UTF-8")));
                   }

                   log.debug("Transaction action " + i + " proposal response status: " + txInfo.getProposalResponseStatus());
                   log.debug("Transaction action " + i + " proposal response payload: " + printableString(new String(txInfo.getProposalResponsePayload())));

                   TxReadWriteSetInfo rwsetInfo = txInfo.getTxReadWriteSet();
                   if (null != rwsetInfo) {
                       log.debug("Transaction action " + i + " has " + rwsetInfo.getNsRwsetCount() +" name space read write sets");

                       for (TxReadWriteSetInfo.NsRwsetInfo nsRwsetInfo : rwsetInfo.getNsRwsetInfos()) {
                       	final String namespace = nsRwsetInfo.getNamespace();
                           KvRwset.KVRWSet rws = nsRwsetInfo.getRwset();

                           int rs = -1;
                           for (KvRwset.KVRead readList : rws.getReadsList()) {
                               rs++;

                               log.debug("Namespace " + namespace + " read set " + rs + " key " + readList.getKey() + " version [" + readList.getVersion().getBlockNum() + " : " + readList.getVersion().getTxNum() + "]");
                           }

                           rs = -1;
                           for (KvRwset.KVWrite writeList : rws.getWritesList()) {
                               rs++;
                               String valAsString = printableString(new String(writeList.getValue().toByteArray(), "UTF-8"));
                               log.debug("Namespace " + namespace + " write set " + rs + " key " + writeList.getKey() + " has value " + valAsString);
                           }
                       }
                   }
			}
		}
	}
}