Пример #1
0
    def query_channels(self, requestor, peer_names, request_channel='mychannel', timeout=10):
        """
        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 request_channel: Name of the channel that the query sent to
        :return: A `ChannelQueryResponse`
        """

        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

        response = Channel(request_channel, 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.ChannelQueryResponse()
                query_trans.ParseFromString(res[0][0][0].response.payload)
                for ch in query_trans.channels:
                    _logger.debug('channel id {}'.format(
                        ch.channel_id))
                return query_trans
            return response

        except Exception:
            _logger.error(
                "Failed to query channel: {}", sys.exc_info()[0])
            raise
Пример #2
0
    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
Пример #3
0
    def new_channel(self, name):
        """Init a channel instance with given name.

        :param name: The name of channel

        :return: The inited channel instance

        """
        _logger.debug("New channel with name = {}".format(name))
        if name not in self._channels:
            self._channels[name] = Channel(name, self)
        return self._channels[name]
Пример #4
0
    def new_channel(self, name):
        """Create a channel handler instance with given name.

        Args:
            name (str): The name of the channel.

        Returns:
            channel: The inited channel.

        """
        _logger.debug("New channel with name = {}".format(name))
        if name not in self._channels:
            self._channels[name] = Channel(name, self)
        return self._channels[name]
Пример #5
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
Пример #6
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
                          key_path=key_path,
                          cert_path=cert_path)

client = Client()

print(client.query_peers(admin_owkin, peer1_owkin))
print(
    client.query_peers(admin_owkin,
                       peer1_owkin,
                       channel='mychannel',
                       local=False))

client.init_with_discovery(admin_owkin, peer1_owkin, 'mychannel')

response = Channel('', '')._discovery(admin_owkin,
                                      peer1_owkin,
                                      config=False,
                                      local=True)

response = Channel('mychannel', '')._discovery(admin_owkin,
                                               peer1_owkin,
                                               config=True,
                                               local=False)


def process_config_result(config_result):

    results = {'msps': {}, 'orderers': {}}

    for msp_name in config_result.msps:
        results['msps'][msp_name] = decode_fabric_MSP_config(
            config_result.msps[msp_name].SerializeToString())
Пример #8
0
 def test_create_channel(self):
     # TODO impl
     channel = Channel()
     channel.add_orderer(Orderer())
     self.fail()