예제 #1
0
    def query_installed_chaincodes(self, requestor, peer_names, decode=True):
        """
        Queries installed chaincode, returns all chaincodes installed on a peer

        :param requestor: User role who issue the request
        :param peer_names: Names of the peers to query
        :param deocode: Decode the response payload
        :return: A `ChaincodeQueryResponse` or `ProposalResponse`
        """
        peers = []
        for peer_name in peer_names:
            peer = self.get_peer(peer_name)
            peers.append(peer)

        request = create_tx_prop_req(prop_type=CC_QUERY,
                                     fcn='getinstalledchaincodes',
                                     cc_name='lscc',
                                     cc_type=CC_TYPE_GOLANG,
                                     args=[])

        tx_context = create_tx_context(requestor, ecies(), TXProposalRequest())
        tx_context.tx_prop_req = request

        responses = Channel._send_tx_proposal('', tx_context, peers)

        try:
            if responses[0][0].response and decode:
                query_trans = query_pb2.ChaincodeQueryResponse()
                query_trans.ParseFromString(responses[0][0].response.payload)
                for cc in query_trans.chaincodes:
                    _logger.debug('cc name {}, version {}, path {}'.format(
                        cc.name, cc.version, cc.path))
                return query_trans
            return responses[0][0]

        except Exception:
            _logger.error("Failed to query installed chaincodes: {}",
                          sys.exc_info()[0])
            raise
예제 #2
0
    def query_channels(self, requestor, peer_names, decode=True):
        """
        Queries channel name joined by a peer

        :param requestor: User role who issue the request
        :param peer_names: Names of the peers to install
        :param deocode: Decode the response payload
        :return: A `ChannelQueryResponse` or `ProposalResponse`
        """

        peers = []
        for peer_name in peer_names:
            peer = self.get_peer(peer_name)
            peers.append(peer)

        request = create_tx_prop_req(prop_type=CC_QUERY,
                                     fcn='GetChannels',
                                     cc_name='cscc',
                                     cc_type=CC_TYPE_GOLANG,
                                     args=[])

        tx_context = create_tx_context(requestor, ecies(), TXProposalRequest())
        tx_context.tx_prop_req = request

        responses = Channel._send_tx_proposal('', tx_context, peers)

        try:
            if responses[0][0].response and decode:
                query_trans = query_pb2.ChannelQueryResponse()
                query_trans.ParseFromString(responses[0][0].response.payload)
                for ch in query_trans.channels:
                    _logger.debug('channel id {}'.format(ch.channel_id))
                return query_trans
            return responses[0][0]

        except Exception:
            _logger.error("Failed to query channel: {}", sys.exc_info()[0])
            raise