github.com/adnan-c/fabric_e2e_couchdb@v0.6.1-preview.0.20170228180935-21ce6b23cf91/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/util" 23 "github.com/hyperledger/fabric/peer/common" 24 "github.com/op/go-logging" 25 "github.com/spf13/cobra" 26 ) 27 28 const ( 29 chainFuncName = "chaincode" 30 ) 31 32 var logger = logging.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 } 60 61 // Cmd returns the cobra command for Chaincode 62 func Cmd(cf *ChaincodeCmdFactory) *cobra.Command { 63 AddFlags(chaincodeCmd) 64 65 chaincodeCmd.AddCommand(instantiateCmd(cf)) 66 chaincodeCmd.AddCommand(invokeCmd(cf)) 67 chaincodeCmd.AddCommand(queryCmd(cf)) 68 chaincodeCmd.AddCommand(upgradeCmd(cf)) 69 chaincodeCmd.AddCommand(packageCmd(cf)) 70 chaincodeCmd.AddCommand(installCmd(cf)) 71 72 return chaincodeCmd 73 } 74 75 // Chaincode-related variables. 76 var ( 77 chaincodeLang string 78 chaincodeCtorJSON string 79 chaincodePath string 80 chaincodeName string 81 chaincodeUsr string 82 chaincodeQueryRaw bool 83 chaincodeQueryHex bool 84 customIDGenAlg string 85 chainID string 86 chaincodeVersion string 87 policy string 88 escc string 89 vscc string 90 policyMarhsalled []byte 91 ) 92 93 var chaincodeCmd = &cobra.Command{ 94 Use: chainFuncName, 95 Short: fmt.Sprintf("%s specific commands.", chainFuncName), 96 Long: fmt.Sprintf("%s specific commands.", chainFuncName), 97 }