def decode_config_envelope(config_envelope_bytes): """Decodes configuration envelope Args: config_envelope_bytes: byte of config envelope Returns: deserialized config envelope """ config_envelope = {} proto_config_envelope = configtx_pb2.ConfigEnvelope() proto_config_envelope.ParseFromString(config_envelope_bytes) config_envelope['config'] = decode_config(proto_config_envelope.config) config_envelope['last_update'] = {} proto_last_update = proto_config_envelope.last_update if proto_last_update: config_envelope['last_update']['payload'] = {} proto_payload = common_pb2.Payload() proto_payload.ParseFromString(proto_last_update.payload) config_envelope['last_update']['payload']['header'] = \ decode_header(proto_payload.header) config_envelope['last_update']['payload']['data'] = \ decode_config_update_envelope(proto_payload.data) config_envelope['last_update']['signature'] = \ proto_last_update.signature return config_envelope
def get_channel_config(self, requestor, channel_name, peer_names, decode=True): """ Get configuration block for the channel :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.get_channel_config(tx_context, peers) try: if responses[0][0].response and decode: _logger.debug('response status {}'.format( responses[0][0].response.status)) block = common_pb2.Block() block.ParseFromString(responses[0][0].response.payload) envelope = common_pb2.Envelope() envelope.ParseFromString(block.data.data[0]) payload = common_pb2.Payload() payload.ParseFromString(envelope.payload) config_envelope = configtx_pb2.ConfigEnvelope() config_envelope.ParseFromString(payload.data) return config_envelope return responses[0][0] except Exception: _logger.error("Failed to get channel config block: {}", sys.exc_info()[0]) raise