github.com/darrenli6/fabric-sdk-example@v0.0.0-20220109053535-94b13b56df8c/bddtests/chaincode.go (about)

     1  /*
     2  Copyright IBM Corp. 2016 All Rights Reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  		 http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package bddtests
    18  
    19  import (
    20  	"fmt"
    21  
    22  	"github.com/golang/protobuf/proto"
    23  	"github.com/hyperledger/fabric/common/util"
    24  	"github.com/hyperledger/fabric/protos/common"
    25  	pb "github.com/hyperledger/fabric/protos/peer"
    26  	putils "github.com/hyperledger/fabric/protos/utils"
    27  )
    28  
    29  func createChaincodeSpec(ccType string, path string, args [][]byte) *pb.ChaincodeSpec {
    30  	// make chaincode spec for chaincode to be deployed
    31  	ccSpec := &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value[ccType]),
    32  		ChaincodeId: &pb.ChaincodeID{Path: path},
    33  		Input:       &pb.ChaincodeInput{Args: args}}
    34  	return ccSpec
    35  
    36  }
    37  
    38  // createChaincodeDeploymentSpec  Returns a deployment proposal of chaincode type
    39  func createProposalForChaincode(ccChaincodeDeploymentSpec *pb.ChaincodeDeploymentSpec, creator []byte) (proposal *pb.Proposal, err error) {
    40  	var ccDeploymentSpecBytes []byte
    41  	if ccDeploymentSpecBytes, err = proto.Marshal(ccChaincodeDeploymentSpec); err != nil {
    42  		return nil, fmt.Errorf("Error creating proposal from ChaincodeDeploymentSpec:  %s", err)
    43  	}
    44  	lcChaincodeSpec := &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_GOLANG,
    45  		ChaincodeId: &pb.ChaincodeID{Name: "lscc"},
    46  		Input:       &pb.ChaincodeInput{Args: [][]byte{[]byte("deploy"), []byte("default"), ccDeploymentSpecBytes}}}
    47  	lcChaincodeInvocationSpec := &pb.ChaincodeInvocationSpec{ChaincodeSpec: lcChaincodeSpec}
    48  
    49  	// make proposal
    50  	proposal, _, err = putils.CreateChaincodeProposal(common.HeaderType_ENDORSER_TRANSACTION, util.GetTestChainID(), lcChaincodeInvocationSpec, creator)
    51  
    52  	return
    53  }