github.com/yacovm/fabric@v2.0.0-alpha.0.20191128145320-c5d4087dc723+incompatible/common/mocks/scc/sccprovider.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 "github.com/hyperledger/fabric/common/channelconfig" 21 lm "github.com/hyperledger/fabric/common/mocks/ledger" 22 "github.com/hyperledger/fabric/common/policies" 23 "github.com/hyperledger/fabric/core/common/sysccprovider" 24 "github.com/hyperledger/fabric/core/ledger" 25 ) 26 27 type MocksccProviderFactory struct { 28 Qe *lm.MockQueryExecutor 29 QErr error 30 ApplicationConfigRv channelconfig.Application 31 ApplicationConfigBool bool 32 PolicyManagerRv policies.Manager 33 PolicyManagerBool bool 34 } 35 36 func (c *MocksccProviderFactory) NewSystemChaincodeProvider() sysccprovider.SystemChaincodeProvider { 37 return &MocksccProviderImpl{ 38 Qe: c.Qe, 39 QErr: c.QErr, 40 ApplicationConfigRv: c.ApplicationConfigRv, 41 ApplicationConfigBool: c.ApplicationConfigBool, 42 PolicyManagerBool: c.PolicyManagerBool, 43 PolicyManagerRv: c.PolicyManagerRv, 44 } 45 } 46 47 type MocksccProviderImpl struct { 48 Qe *lm.MockQueryExecutor 49 QErr error 50 ApplicationConfigRv channelconfig.Application 51 ApplicationConfigBool bool 52 PolicyManagerRv policies.Manager 53 PolicyManagerBool bool 54 SysCCMap map[string]bool 55 } 56 57 func (c *MocksccProviderImpl) IsSysCC(name string) bool { 58 if c.SysCCMap != nil { 59 return c.SysCCMap[name] 60 } 61 62 return (name == "lscc") || (name == "escc") || (name == "vscc") || (name == "notext") 63 } 64 65 func (c *MocksccProviderImpl) IsSysCCAndNotInvokableCC2CC(name string) bool { 66 return (name == "escc") || (name == "vscc") 67 } 68 69 func (c *MocksccProviderImpl) IsSysCCAndNotInvokableExternal(name string) bool { 70 return (name == "escc") || (name == "vscc") || (name == "notext") 71 } 72 73 func (c *MocksccProviderImpl) GetQueryExecutorForLedger(cid string) (ledger.QueryExecutor, error) { 74 return c.Qe, c.QErr 75 } 76 77 func (c *MocksccProviderImpl) GetApplicationConfig(cid string) (channelconfig.Application, bool) { 78 return c.ApplicationConfigRv, c.ApplicationConfigBool 79 } 80 81 func (c *MocksccProviderImpl) PolicyManager(channelID string) (policies.Manager, bool) { 82 return c.PolicyManagerRv, c.PolicyManagerBool 83 }