github.com/myafeier/fabric@v1.0.1-0.20170722181825-3a4b1f2bce86/common/config/channel_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  	"math"
    21  
    22  	"github.com/hyperledger/fabric/bccsp"
    23  	cb "github.com/hyperledger/fabric/protos/common"
    24  	"github.com/hyperledger/fabric/protos/utils"
    25  )
    26  
    27  const defaultHashingAlgorithm = bccsp.SHA256
    28  
    29  func configGroup(key string, value []byte) *cb.ConfigGroup {
    30  	result := cb.NewConfigGroup()
    31  	result.Values[key] = &cb.ConfigValue{
    32  		Value: value,
    33  	}
    34  	return result
    35  }
    36  
    37  // TemplateConsortiumName creates a ConfigGroup representing the ConsortiumName
    38  func TemplateConsortium(name string) *cb.ConfigGroup {
    39  	return configGroup(ConsortiumKey, utils.MarshalOrPanic(&cb.Consortium{Name: name}))
    40  }
    41  
    42  // TemplateHashingAlgorithm creates a ConfigGroup representing the HashingAlgorithm
    43  func TemplateHashingAlgorithm(name string) *cb.ConfigGroup {
    44  	return configGroup(HashingAlgorithmKey, utils.MarshalOrPanic(&cb.HashingAlgorithm{Name: name}))
    45  }
    46  
    47  // DefaultHashingAlgorithm creates a headerless config item for the default hashing algorithm
    48  func DefaultHashingAlgorithm() *cb.ConfigGroup {
    49  	return TemplateHashingAlgorithm(defaultHashingAlgorithm)
    50  }
    51  
    52  const defaultBlockDataHashingStructureWidth = math.MaxUint32
    53  
    54  // TemplateBlockDataHashingStructure creates a headerless config item representing the block data hashing structure
    55  func TemplateBlockDataHashingStructure(width uint32) *cb.ConfigGroup {
    56  	return configGroup(BlockDataHashingStructureKey, utils.MarshalOrPanic(&cb.BlockDataHashingStructure{Width: width}))
    57  }
    58  
    59  // DefaultBlockDatahashingStructure creates a headerless config item for the default block data hashing structure
    60  func DefaultBlockDataHashingStructure() *cb.ConfigGroup {
    61  	return TemplateBlockDataHashingStructure(defaultBlockDataHashingStructureWidth)
    62  }
    63  
    64  var defaultOrdererAddresses = []string{"127.0.0.1:7050"}
    65  
    66  // TemplateOrdererAddressess creates a headerless config item representing the orderer addresses
    67  func TemplateOrdererAddresses(addresses []string) *cb.ConfigGroup {
    68  	return configGroup(OrdererAddressesKey, utils.MarshalOrPanic(&cb.OrdererAddresses{Addresses: addresses}))
    69  }
    70  
    71  // DefaultOrdererAddresses creates a headerless config item for the default orderer addresses
    72  func DefaultOrdererAddresses() *cb.ConfigGroup {
    73  	return TemplateOrdererAddresses(defaultOrdererAddresses)
    74  }