All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hyperledger.fabric.shim.impl.QueryResultsIteratorWithMetadataImpl Maven / Gradle / Ivy

There is a newer version: 2.5.3
Show newest version
/*
Copyright IBM Corp. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/

package org.hyperledger.fabric.shim.impl;

import java.util.function.Function;
import java.util.logging.Logger;

import org.hyperledger.fabric.protos.peer.ChaincodeShim;
import org.hyperledger.fabric.protos.peer.ChaincodeShim.QueryResponse;
import org.hyperledger.fabric.protos.peer.ChaincodeShim.QueryResultBytes;
import org.hyperledger.fabric.shim.ledger.QueryResultsIteratorWithMetadata;

import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;

/**
 * Implementation of {@link QueryResultsIteratorWithMetadata}, by extending {@link org.hyperledger.fabric.shim.ledger.QueryResultsIterator} implementations, {@link QueryResultsIteratorImpl}
 *
 * @param 
 */
public class QueryResultsIteratorWithMetadataImpl extends QueryResultsIteratorImpl implements QueryResultsIteratorWithMetadata {
    private static Logger logger = Logger.getLogger(QueryResultsIteratorWithMetadataImpl.class.getName());

    ChaincodeShim.QueryResponseMetadata metadata;

    public QueryResultsIteratorWithMetadataImpl(final ChaincodeInnvocationTask handler,
			final String channelId, final String txId, final ByteString responseBuffer,
			Function mapper) {
        super(handler,channelId,txId,responseBuffer,mapper);
        try {
        	QueryResponse queryResponse = QueryResponse.parseFrom(responseBuffer);
            metadata = ChaincodeShim.QueryResponseMetadata.parseFrom(queryResponse.getMetadata());
        } catch (InvalidProtocolBufferException e) {
            logger.warning("can't parse response metadata");
            throw new RuntimeException(e);
        }
    }

    @Override
    public ChaincodeShim.QueryResponseMetadata getMetadata() {
        return metadata;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy