github.com/myafeier/fabric@v1.0.1-0.20170722181825-3a4b1f2bce86/core/scc/sccproviderimpl.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 scc
    18  
    19  import (
    20  	"fmt"
    21  
    22  	"github.com/hyperledger/fabric/core/common/sysccprovider"
    23  	"github.com/hyperledger/fabric/core/ledger"
    24  	"github.com/hyperledger/fabric/core/peer"
    25  )
    26  
    27  // sccProviderFactory implements the sysccprovider.SystemChaincodeProviderFactory
    28  // interface and returns instances of sysccprovider.SystemChaincodeProvider
    29  type sccProviderFactory struct {
    30  }
    31  
    32  // NewSystemChaincodeProvider returns pointers to sccProviderFactory as an
    33  // implementer of the sysccprovider.SystemChaincodeProvider interface
    34  func (c *sccProviderFactory) NewSystemChaincodeProvider() sysccprovider.SystemChaincodeProvider {
    35  	return &sccProviderImpl{}
    36  }
    37  
    38  // init is called when this package is loaded. This implementation registers the factory
    39  func init() {
    40  	sysccprovider.RegisterSystemChaincodeProviderFactory(&sccProviderFactory{})
    41  }
    42  
    43  // ccProviderImpl is an implementation of the ccprovider.ChaincodeProvider interface
    44  type sccProviderImpl struct {
    45  }
    46  
    47  // IsSysCC returns true if the supplied chaincode is a system chaincode
    48  func (c *sccProviderImpl) IsSysCC(name string) bool {
    49  	return IsSysCC(name)
    50  }
    51  
    52  // IsSysCCAndNotInvokableCC2CC returns true if the supplied chaincode is
    53  // ia system chaincode and it NOT nvokable through a cc2cc invocation
    54  func (c *sccProviderImpl) IsSysCCAndNotInvokableCC2CC(name string) bool {
    55  	return IsSysCCAndNotInvokableCC2CC(name)
    56  }
    57  
    58  // GetQueryExecutorForLedger returns a query executor for the specified channel
    59  func (c *sccProviderImpl) GetQueryExecutorForLedger(cid string) (ledger.QueryExecutor, error) {
    60  	l := peer.GetLedger(cid)
    61  	if l == nil {
    62  		return nil, fmt.Errorf("Could not retrieve ledger for channel %s", cid)
    63  	}
    64  
    65  	return l.NewQueryExecutor()
    66  }
    67  
    68  // IsSysCCAndNotInvokableExternal returns true if the supplied chaincode is
    69  // ia system chaincode and it NOT nvokable
    70  func (c *sccProviderImpl) IsSysCCAndNotInvokableExternal(name string) bool {
    71  	// call the static method of the same name
    72  	return IsSysCCAndNotInvokableExternal(name)
    73  }