github.com/leonlxy/hyperledger@v1.0.0-alpha.0.20170427033203-34922035d248/core/scc/importsysccs.go (about) 1 /* 2 Copyright IBM Corp. 2016, 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 //import system chain codes here 21 "github.com/hyperledger/fabric/core/scc/cscc" 22 "github.com/hyperledger/fabric/core/scc/escc" 23 "github.com/hyperledger/fabric/core/scc/lscc" 24 "github.com/hyperledger/fabric/core/scc/qscc" 25 "github.com/hyperledger/fabric/core/scc/vscc" 26 ) 27 28 //see systemchaincode_test.go for an example using "sample_syscc" 29 var systemChaincodes = []*SystemChaincode{ 30 { 31 Enabled: true, 32 Name: "cscc", 33 Path: "github.com/hyperledger/fabric/core/scc/cscc", 34 InitArgs: [][]byte{[]byte("")}, 35 Chaincode: &cscc.PeerConfiger{}, 36 InvokableExternal: true, // cscc is invoked to join a channel 37 }, 38 { 39 Enabled: true, 40 Name: "lscc", 41 Path: "github.com/hyperledger/fabric/core/scc/lscc", 42 InitArgs: [][]byte{[]byte("")}, 43 Chaincode: &lscc.LifeCycleSysCC{}, 44 InvokableExternal: true, // lscc is invoked to deploy new chaincodes 45 InvokableCC2CC: true, // lscc can be invoked by other chaincodes 46 }, 47 { 48 Enabled: true, 49 Name: "escc", 50 Path: "github.com/hyperledger/fabric/core/scc/escc", 51 InitArgs: [][]byte{[]byte("")}, 52 Chaincode: &escc.EndorserOneValidSignature{}, 53 }, 54 { 55 Enabled: true, 56 Name: "vscc", 57 Path: "github.com/hyperledger/fabric/core/scc/vscc", 58 InitArgs: [][]byte{[]byte("")}, 59 Chaincode: &vscc.ValidatorOneValidSignature{}, 60 }, 61 { 62 Enabled: true, 63 Name: "qscc", 64 Path: "github.com/hyperledger/fabric/core/chaincode/qscc", 65 InitArgs: [][]byte{[]byte("")}, 66 Chaincode: &qscc.LedgerQuerier{}, 67 InvokableExternal: true, // qscc can be invoked to retrieve blocks 68 InvokableCC2CC: true, // qscc can be invoked to retrieve blocks also by a cc 69 }, 70 } 71 72 //RegisterSysCCs is the hook for system chaincodes where system chaincodes are registered with the fabric 73 //note the chaincode must still be deployed and launched like a user chaincode will be 74 func RegisterSysCCs() { 75 for _, sysCC := range systemChaincodes { 76 RegisterSysCC(sysCC) 77 } 78 } 79 80 //DeploySysCCs is the hook for system chaincodes where system chaincodes are registered with the fabric 81 //note the chaincode must still be deployed and launched like a user chaincode will be 82 func DeploySysCCs(chainID string) { 83 for _, sysCC := range systemChaincodes { 84 deploySysCC(chainID, sysCC) 85 } 86 } 87 88 //DeDeploySysCCs is used in unit tests to stop and remove the system chaincodes before 89 //restarting them in the same process. This allows clean start of the system 90 //in the same process 91 func DeDeploySysCCs(chainID string) { 92 for _, sysCC := range systemChaincodes { 93 DeDeploySysCC(chainID, sysCC) 94 } 95 } 96 97 //IsSysCC returns true if the name matches a system chaincode's 98 //system chaincode names are system, chain wide 99 func IsSysCC(name string) bool { 100 for _, sysCC := range systemChaincodes { 101 if sysCC.Name == name { 102 return true 103 } 104 } 105 return false 106 } 107 108 // IsSysCCAndNotInvokable returns true if the chaincode 109 // is a system chaincode and *CANNOT* be invoked through 110 // a proposal to this peer 111 func IsSysCCAndNotInvokable(name string) bool { 112 for _, sysCC := range systemChaincodes { 113 if sysCC.Name == name { 114 return !sysCC.InvokableExternal 115 } 116 } 117 return false 118 } 119 120 // IsSysCCAndNotInvokableCC2CC returns true if the chaincode 121 // is a system chaincode and *CANNOT* be invoked through 122 // a cc2cc invocation 123 func IsSysCCAndNotInvokableCC2CC(name string) bool { 124 for _, sysCC := range systemChaincodes { 125 if sysCC.Name == name { 126 return !sysCC.InvokableCC2CC 127 } 128 } 129 return false 130 } 131 132 // MockRegisterSysCCs is used only for testing 133 // This is needed to break import cycle 134 func MockRegisterSysCCs(mockSysCCs []*SystemChaincode) []*SystemChaincode { 135 orig := systemChaincodes 136 systemChaincodes = mockSysCCs 137 RegisterSysCCs() 138 return orig 139 } 140 141 // MockResetSysCCs restore orig system ccs - is used only for testing 142 func MockResetSysCCs(mockSysCCs []*SystemChaincode) { 143 systemChaincodes = mockSysCCs 144 }