Esempio n. 1
0
    def _build_channel_header(type,
                              tx_id,
                              channel_id,
                              timestamp,
                              epoch=0,
                              extension=None):
        """Build channel.

        Args:
            extension: extension
            timestamp: timestamp
            channel_id: channel id
            tx_id: transaction id
            type: type
            epoch: epoch

        Returns: common_proto.Header instance

        """
        channel_header = common_pb2.ChannelHeader()
        channel_header.type = type
        channel_header.version = 1
        channel_header.channel_id = proto_str(channel_id)
        channel_header.tx_id = proto_str(tx_id)
        channel_header.epoch = epoch
        channel_header.timestamp = timestamp
        if extension:
            channel_header.extension = extension

        return channel_header
Esempio n. 2
0
def build_channel_header(type, tx_id, channel_id,
                         timestamp, epoch=0, extension=None):
    """Build channel header.

    Args:
        type (common_pb2.HeaderType): type
        tx_id (str): transaction id
        channel_id (str): channel id
        timestamp (grpc.timestamp): timestamp
        epoch (int): epoch
        extension: extension

    Returns:
        common_proto.Header instance

    """
    channel_header = common_pb2.ChannelHeader()
    channel_header.type = type
    channel_header.version = 1
    channel_header.channel_id = proto_str(channel_id)
    channel_header.tx_id = proto_str(tx_id)
    channel_header.epoch = epoch
    channel_header.timestamp.CopyFrom(timestamp)
    if extension:
        channel_header.extension = extension
    return channel_header
Esempio n. 3
0
    def _build_channel_header(type,
                              tx_id,
                              channel_id,
                              timestamp,
                              epoch=0,
                              extension=None):
        """Build channel.

        :param extension: extension (Default value = None)
        :param timestamp: timestamp
        :param channel_id: channel id
        :param tx_id: transaction id
        :param type: type
        :param epoch: epoch
        :return: common_proto.Header instance (Default value = 0)
        """
        channel_header = common_pb2.ChannelHeader()
        channel_header.type = type
        channel_header.version = 1
        channel_header.channel_id = proto_str(channel_id)
        channel_header.tx_id = proto_str(tx_id)
        channel_header.epoch = epoch
        channel_header.timestamp = timestamp
        if extension:
            channel_header.extension = extension

        return channel_header
Esempio n. 4
0
def decode_channel_header(header_bytes):
    """Decodes channel header for Payload channel header

    :param header_bytes: Bytes channel header
    :return: deserialized payload channel_header
    :type header_bytes: str
    """
    channel_header = {}
    proto_channel_header = common_pb2.ChannelHeader()
    proto_channel_header.ParseFromString(header_bytes)
    channel_header['type'] = proto_channel_header.type
    channel_header['version'] = decode_version(proto_channel_header.version)
    channel_header['timestamp'] = \
        timestamp_to_date(proto_channel_header.timestamp)
    channel_header['channel_id'] = proto_channel_header.channel_id
    channel_header['tx_id'] = proto_channel_header.tx_id
    channel_header['epoch'] = proto_channel_header.epoch
    channel_header['extension'] = proto_channel_header.extension
    return channel_header
def build_header(creator,
                 nonce,
                 tran_prop_type,
                 chain,
                 prop_type,
                 epoch=0,
                 chaincode_id=None):
    """Build a header for transaction proposal.

    Args:
        prop_type: prop type
        creator: user
        nonce: nonce
        tran_prop_type: transaction proposal type
        chain: chain instance
        epoch: epoch
        chaincode_id: chaincode id

    Returns: common_proto.Header instance

    """
    header = common_pb2.Header()

    signature_header = common_pb2.SignatureHeader()
    signature_header.creator = creator.serialize()
    signature_header.nonce = nonce
    header.signature_header = signature_header.SerializeToString()

    channel_header = common_pb2.ChannelHeader()
    channel_header.type = tran_prop_type
    channel_header.version = 1
    if prop_type != CC_INSTALL:
        channel_header.channel_id = proto_str(chain.name)
    channel_header.tx_id = proto_str(chain.generate_tx_id(nonce, creator))
    channel_header.epoch = epoch
    if chaincode_id:
        header_ext = proposal_pb2.ChaincodeHeaderExtension()
        header_ext.chaincode_id.name = proto_str(chaincode_id)
        channel_header.extension = header_ext.SerializeToString()
    header.channel_header = channel_header.SerializeToString()

    return header
Esempio n. 6
0
def build_channel_header(type,
                         tx_id,
                         channel_id,
                         timestamp,
                         epoch=0,
                         extension=None,
                         tls_cert_hash=None):
    """Build channel header.

    :param type: type
    :type type: common_pb2.HeaderType
    :param tx_id: transaction id
    :type tx_id: str
    :param channel_id: channel id
    :type channel_id: str
    :param timestamp: timestamp
    :type timestamp: grpc.timestamp
    :param epoch: epoch (Default value = 0)
    :type epoch: int
    :param extension: extension (Default value = None)
    :param tls_cert_hash:  (Default value = None)
    :return: common_proto.Header instance
    """
    channel_header = common_pb2.ChannelHeader()
    channel_header.type = type
    channel_header.version = 1
    channel_header.channel_id = proto_str(channel_id)
    channel_header.tx_id = proto_str(tx_id)
    channel_header.epoch = epoch
    channel_header.timestamp.CopyFrom(timestamp)

    if tls_cert_hash:
        channel_header.tls_cert_hash = tls_cert_hash

    if extension:
        channel_header.extension = extension
    return channel_header