github.com/leonlxy/hyperledger@v1.0.0-alpha.0.20170427033203-34922035d248/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  	OrdererConfig() config.Orderer
    63  
    64  	// ConsortiumsConfig() returns the config.Consortiums for the channel
    65  	ConsortiumsConfig() config.Consortiums
    66  
    67  	// ApplicationConfig returns the configtxapplication.SharedConfig for the channel
    68  	ApplicationConfig() config.Application
    69  
    70  	// MSPManager returns the msp.MSPManager for the chain
    71  	MSPManager() msp.MSPManager
    72  }
    73  
    74  // Transactional is an interface which allows for an update to be proposed and rolled back
    75  type Transactional interface {
    76  	// RollbackConfig called when a config proposal is abandoned
    77  	RollbackProposals(tx interface{})
    78  
    79  	// PreCommit verifies that the transaction can be committed successfully
    80  	PreCommit(tx interface{}) error
    81  
    82  	// CommitConfig called when a config proposal is committed
    83  	CommitProposals(tx interface{})
    84  }
    85  
    86  // PolicyHandler is used for config updates to policy
    87  type PolicyHandler interface {
    88  	Transactional
    89  
    90  	BeginConfig(tx interface{}, groups []string) ([]PolicyHandler, error)
    91  
    92  	ProposePolicy(tx interface{}, key string, path []string, policy *cb.ConfigPolicy) (proto.Message, error)
    93  }
    94  
    95  // Proposer contains the references necesssary to appropriately unmarshal
    96  // a cb.ConfigGroup
    97  type Proposer interface {
    98  	// ValueProposer return the root value proposer
    99  	ValueProposer() config.ValueProposer
   100  
   101  	// PolicyProposer return the root policy proposer
   102  	PolicyProposer() policies.Proposer
   103  }
   104  
   105  // Initializer is used as indirection between Manager and Handler to allow
   106  // for single Handlers to handle multiple paths
   107  type Initializer interface {
   108  	Proposer
   109  
   110  	Resources
   111  }