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