Beispiel #1
0
def deployChaincode(context, enrollId, chaincodePath, ccAlias, ctor):
    '''Deploy a chaincode with the specified alias for the specfied enrollId'''
    (channel, userRegistration) = getGRPCChannelAndUser(context, enrollId)
    stub = devops_pb2.beta_create_Devops_stub(channel)

    # Make sure deployment alias does NOT already exist
    assert getDeployment(
        context,
        ccAlias) == None, "Deployment alias already exists: '{0}'.".format(
            ccAlias)

    args = getArgsFromContextForUser(context, enrollId)
    ccSpec = chaincode_pb2.ChaincodeSpec(
        type=chaincode_pb2.ChaincodeSpec.GOLANG,
        chaincodeID=chaincode_pb2.ChaincodeID(name="", path=chaincodePath),
        ctorMsg=chaincode_pb2.ChaincodeInput(function=ctor, args=args))
    ccSpec.secureContext = userRegistration.getUserName()
    if 'metadata' in context:
        ccSpec.metadata = context.metadata
    try:
        ccDeploymentSpec = stub.Deploy(ccSpec, 60)
        ccSpec.chaincodeID.name = ccDeploymentSpec.chaincodeSpec.chaincodeID.name
        context.grpcChaincodeSpec = ccSpec
        context.deployments[ccAlias] = ccSpec
    except:
        del stub
        raise
def getChaincodeSpec(ccType, path, args):
    # make chaincode spec for chaincode to be deployed
    ccSpec = chaincode_pb2.ChaincodeSpec(
        type=ccType,
        chaincodeID=chaincode_pb2.ChaincodeID(path=path),
        ctorMsg=chaincode_pb2.ChaincodeInput(args=args))
    return ccSpec
Beispiel #3
0
def invokeChaincode(context, enrollId, ccAlias, functionName):
    # Get the deployment for the supplied chaincode alias
    deployedCcSpec = getDeployment(context, ccAlias)
    assert deployedCcSpec != None, "Deployment NOT found for chaincode alias '{0}'".format(
        ccAlias)

    # Create a new ChaincodeSpec by copying the deployed one
    newChaincodeSpec = chaincode_pb2.ChaincodeSpec()
    newChaincodeSpec.CopyFrom(deployedCcSpec)

    # Update hte chaincodeSpec ctorMsg for invoke
    args = getArgsFromContextForUser(context, enrollId)

    chaincodeInput = chaincode_pb2.ChaincodeInput(function=functionName,
                                                  args=args)
    newChaincodeSpec.ctorMsg.CopyFrom(chaincodeInput)

    ccInvocationSpec = chaincode_pb2.ChaincodeInvocationSpec(
        chaincodeSpec=newChaincodeSpec)

    (channel, userRegistration) = getGRPCChannelAndUser(context, enrollId)

    stub = devops_pb2.beta_create_Devops_stub(channel)
    response = stub.Invoke(ccInvocationSpec, 2)
    return response
def step_impl(context, enrollId, assignerAppTCert, role, assigneeAppTCert):
    assert 'users' in context, "users not found in context. Did you register a user?"
    assert 'compose_containers' in context, "compose_containers not found in context"

    (channel, userRegistration) = bdd_grpc_util.getGRPCChannelAndUser(
        context, enrollId)

    stub = devops_pb2.beta_create_Devops_stub(channel)

    # First get binding with EXP_PrepareForTx
    secret = bdd_grpc_util.getSecretForUserRegistration(userRegistration)
    response = stub.EXP_PrepareForTx(secret, 2)
    assert response.status == fabric_pb2.Response.SUCCESS, 'Failure getting Binding from {0}, for user "{1}":  {2}'.format(
        userRegistration.composeService, enrollId, response.msg)
    binding = response.msg

    # Now produce the sigma EXP_ProduceSigma
    chaincodeInput = chaincode_pb2.ChaincodeInput(
        function="addRole",
        args=(base64.b64encode(userRegistration.tags[assigneeAppTCert]), role))
    chaincodeInputRaw = chaincodeInput.SerializeToString()
    appTCert = userRegistration.tags[assignerAppTCert]
    sigmaInput = devops_pb2.SigmaInput(secret=secret,
                                       appTCert=appTCert,
                                       data=chaincodeInputRaw + binding)
    response = stub.EXP_ProduceSigma(sigmaInput, 2)
    assert response.status == fabric_pb2.Response.SUCCESS, 'Failure prducing sigma from {0}, for user "{1}":  {2}'.format(
        userRegistration.composeService, enrollId, response.msg)
    sigmaOutputBytes = response.msg
    # Parse the msg bytes as a SigmaOutput message
    sigmaOutput = devops_pb2.SigmaOutput()
    sigmaOutput.ParseFromString(sigmaOutputBytes)
    print('Length of sigma = {0}'.format(len(sigmaOutput.sigma)))

    # Now execute the transaction with the saved binding, EXP_ExecuteWithBinding
    assert "grpcChaincodeSpec" in context, "grpcChaincodeSpec NOT found in context"
    newChaincodeSpec = chaincode_pb2.ChaincodeSpec()
    newChaincodeSpec.CopyFrom(context.grpcChaincodeSpec)
    newChaincodeSpec.metadata = sigmaOutput.asn1Encoding
    newChaincodeSpec.ctorMsg.CopyFrom(chaincodeInput)

    ccInvocationSpec = chaincode_pb2.ChaincodeInvocationSpec(
        chaincodeSpec=newChaincodeSpec)

    executeWithBinding = devops_pb2.ExecuteWithBinding(
        chaincodeInvocationSpec=ccInvocationSpec, binding=binding)

    response = stub.EXP_ExecuteWithBinding(executeWithBinding, 60)
    assert response.status == fabric_pb2.Response.SUCCESS, 'Failure executeWithBinding from {0}, for user "{1}":  {2}'.format(
        userRegistration.composeService, enrollId, response.msg)
    context.response = response
    context.transactionID = response.msg
def createDeploymentProposalForBDD(ccDeploymentSpec):
    "Returns a deployment proposal of chaincode type"
    lc_chaincode_spec = chaincode_pb2.ChaincodeSpec(
        type=chaincode_pb2.ChaincodeSpec.GOLANG,
        chaincodeID=chaincode_pb2.ChaincodeID(name="lccc"),
        ctorMsg=chaincode_pb2.ChaincodeInput(
            args=['deploy', 'default',
                  ccDeploymentSpec.SerializeToString()]))
    lc_chaincode_invocation_spec = chaincode_pb2.ChaincodeInvocationSpec(
        chaincodeSpec=lc_chaincode_spec)
    # make proposal
    proposal = fabric_next_pb2.Proposal(
        type=fabric_next_pb2.Proposal.CHAINCODE, id=createPropsalId())
    proposal.payload = lc_chaincode_invocation_spec.SerializeToString()
    return proposal