コード例 #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
コード例 #2
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
コード例 #3
0
ファイル: endorser_impl.py プロジェクト: 0yukikaze0/fabric
def step_impl(context, enrollId, ccDeploymentSpecAlias, ccSpecAlias, devopsComposeService):
	userRegistration = bdd_test_util.getUserRegistration(context, enrollId)
	assert ccSpecAlias in userRegistration.tags, "ChaincodeSpec alias '{0}' not found for user '{1}'".format(ccSpecAlias, enrollId)

	ipAddress = bdd_test_util.ipFromContainerNamePart(devopsComposeService, context.compose_containers)
	channel = bdd_grpc_util.getGRPCChannel(ipAddress)
	devopsStub = devops_pb2.beta_create_Devops_stub(channel)
	deploymentSpec = devopsStub.Build(userRegistration.tags[ccSpecAlias],20)
	userRegistration.tags[ccDeploymentSpecAlias] = deploymentSpec
コード例 #4
0
ファイル: endorser_impl.py プロジェクト: conseweb/fabric
def step_impl(context, userName, ccDeploymentSpecAlias, ccSpecAlias, devopsComposeService):
    directory = bootstrap_util.getDirectory(context=context)
    user = directory.getUser(userName=userName)
    assert ccSpecAlias in user.tags, "ChaincodeSpec alias '{0}' not found for user '{1}'".format(ccSpecAlias, userName)

    ipAddress = bdd_test_util.ipFromContainerNamePart(devopsComposeService, context.compose_containers)
    channel = bdd_grpc_util.getGRPCChannel(ipAddress)
    devopsStub = devops_pb2.beta_create_Devops_stub(channel)
    deploymentSpec = devopsStub.Build(user.tags[ccSpecAlias],20)
    user.tags[ccDeploymentSpecAlias] = deploymentSpec
コード例 #5
0
ファイル: chaincode_rbac_impl.py プロジェクト: Liamsi/fabric
def step_impl(context, enrollId):
	assert 'users' in context, "users not found in context. Did you register a user?"
	(channel, userRegistration) = bdd_test_util.getGRPCChannelAndUser(context, enrollId)
	
	stub = devops_pb2.beta_create_Devops_stub(channel)

	secret = userRegistration.getSecret()
	response = stub.EXP_GetApplicationTCert(secret,2)
	assert response.status == fabric_pb2.Response.SUCCESS, 'Failure getting TCert from {0}, for user "{1}":  {2}'.format(userRegistration.composeService,enrollId, response.msg)
	tcert = response.msg

	userRegistration.lastResult = tcert
コード例 #6
0
def step_impl(context, enrollId, ccDeploymentSpecAlias, ccSpecAlias,
              devopsComposeService):
    userRegistration = bdd_test_util.getUserRegistration(context, enrollId)
    assert ccSpecAlias in userRegistration.tags, "ChaincodeSpec alias '{0}' not found for user '{1}'".format(
        ccSpecAlias, enrollId)

    ipAddress = bdd_test_util.ipFromContainerNamePart(
        devopsComposeService, context.compose_containers)
    channel = bdd_grpc_util.getGRPCChannel(ipAddress)
    devopsStub = devops_pb2.beta_create_Devops_stub(channel)
    deploymentSpec = devopsStub.Build(userRegistration.tags[ccSpecAlias], 20)
    userRegistration.tags[ccDeploymentSpecAlias] = deploymentSpec
コード例 #7
0
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
コード例 #8
0
def step_impl(context, userName, ccDeploymentSpecAlias, ccSpecAlias,
              devopsComposeService):
    directory = bootstrap_util.getDirectory(context=context)
    user = directory.getUser(userName=userName)
    assert ccSpecAlias in user.tags, "ChaincodeSpec alias '{0}' not found for user '{1}'".format(
        ccSpecAlias, userName)

    ipAddress = bdd_test_util.ipFromContainerNamePart(
        devopsComposeService, context.compose_containers)
    channel = bdd_grpc_util.getGRPCChannel(ipAddress)
    devopsStub = devops_pb2.beta_create_Devops_stub(channel)
    deploymentSpec = devopsStub.Build(user.tags[ccSpecAlias], 20)
    user.tags[ccDeploymentSpecAlias] = deploymentSpec
コード例 #9
0
def step_impl(context, enrollId):
    assert 'users' in context, "users not found in context. Did you register a user?"
    (channel, userRegistration) = bdd_grpc_util.getGRPCChannelAndUser(
        context, enrollId)

    stub = devops_pb2.beta_create_Devops_stub(channel)

    secret = bdd_grpc_util.getSecretForUserRegistration(userRegistration)
    response = stub.EXP_GetApplicationTCert(secret, 2)
    assert response.status == fabric_pb2.Response.SUCCESS, 'Failure getting TCert from {0}, for user "{1}":  {2}'.format(
        userRegistration.composeService, enrollId, response.msg)
    tcert = response.msg

    userRegistration.lastResult = tcert
コード例 #10
0
ファイル: bdd_grpc_util.py プロジェクト: OlegIakovlev/fabric
def getTxResult(context, enrollId):
    '''Returns the TransactionResult using the enrollId supplied'''
    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) = getGRPCChannelAndUser(context, enrollId)
    stub = devops_pb2.beta_create_Devops_stub(channel)

    txRequest = devops_pb2.TransactionRequest(transactionUuid = context.transactionID)
    response = stub.GetTransactionResult(txRequest, 2)
    assert response.status == fabric_pb2.Response.SUCCESS, 'Failure getting Transaction Result from {0}, for user "{1}":  {2}'.format(userRegistration.composeService,enrollId, response.msg)
    # Now grab the TransactionResult from the Msg bytes
    txResult = fabric_pb2.TransactionResult()
    txResult.ParseFromString(response.msg)
    return txResult
コード例 #11
0
def getTxResult(context, enrollId):
    '''Returns the TransactionResult using the enrollId supplied'''
    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) = getGRPCChannelAndUser(context, enrollId)
    stub = devops_pb2.beta_create_Devops_stub(channel)

    txRequest = devops_pb2.TransactionRequest(transactionUuid = context.transactionID)
    response = stub.GetTransactionResult(txRequest, 2)
    assert response.status == fabric_pb2.Response.SUCCESS, 'Failure getting Transaction Result from {0}, for user "{1}":  {2}'.format(userRegistration.composeService,enrollId, response.msg)
    # Now grab the TransactionResult from the Msg bytes
    txResult = fabric_pb2.TransactionResult()
    txResult.ParseFromString(response.msg)
    return txResult
コード例 #12
0
ファイル: chaincode_rbac_impl.py プロジェクト: Liamsi/fabric
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_test_util.getGRPCChannelAndUser(context, enrollId)

	stub = devops_pb2.beta_create_Devops_stub(channel)

	# First get binding with EXP_PrepareForTx
	secret = userRegistration.getSecret()
	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
コード例 #13
0
ファイル: bdd_grpc_util.py プロジェクト: OlegIakovlev/fabric
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
コード例 #14
0
ファイル: bdd_grpc_util.py プロジェクト: OlegIakovlev/fabric
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