github.com/lzy4123/fabric@v2.1.1+incompatible/internal/peer/channel/signconfigtx.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package channel 8 9 import ( 10 "io/ioutil" 11 12 "github.com/hyperledger/fabric/protoutil" 13 "github.com/spf13/cobra" 14 ) 15 16 func signconfigtxCmd(cf *ChannelCmdFactory) *cobra.Command { 17 signconfigtxCmd := &cobra.Command{ 18 Use: "signconfigtx", 19 Short: "Signs a configtx update.", 20 Long: "Signs the supplied configtx update file in place on the filesystem. Requires '-f'.", 21 RunE: func(cmd *cobra.Command, args []string) error { 22 return sign(cmd, args, cf) 23 }, 24 } 25 flagList := []string{ 26 "file", 27 } 28 attachFlags(signconfigtxCmd, flagList) 29 30 return signconfigtxCmd 31 } 32 33 func sign(cmd *cobra.Command, args []string, cf *ChannelCmdFactory) error { 34 if channelTxFile == "" { 35 return InvalidCreateTx("No configtx file name supplied") 36 } 37 // Parsing of the command line is done so silence cmd usage 38 cmd.SilenceUsage = true 39 40 var err error 41 if cf == nil { 42 cf, err = InitCmdFactory(EndorserNotRequired, PeerDeliverNotRequired, OrdererNotRequired) 43 if err != nil { 44 return err 45 } 46 } 47 48 fileData, err := ioutil.ReadFile(channelTxFile) 49 if err != nil { 50 return ConfigTxFileNotFound(err.Error()) 51 } 52 53 ctxEnv, err := protoutil.UnmarshalEnvelope(fileData) 54 if err != nil { 55 return err 56 } 57 58 sCtxEnv, err := sanityCheckAndSignConfigTx(ctxEnv, cf.Signer) 59 if err != nil { 60 return err 61 } 62 63 sCtxEnvData := protoutil.MarshalOrPanic(sCtxEnv) 64 65 return ioutil.WriteFile(channelTxFile, sCtxEnvData, 0660) 66 }