github.com/leonlxy/hyperledger@v1.0.0-alpha.0.20170427033203-34922035d248/peer/chaincode/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 chaincode
    18  
    19  import (
    20  	"fmt"
    21  
    22  	"github.com/hyperledger/fabric/common/flogging"
    23  	"github.com/hyperledger/fabric/common/util"
    24  	"github.com/hyperledger/fabric/peer/common"
    25  	"github.com/spf13/cobra"
    26  )
    27  
    28  const (
    29  	chainFuncName = "chaincode"
    30  )
    31  
    32  var logger = flogging.MustGetLogger("chaincodeCmd")
    33  
    34  func AddFlags(cmd *cobra.Command) {
    35  	flags := cmd.PersistentFlags()
    36  
    37  	flags.StringVarP(&chaincodeLang, "lang", "l", "golang",
    38  		fmt.Sprintf("Language the %s is written in", chainFuncName))
    39  	flags.StringVarP(&chaincodeCtorJSON, "ctor", "c", "{}",
    40  		fmt.Sprintf("Constructor message for the %s in JSON format", chainFuncName))
    41  	flags.StringVarP(&chaincodePath, "path", "p", common.UndefinedParamValue,
    42  		fmt.Sprintf("Path to %s", chainFuncName))
    43  	flags.StringVarP(&chaincodeName, "name", "n", common.UndefinedParamValue,
    44  		fmt.Sprint("Name of the chaincode"))
    45  	flags.StringVarP(&chaincodeVersion, "version", "v", common.UndefinedParamValue,
    46  		fmt.Sprint("Version of the chaincode specified in install/instantiate/upgrade commands"))
    47  	flags.StringVarP(&chaincodeUsr, "username", "u", common.UndefinedParamValue,
    48  		fmt.Sprint("Username for chaincode operations when security is enabled"))
    49  	flags.StringVarP(&customIDGenAlg, "tid", "t", common.UndefinedParamValue,
    50  		fmt.Sprint("Name of a custom ID generation algorithm (hashing and decoding) e.g. sha256base64"))
    51  	flags.StringVarP(&chainID, "chainID", "C", util.GetTestChainID(),
    52  		fmt.Sprint("The chain on which this command should be executed"))
    53  	flags.StringVarP(&policy, "policy", "P", common.UndefinedParamValue,
    54  		fmt.Sprint("The endorsement policy associated to this chaincode"))
    55  	flags.StringVarP(&escc, "escc", "E", common.UndefinedParamValue,
    56  		fmt.Sprint("The name of the endorsement system chaincode to be used for this chaincode"))
    57  	flags.StringVarP(&vscc, "vscc", "V", common.UndefinedParamValue,
    58  		fmt.Sprint("The name of the verification system chaincode to be used for this chaincode"))
    59  	flags.StringVarP(&orderingEndpoint, "orderer", "o", "", "Ordering service endpoint")
    60  	flags.BoolVarP(&tls, "tls", "", false, "Use TLS when communicating with the orderer endpoint")
    61  	flags.StringVarP(&caFile, "cafile", "", "", "Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint")
    62  }
    63  
    64  // Cmd returns the cobra command for Chaincode
    65  func Cmd(cf *ChaincodeCmdFactory) *cobra.Command {
    66  	AddFlags(chaincodeCmd)
    67  
    68  	chaincodeCmd.AddCommand(instantiateCmd(cf))
    69  	chaincodeCmd.AddCommand(invokeCmd(cf))
    70  	chaincodeCmd.AddCommand(queryCmd(cf))
    71  	chaincodeCmd.AddCommand(upgradeCmd(cf))
    72  	chaincodeCmd.AddCommand(packageCmd(cf, nil))
    73  	chaincodeCmd.AddCommand(installCmd(cf))
    74  	chaincodeCmd.AddCommand(signpackageCmd(cf))
    75  
    76  	return chaincodeCmd
    77  }
    78  
    79  // Chaincode-related variables.
    80  var (
    81  	chaincodeLang     string
    82  	chaincodeCtorJSON string
    83  	chaincodePath     string
    84  	chaincodeName     string
    85  	chaincodeUsr      string
    86  	chaincodeQueryRaw bool
    87  	chaincodeQueryHex bool
    88  	customIDGenAlg    string
    89  	chainID           string
    90  	chaincodeVersion  string
    91  	policy            string
    92  	escc              string
    93  	vscc              string
    94  	policyMarhsalled  []byte
    95  	orderingEndpoint  string
    96  	tls               bool
    97  	caFile            string
    98  )
    99  
   100  var chaincodeCmd = &cobra.Command{
   101  	Use:   chainFuncName,
   102  	Short: fmt.Sprintf("%s specific commands.", chainFuncName),
   103  	Long:  fmt.Sprintf("%s specific commands.", chainFuncName),
   104  }