github.com/darrenli6/fabric-sdk-example@v0.0.0-20220109053535-94b13b56df8c/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 import ( 20 "github.com/hyperledger/fabric/core/ledger" 21 ) 22 23 // SystemChaincodeProvider provides an abstraction layer that is 24 // used for different packages to interact with code in the 25 // system chaincode package without importing it; more methods 26 // should be added below if necessary 27 type SystemChaincodeProvider interface { 28 // IsSysCC returns true if the supplied chaincode is a system chaincode 29 IsSysCC(name string) bool 30 31 // IsSysCCAndNotInvokableCC2CC returns true if the supplied chaincode 32 // is a system chaincode and is not invokable through a cc2cc invocation 33 IsSysCCAndNotInvokableCC2CC(name string) bool 34 35 // IsSysCCAndNotInvokable returns true if the supplied chaincode 36 // is a system chaincode and is not invokable through a proposal 37 IsSysCCAndNotInvokableExternal(name string) bool 38 39 // GetQueryExecutorForLedger returns a query executor for the 40 // ledger of the supplied channel. 41 // That's useful for system chaincodes that require unfettered 42 // access to the ledger 43 GetQueryExecutorForLedger(cid string) (ledger.QueryExecutor, error) 44 } 45 46 var sccFactory SystemChaincodeProviderFactory 47 48 // SystemChaincodeProviderFactory defines a factory interface so 49 // that the actual implementation can be injected 50 type SystemChaincodeProviderFactory interface { 51 NewSystemChaincodeProvider() SystemChaincodeProvider 52 } 53 54 // RegisterSystemChaincodeProviderFactory is to be called once to set 55 // the factory that will be used to obtain instances of ChaincodeProvider 56 func RegisterSystemChaincodeProviderFactory(sccfact SystemChaincodeProviderFactory) { 57 sccFactory = sccfact 58 } 59 60 // GetSystemChaincodeProvider returns instances of SystemChaincodeProvider; 61 // the actual implementation is controlled by the factory that 62 // is registered via RegisterSystemChaincodeProviderFactory 63 func GetSystemChaincodeProvider() SystemChaincodeProvider { 64 if sccFactory == nil { 65 panic("The factory must be set first via RegisterSystemChaincodeProviderFactory") 66 } 67 return sccFactory.NewSystemChaincodeProvider() 68 } 69 70 // ChaincodeInstance is unique identifier of chaincode instance 71 type ChaincodeInstance struct { 72 ChainID string 73 ChaincodeName string 74 ChaincodeVersion string 75 } 76 77 func (ci *ChaincodeInstance) String() string { 78 return ci.ChainID + "." + ci.ChaincodeName + "#" + ci.ChaincodeVersion 79 }