github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/orderer/common/channelparticipation/validator.go (about) 1 /* 2 Copyright hechain. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package channelparticipation 8 9 import ( 10 "errors" 11 12 "github.com/hechain20/hechain/bccsp/factory" 13 "github.com/hechain20/hechain/common/channelconfig" 14 "github.com/hechain20/hechain/protoutil" 15 cb "github.com/hyperledger/fabric-protos-go/common" 16 ) 17 18 // ValidateJoinBlock checks whether this block can be used as a join block for the channel participation API. 19 // It returns the channel ID, and whether it is an system channel if it contains consortiums, or otherwise 20 // an application channel if an application group exists. It returns an error when it cannot be used as a join-block. 21 func ValidateJoinBlock(configBlock *cb.Block) (channelID string, isAppChannel bool, err error) { 22 if !protoutil.IsConfigBlock(configBlock) { 23 return "", false, errors.New("block is not a config block") 24 } 25 26 envelope, err := protoutil.ExtractEnvelope(configBlock, 0) 27 if err != nil { 28 return "", false, err 29 } 30 31 cryptoProvider := factory.GetDefault() 32 bundle, err := channelconfig.NewBundleFromEnvelope(envelope, cryptoProvider) 33 if err != nil { 34 return "", false, err 35 } 36 37 channelID = bundle.ConfigtxValidator().ChannelID() 38 39 // Check channel type 40 _, isSystemChannel := bundle.ConsortiumsConfig() 41 if !isSystemChannel { 42 _, isAppChannel = bundle.ApplicationConfig() 43 if !isAppChannel { 44 return "", false, errors.New("invalid config: must have at least one of application or consortiums") 45 } 46 } 47 48 return channelID, isAppChannel, err 49 }