github.com/kchristidis/fabric@v1.0.4-0.20171028114726-837acd08cde1/peer/channel/update.go (about) 1 /* 2 Copyright IBM Corp. 2017 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 channel 18 19 import ( 20 "fmt" 21 "io/ioutil" 22 23 "errors" 24 25 "github.com/hyperledger/fabric/peer/common" 26 "github.com/hyperledger/fabric/protos/utils" 27 28 "github.com/spf13/cobra" 29 ) 30 31 func updateCmd(cf *ChannelCmdFactory) *cobra.Command { 32 updateCmd := &cobra.Command{ 33 Use: "update", 34 Short: "Send a configtx update.", 35 Long: "Signs and sends the supplied configtx update file to the channel. Requires '-f', '-o', '-c'.", 36 RunE: func(cmd *cobra.Command, args []string) error { 37 return update(cmd, args, cf) 38 }, 39 } 40 flagList := []string{ 41 "channelID", 42 "file", 43 } 44 attachFlags(updateCmd, flagList) 45 46 return updateCmd 47 } 48 49 func update(cmd *cobra.Command, args []string, cf *ChannelCmdFactory) error { 50 //the global chainID filled by the "-c" command 51 if chainID == common.UndefinedParamValue { 52 return errors.New("Must supply channel ID") 53 } 54 55 if channelTxFile == "" { 56 return InvalidCreateTx("No configtx file name supplied") 57 } 58 59 var err error 60 if cf == nil { 61 cf, err = InitCmdFactory(EndorserNotRequired, OrdererRequired) 62 if err != nil { 63 return err 64 } 65 } 66 67 fileData, err := ioutil.ReadFile(channelTxFile) 68 if err != nil { 69 return ConfigTxFileNotFound(err.Error()) 70 } 71 72 ctxEnv, err := utils.UnmarshalEnvelope(fileData) 73 if err != nil { 74 return err 75 } 76 77 sCtxEnv, err := sanityCheckAndSignConfigTx(ctxEnv) 78 if err != nil { 79 return err 80 } 81 82 var broadcastClient common.BroadcastClient 83 broadcastClient, err = cf.BroadcastFactory() 84 if err != nil { 85 return fmt.Errorf("Error getting broadcast client: %s", err) 86 } 87 88 defer broadcastClient.Close() 89 return broadcastClient.Send(sCtxEnv) 90 }