github.com/yacovm/fabric@v2.0.0-alpha.0.20191128145320-c5d4087dc723+incompatible/common/capabilities/channel.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package capabilities 8 9 import ( 10 cb "github.com/hyperledger/fabric-protos-go/common" 11 "github.com/hyperledger/fabric/msp" 12 ) 13 14 const ( 15 channelTypeName = "Channel" 16 17 // ChannelV1_1 is the capabilities string for standard new non-backwards compatible fabric v1.1 channel capabilities. 18 ChannelV1_1 = "V1_1" 19 20 // ChannelV1_3 is the capabilities string for standard new non-backwards compatible fabric v1.3 channel capabilities. 21 ChannelV1_3 = "V1_3" 22 23 // ChannelV1_4_2 is the capabilities string for standard new non-backwards compatible fabric v1.4.2 channel capabilities. 24 ChannelV1_4_2 = "V1_4_2" 25 26 // ChannelV1_4_3 is the capabilities string for standard new non-backwards compatible fabric v1.4.3 channel capabilities. 27 ChannelV1_4_3 = "V1_4_3" 28 29 // ChannelV2_0 is the capabilities string for standard new non-backwards compatible fabric v2.0 channel capabilities. 30 ChannelV2_0 = "V2_0" 31 ) 32 33 // ChannelProvider provides capabilities information for channel level config. 34 type ChannelProvider struct { 35 *registry 36 v11 bool 37 v13 bool 38 v142 bool 39 v143 bool 40 v20 bool 41 } 42 43 // NewChannelProvider creates a channel capabilities provider. 44 func NewChannelProvider(capabilities map[string]*cb.Capability) *ChannelProvider { 45 cp := &ChannelProvider{} 46 cp.registry = newRegistry(cp, capabilities) 47 _, cp.v11 = capabilities[ChannelV1_1] 48 _, cp.v13 = capabilities[ChannelV1_3] 49 _, cp.v142 = capabilities[ChannelV1_4_2] 50 _, cp.v143 = capabilities[ChannelV1_4_3] 51 _, cp.v20 = capabilities[ChannelV2_0] 52 return cp 53 } 54 55 // Type returns a descriptive string for logging purposes. 56 func (cp *ChannelProvider) Type() string { 57 return channelTypeName 58 } 59 60 // HasCapability returns true if the capability is supported by this binary. 61 func (cp *ChannelProvider) HasCapability(capability string) bool { 62 switch capability { 63 // Add new capability names here 64 case ChannelV2_0: 65 return true 66 case ChannelV1_4_3: 67 return true 68 case ChannelV1_4_2: 69 return true 70 case ChannelV1_3: 71 return true 72 case ChannelV1_1: 73 return true 74 default: 75 return false 76 } 77 } 78 79 // MSPVersion returns the level of MSP support required by this channel. 80 func (cp *ChannelProvider) MSPVersion() msp.MSPVersion { 81 switch { 82 case cp.v143 || cp.v20: 83 return msp.MSPv1_4_3 84 case cp.v13 || cp.v142: 85 return msp.MSPv1_3 86 case cp.v11: 87 return msp.MSPv1_1 88 default: 89 return msp.MSPv1_0 90 } 91 } 92 93 // ConsensusTypeMigration return true if consensus-type migration is supported and permitted in both orderer and peer. 94 func (cp *ChannelProvider) ConsensusTypeMigration() bool { 95 return cp.v142 || cp.v143 || cp.v20 96 } 97 98 // OrgSpecificOrdererEndpoints allows for individual orderer orgs to specify their external addresses for their OSNs. 99 func (cp *ChannelProvider) OrgSpecificOrdererEndpoints() bool { 100 return cp.v142 || cp.v143 || cp.v20 101 }