Пример #1
0
def _create_installment_proposal(tran_prop_req, signing_identity, chain):
    """Create a chaincode install proposal

    This involves assembling the proposal with the data (chaincodeID,
    chaincode invocation spec, etc.) and signing it using the private key
    corresponding to the ECert to sign.

    Args:
        chain: chain
        signing_identity: signing_identity
        tran_prop_req: see TransactionProposalRequest

    Returns: (Proposal): The created Proposal instance or None.

    """

    cc_deployment_spec = chaincode_pb2.ChaincodeDeploymentSpec()
    cc_deployment_spec.chaincode_spec.type = \
        chaincode_pb2.ChaincodeSpec.Type.Value('GOLANG')
    cc_deployment_spec.chaincode_spec.chaincode_id.name = \
        proto_str(tran_prop_req.chaincode_id)
    cc_deployment_spec.chaincode_spec.chaincode_id.path = \
        proto_str(tran_prop_req.chaincode_path)
    cc_deployment_spec.chaincode_spec.chaincode_id.version = \
        proto_str(tran_prop_req.chaincode_version)
    if not chain.is_dev_mode:
        cc_deployment_spec.code_package = _package_chaincode(
            tran_prop_req.chaincode_path) if not \
            tran_prop_req.chaincode_package else \
            tran_prop_req.chaincode_package
    cc_deployment_spec.effective_date.seconds = \
        tran_prop_req.effective_date.seconds
    cc_deployment_spec.effective_date.nanos = \
        tran_prop_req.effective_date.nanos

    header = build_header(signing_identity,
                          tran_prop_req.nonce,
                          common_pb2.ENDORSER_TRANSACTION,
                          chain,
                          tran_prop_req.prop_type,
                          chaincode_id="lscc")

    cci_spec = chaincode_pb2.ChaincodeInvocationSpec()
    cci_spec.chaincode_spec.type = \
        chaincode_pb2.ChaincodeSpec.Type.Value('GOLANG')
    cci_spec.chaincode_spec.chaincode_id.name = proto_str("lscc")
    cci_spec.chaincode_spec.input.args.extend(
        [proto_b(CC_INSTALL),
         cc_deployment_spec.SerializeToString()])
    proposal = build_proposal(cci_spec, header)

    return proposal, header
Пример #2
0
def _create_instantiation_proposal(tran_prop_req, chain):
    """Create a chaincode instantiation proposal

    This involves assembling the proposal with the data (chaincodeID,
    chaincode invocation spec, etc.) and signing it using the private key
    corresponding to the ECert to sign.

    Args:
        tran_prop_req: see TransactionProposalRequest

    Returns: (Proposal): The created Proposal instance or None.

    """
    args = ["init" if not tran_prop_req.fcn
            else tran_prop_req.fcn] + tran_prop_req.args

    cc_deployment_spec = chaincode_pb2.ChaincodeDeploymentSpec()
    cc_deployment_spec.chaincode_spec.type = \
        chaincode_pb2.ChaincodeSpec.Type.Value('GOLANG')
    cc_deployment_spec.chaincode_spec.chaincode_id.name = \
        proto_str(tran_prop_req.chaincode_id)
    cc_deployment_spec.chaincode_spec.chaincode_id.path = \
        proto_str(tran_prop_req.chaincode_path)
    cc_deployment_spec.chaincode_spec.chaincode_id.version = \
        proto_str(tran_prop_req.chaincode_version)
    cc_deployment_spec.chaincode_spec.input.args.extend(list(map(
        lambda x: proto_b(x), args)))

    header = build_header(tran_prop_req.signing_identity,
                          tran_prop_req.nonce,
                          common_pb2.ENDORSER_TRANSACTION,
                          chain,
                          tran_prop_req.prop_type,
                          chaincode_id=tran_prop_req.chaincode_id
                          )

    cci_spec = chaincode_pb2.ChaincodeInvocationSpec()
    cci_spec.chaincode_spec.type = \
        chaincode_pb2.ChaincodeSpec.Type.Value('GOLANG')
    cci_spec.chaincode_spec.chaincode_id.name = proto_str("lscc")
    cci_spec.chaincode_spec.input.args.extend(
        [proto_b(CC_INSTANTIATE), proto_b('default'),
         cc_deployment_spec.SerializeToString()])
    proposal = build_proposal(cci_spec, header)

    signed_proposal = sign_proposal(
        tran_prop_req.signing_identity, proposal)
    return signed_proposal
Пример #3
0
def _create_invocation_proposal(tran_prop_req, chain):
    """Create a chaincode invocation proposal

    This involves assembling the proposal with the data (chaincodeID,
    chaincode invocation spec, etc.) and signing it using the private key
    corresponding to the ECert to sign.

    Args:
        tran_prop_req: see TransactionProposalRequest

    Returns: (Proposal): The created Proposal instance or None.

    """
    args = ["invoke" if not tran_prop_req.fcn
            else tran_prop_req.fcn] + tran_prop_req.args

    if tran_prop_req.bytes_args:
        args += tran_prop_req.bytes_args

    header = build_header(tran_prop_req.signing_identity,
                          tran_prop_req.nonce,
                          common_pb2.ENDORSER_TRANSACTION,
                          chain,
                          tran_prop_req.prop_type,
                          chaincode_id=tran_prop_req.chaincode_id
                          )

    cci_spec = chaincode_pb2.ChaincodeInvocationSpec()
    cci_spec.chaincode_spec.type = \
        chaincode_pb2.ChaincodeSpec.Type.Value('GOLANG')
    cci_spec.chaincode_spec.chaincode_id.name = \
        proto_str(tran_prop_req.chaincode_id)
    cci_spec.chaincode_spec.chaincode_id.version = \
        proto_str(tran_prop_req.chaincode_version)
    cci_spec.chaincode_spec.input.args.extend(list(map(
        lambda x: proto_b(x), args)))
    proposal = build_proposal(cci_spec, header)

    signed_proposal = sign_proposal(
        tran_prop_req.signing_identity, proposal)
    return signed_proposal