github.com/leonlxy/hyperledger@v1.0.0-alpha.0.20170427033203-34922035d248/core/common/sysccprovider/sysccprovider.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 sysccprovider
    18  
    19  // SystemChaincodeProvider provides an abstraction layer that is
    20  // used for different packages to interact with code in the
    21  // system chaincode package without importing it; more methods
    22  // should be added below if necessary
    23  type SystemChaincodeProvider interface {
    24  	// IsSysCC returns true if the supplied chaincode is a system chaincode
    25  	IsSysCC(name string) bool
    26  
    27  	// IsSysCCAndNotInvokableCC2CC returns true if the supplied chaincode
    28  	// is a system chaincode and is not invokable through a cc2cc invocation
    29  	IsSysCCAndNotInvokableCC2CC(name string) bool
    30  }
    31  
    32  var sccFactory SystemChaincodeProviderFactory
    33  
    34  // SystemChaincodeProviderFactory defines a factory interface so
    35  // that the actual implementation can be injected
    36  type SystemChaincodeProviderFactory interface {
    37  	NewSystemChaincodeProvider() SystemChaincodeProvider
    38  }
    39  
    40  // RegisterSystemChaincodeProviderFactory is to be called once to set
    41  // the factory that will be used to obtain instances of ChaincodeProvider
    42  func RegisterSystemChaincodeProviderFactory(sccfact SystemChaincodeProviderFactory) {
    43  	sccFactory = sccfact
    44  }
    45  
    46  // GetSystemChaincodeProvider returns instances of SystemChaincodeProvider;
    47  // the actual implementation is controlled by the factory that
    48  // is registered via RegisterSystemChaincodeProviderFactory
    49  func GetSystemChaincodeProvider() SystemChaincodeProvider {
    50  	if sccFactory == nil {
    51  		panic("The factory must be set first via RegisterSystemChaincodeProviderFactory")
    52  	}
    53  	return sccFactory.NewSystemChaincodeProvider()
    54  }