github.com/myafeier/fabric@v1.0.1-0.20170722181825-3a4b1f2bce86/common/config/orderer_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 config
    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 ordererConfigGroup(key string, value []byte) *cb.ConfigGroup {
    26  	result := cb.NewConfigGroup()
    27  	result.Groups[OrdererGroupKey] = cb.NewConfigGroup()
    28  	result.Groups[OrdererGroupKey].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 ordererConfigGroup(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 ordererConfigGroup(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 ordererConfigGroup(BatchTimeoutKey, utils.MarshalOrPanic(&ab.BatchTimeout{Timeout: batchTimeout}))
    47  }
    48  
    49  // TemplateChannelRestrictions creates a config group with ChannelRestrictions specified
    50  func TemplateChannelRestrictions(maxChannels uint64) *cb.ConfigGroup {
    51  	return ordererConfigGroup(ChannelRestrictionsKey, utils.MarshalOrPanic(&ab.ChannelRestrictions{MaxCount: maxChannels}))
    52  }
    53  
    54  // TemplateKafkaBrokers creates a headerless config item representing the kafka brokers
    55  func TemplateKafkaBrokers(brokers []string) *cb.ConfigGroup {
    56  	return ordererConfigGroup(KafkaBrokersKey, utils.MarshalOrPanic(&ab.KafkaBrokers{Brokers: brokers}))
    57  }