github.com/adnan-c/fabric_e2e_couchdb@v0.6.1-preview.0.20170228180935-21ce6b23cf91/common/configvalues/channel/orderer/sharedconfig_util.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 orderer
    18  
    19  import (
    20  	cb "github.com/hyperledger/fabric/protos/common"
    21  	ab "github.com/hyperledger/fabric/protos/orderer"
    22  	"github.com/hyperledger/fabric/protos/utils"
    23  )
    24  
    25  func configGroup(key string, value []byte) *cb.ConfigGroup {
    26  	result := cb.NewConfigGroup()
    27  	result.Groups[GroupKey] = cb.NewConfigGroup()
    28  	result.Groups[GroupKey].Values[key] = &cb.ConfigValue{
    29  		Value: value,
    30  	}
    31  	return result
    32  }
    33  
    34  // TemplateConsensusType creates a headerless config item representing the consensus type
    35  func TemplateConsensusType(typeValue string) *cb.ConfigGroup {
    36  	return configGroup(ConsensusTypeKey, utils.MarshalOrPanic(&ab.ConsensusType{Type: typeValue}))
    37  }
    38  
    39  // TemplateBatchSize creates a headerless config item representing the batch size
    40  func TemplateBatchSize(batchSize *ab.BatchSize) *cb.ConfigGroup {
    41  	return configGroup(BatchSizeKey, utils.MarshalOrPanic(batchSize))
    42  }
    43  
    44  // TemplateBatchTimeout creates a headerless config item representing the batch timeout
    45  func TemplateBatchTimeout(batchTimeout string) *cb.ConfigGroup {
    46  	return configGroup(BatchTimeoutKey, utils.MarshalOrPanic(&ab.BatchTimeout{Timeout: batchTimeout}))
    47  }
    48  
    49  // TemplateChainCreationPolicyNames creates a headerless configuraiton item representing the chain creation policy names
    50  func TemplateChainCreationPolicyNames(names []string) *cb.ConfigGroup {
    51  	return configGroup(ChainCreationPolicyNamesKey, utils.MarshalOrPanic(&ab.ChainCreationPolicyNames{Names: names}))
    52  }
    53  
    54  // TemplateIngressPolicyNames creates a headerless config item representing the ingress policy names
    55  func TemplateIngressPolicyNames(names []string) *cb.ConfigGroup {
    56  	return configGroup(IngressPolicyNamesKey, utils.MarshalOrPanic(&ab.IngressPolicyNames{Names: names}))
    57  }
    58  
    59  // TemplateEgressPolicyNames creates a headerless config item representing the egress policy names
    60  func TemplateEgressPolicyNames(names []string) *cb.ConfigGroup {
    61  	return configGroup(EgressPolicyNamesKey, utils.MarshalOrPanic(&ab.EgressPolicyNames{Names: names}))
    62  }
    63  
    64  // TemplateKafkaBrokers creates a headerless config item representing the kafka brokers
    65  func TemplateKafkaBrokers(brokers []string) *cb.ConfigGroup {
    66  	return configGroup(KafkaBrokersKey, utils.MarshalOrPanic(&ab.KafkaBrokers{Brokers: brokers}))
    67  }