def query_installed_chaincodes(self, requestor, peer_names, channel_name='mychannel', timeout=10): """ 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 channel_name: Name of the channel to send query to :return: A `ChaincodeQueryResponse` """ 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 response = Channel(channel_name, self).send_tx_proposal( tx_context, peers) queue = Queue(1) response.subscribe( on_next=lambda x: queue.put(x), on_error=lambda x: queue.put(x) ) try: res = queue.get(timeout=timeout) _logger.debug(res) response = res[0][0][0] if response.response: query_trans = query_pb2.ChaincodeQueryResponse() query_trans.ParseFromString(res[0][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 response except Exception: _logger.error( "Failed to query installed chaincodes: {}", sys.exc_info()[0]) raise
def query_instantiated_chaincodes(self, requestor, channel_name, peer_names, timeout=5): """ Queries instantiated chaincode :param requestor: User role who issue the request :param channel_name: name of channel to query :param peer_names: Names of the peers to query :return: A `ChaincodeQueryResponse` """ peers = [] for peer_name in peer_names: peer = self.get_peer(peer_name) peers.append(peer) channel = self.get_channel(channel_name) tx_context = create_tx_context(requestor, ecies(), TXProposalRequest()) response = channel.query_instantiated_chaincodes(tx_context, peers) queue = Queue(1) response.subscribe(on_next=lambda x: queue.put(x), on_error=lambda x: queue.put(x)) try: res = queue.get(timeout=timeout) _logger.debug(res) response = res[0][0][0] if response.response: query_trans = query_pb2.ChaincodeQueryResponse() query_trans.ParseFromString(res[0][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 response except Exception: _logger.error("Failed to query instantiated chaincodes: {}", sys.exc_info()[0]) raise
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
def query_instantiated_chaincodes(self, requestor, channel_name, peer_names, decode=True): """ Queries instantiated chaincode :param requestor: User role who issue the request :param channel_name: name of channel to query :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) channel = self.get_channel(channel_name) tx_context = create_tx_context(requestor, ecies(), TXProposalRequest()) responses = channel.query_instantiated_chaincodes(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 instantiated chaincodes: {}", sys.exc_info()[0]) raise