github.com/myafeier/fabric@v1.0.1-0.20170722181825-3a4b1f2bce86/common/config/root.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  	"fmt"
    21  
    22  	"github.com/hyperledger/fabric/common/config/msp"
    23  
    24  	"github.com/golang/protobuf/proto"
    25  )
    26  
    27  // Root acts as the object which anchors the rest of the config
    28  // Note, yes, this is a stuttering name, but, the intent is to move
    29  // this up one level at the end of refactoring
    30  type Root struct {
    31  	channel          *ChannelGroup
    32  	mspConfigHandler *msp.MSPConfigHandler
    33  }
    34  
    35  // NewRoot creates a new instance of the Root
    36  func NewRoot(mspConfigHandler *msp.MSPConfigHandler) *Root {
    37  	return &Root{
    38  		channel:          NewChannelGroup(mspConfigHandler),
    39  		mspConfigHandler: mspConfigHandler,
    40  	}
    41  }
    42  
    43  type failDeserializer struct{}
    44  
    45  func (fd failDeserializer) Deserialize(key string, value []byte) (proto.Message, error) {
    46  	return nil, fmt.Errorf("Programming error, this should never be invoked")
    47  }
    48  
    49  // BeginValueProposals is used to start a new config proposal
    50  func (r *Root) BeginValueProposals(tx interface{}, groups []string) (ValueDeserializer, []ValueProposer, error) {
    51  	if len(groups) != 1 {
    52  		return nil, nil, fmt.Errorf("Root config only supports having one base group")
    53  	}
    54  	if groups[0] != ChannelGroupKey {
    55  		return nil, nil, fmt.Errorf("Root group must have channel")
    56  	}
    57  	r.mspConfigHandler.BeginConfig(tx)
    58  	return failDeserializer{}, []ValueProposer{r.channel}, nil
    59  }
    60  
    61  // RollbackConfig is used to abandon a new config proposal
    62  func (r *Root) RollbackProposals(tx interface{}) {
    63  	r.mspConfigHandler.RollbackProposals(tx)
    64  }
    65  
    66  // PreCommit is used to verify total configuration before commit
    67  func (r *Root) PreCommit(tx interface{}) error {
    68  	return r.mspConfigHandler.PreCommit(tx)
    69  }
    70  
    71  // CommitConfig is used to commit a new config proposal
    72  func (r *Root) CommitProposals(tx interface{}) {
    73  	r.mspConfigHandler.CommitProposals(tx)
    74  }
    75  
    76  // Channel returns the associated Channel level config
    77  func (r *Root) Channel() *ChannelGroup {
    78  	return r.channel
    79  }
    80  
    81  // Orderer returns the associated Orderer level config
    82  func (r *Root) Orderer() *OrdererGroup {
    83  	return r.channel.OrdererConfig()
    84  }
    85  
    86  // Application returns the associated Application level config
    87  func (r *Root) Application() *ApplicationGroup {
    88  	return r.channel.ApplicationConfig()
    89  }
    90  
    91  func (r *Root) Consortiums() *ConsortiumsGroup {
    92  	return r.channel.ConsortiumsConfig()
    93  }