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

The following examples show how to use org.hyperledger.fabric.sdk.BlockInfo#EnvelopeInfo . 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: FabricSDKWrapper.java    From WeEvent with Apache License 2.0 5 votes vote down vote up
private static void generateTbTransHashListPage(Integer pageIndex,
                                                Integer pageSize,
                                                ListPage<TbTransHash> tbTransHashListPage,
                                                List<TbTransHash> tbTransHashes,
                                                BlockInfo blockInfo) throws BrokerException {
    Integer transCount = blockInfo.getTransactionCount();

    if (pageIndex < 1 || (pageIndex - 1) * pageSize > transCount) {
        log.error("pageIndex error.");
        throw new BrokerException("pageIndex error.");
    }
    Integer transSize = (transCount <= pageIndex * pageSize) ? (transCount - ((pageIndex - 1) * pageSize)) : pageSize;
    Integer transIndexStart = (pageIndex - 1) * pageSize;


    Iterable<BlockInfo.EnvelopeInfo> envelopeInfos = blockInfo.getEnvelopeInfos();
    envelopeInfos.forEach(envelopeInfo -> {
        TbTransHash tbTransHash = new TbTransHash();
        tbTransHash.setCreateTime(DataTypeUtils.getTimestamp(envelopeInfo.getTimestamp()));
        tbTransHash.setBlockTimestamp(DataTypeUtils.getTimestamp(envelopeInfo.getTimestamp()));
        tbTransHash.setTransHash(envelopeInfo.getTransactionID());
        tbTransHash.setBlockNumber(BigInteger.valueOf(blockInfo.getBlockNumber()));
        tbTransHashes.add(tbTransHash);
    });

    if (tbTransHashes != null && !tbTransHashes.isEmpty()) {
        tbTransHashes.subList(transIndexStart, transSize + transIndexStart);
    }

    tbTransHashListPage.setPageSize(transSize);
    tbTransHashListPage.setTotal(transCount);
    tbTransHashListPage.setPageData(tbTransHashes);
}
 
Example 3
Source File: FabricContext.java    From spring-fabric-gateway with MIT License 4 votes vote down vote up
public FabricQueryResponse<FabricTransaction> queryTransactionInfo(String txId) {
	try {
		if (network == null) {
			getContract();
		}
		Channel channel = network.getChannel();

		BlockInfo block = channel.queryBlockByTransactionID(txId);

		if (block == null) {
			return FabricQueryResponse.failure("Unable to query block from txId=" + txId);
		}
		TransactionEnvelopeInfo envelopeInfo = null;
		Iterator<EnvelopeInfo> iterator = block.getEnvelopeInfos().iterator();
		while (iterator.hasNext()) {
			BlockInfo.EnvelopeInfo info = iterator.next();
			if (info.getTransactionID().equals(txId) && info instanceof TransactionEnvelopeInfo) {
				envelopeInfo = (TransactionEnvelopeInfo) info;
				break;
			}
		}
		FabricTransaction tx = new FabricTransaction();
		tx.setTxId(txId);
		tx.setChannel(envelopeInfo.getChannelId());
		IdentitiesInfo creator = envelopeInfo.getCreator();
		if (creator != null) {
			String mspid = creator.getMspid();
			tx.setCreator(mspid);
		}
		tx.setDate(envelopeInfo.getTimestamp());
		EnvelopeType type = envelopeInfo.getType();
		if (type != null) {
			tx.setType(type.name());
		}
		tx.setValidationCode(envelopeInfo.getValidationCode());

		TransactionInfo transaction = channel.queryTransactionByID(txId);
		TxValidationCode validationCode = transaction.getValidationCode();
		if (validationCode != null) {
			tx.setValidationCode(validationCode.getNumber());
		}
		return FabricQueryResponse.success(tx);
	} catch (Exception e) {
		return FabricQueryResponse.failure(e.getLocalizedMessage());
	}
}