github.com/kchristidis/fabric@v1.0.4-0.20171028114726-837acd08cde1/common/configtx/api/api.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 api
    18  
    19  import (
    20  	"github.com/hyperledger/fabric/common/config"
    21  	"github.com/hyperledger/fabric/common/policies"
    22  	"github.com/hyperledger/fabric/msp"
    23  	cb "github.com/hyperledger/fabric/protos/common"
    24  
    25  	"github.com/golang/protobuf/proto"
    26  )
    27  
    28  // Manager provides a mechanism to query and update config
    29  type Manager interface {
    30  	Resources
    31  
    32  	// Apply attempts to apply a configtx to become the new config
    33  	Apply(configEnv *cb.ConfigEnvelope) error
    34  
    35  	// Validate attempts to apply a configtx to become the new config
    36  	Validate(configEnv *cb.ConfigEnvelope) error
    37  
    38  	// Validate attempts to validate a new configtx against the current config state
    39  	ProposeConfigUpdate(configtx *cb.Envelope) (*cb.ConfigEnvelope, error)
    40  
    41  	// ChainID retrieves the chain ID associated with this manager
    42  	ChainID() string
    43  
    44  	// ConfigEnvelope returns the current config envelope
    45  	ConfigEnvelope() *cb.ConfigEnvelope
    46  
    47  	// Sequence returns the current sequence number of the config
    48  	Sequence() uint64
    49  }
    50  
    51  // Resources is the common set of config resources for all channels
    52  // Depending on whether chain is used at the orderer or at the peer, other
    53  // config resources may be available
    54  type Resources interface {
    55  	// PolicyManager returns the policies.Manager for the channel
    56  	PolicyManager() policies.Manager
    57  
    58  	// ChannelConfig returns the config.Channel for the chain
    59  	ChannelConfig() config.Channel
    60  
    61  	// OrdererConfig returns the config.Orderer for the channel
    62  	// and whether the Orderer config exists
    63  	OrdererConfig() (config.Orderer, bool)
    64  
    65  	// ConsortiumsConfig() returns the config.Consortiums for the channel
    66  	// and whether the consortiums config exists
    67  	ConsortiumsConfig() (config.Consortiums, bool)
    68  
    69  	// ApplicationConfig returns the configtxapplication.SharedConfig for the channel
    70  	// and whether the Application config exists
    71  	ApplicationConfig() (config.Application, bool)
    72  
    73  	// MSPManager returns the msp.MSPManager for the chain
    74  	MSPManager() msp.MSPManager
    75  }
    76  
    77  // Transactional is an interface which allows for an update to be proposed and rolled back
    78  type Transactional interface {
    79  	// RollbackConfig called when a config proposal is abandoned
    80  	RollbackProposals(tx interface{})
    81  
    82  	// PreCommit verifies that the transaction can be committed successfully
    83  	PreCommit(tx interface{}) error
    84  
    85  	// CommitConfig called when a config proposal is committed
    86  	CommitProposals(tx interface{})
    87  }
    88  
    89  // PolicyHandler is used for config updates to policy
    90  type PolicyHandler interface {
    91  	Transactional
    92  
    93  	BeginConfig(tx interface{}, groups []string) ([]PolicyHandler, error)
    94  
    95  	ProposePolicy(tx interface{}, key string, path []string, policy *cb.ConfigPolicy) (proto.Message, error)
    96  }
    97  
    98  // Proposer contains the references necesssary to appropriately unmarshal
    99  // a cb.ConfigGroup
   100  type Proposer interface {
   101  	// ValueProposer return the root value proposer
   102  	ValueProposer() config.ValueProposer
   103  
   104  	// PolicyProposer return the root policy proposer
   105  	PolicyProposer() policies.Proposer
   106  }
   107  
   108  // Initializer is used as indirection between Manager and Handler to allow
   109  // for single Handlers to handle multiple paths
   110  type Initializer interface {
   111  	Proposer
   112  
   113  	Resources
   114  }