@@ -8,112 +8,63 @@ package scc
8
8
9
9
import (
10
10
//import system chaincodes here
11
- "github.com/hyperledger/fabric/core/container/inproccontroller"
12
11
"github.com/hyperledger/fabric/core/scc/cscc"
13
12
"github.com/hyperledger/fabric/core/scc/lscc"
14
13
"github.com/hyperledger/fabric/core/scc/qscc"
15
14
"github.com/hyperledger/fabric/core/scc/vscc"
16
15
)
17
16
18
- //see systemchaincode_test.go for an example using "sample_syscc"
19
- var systemChaincodes = []* SystemChaincode {
20
- {
21
- Enabled : true ,
22
- Name : "cscc" ,
23
- Path : "github.com/hyperledger/fabric/core/scc/cscc" ,
24
- InitArgs : nil ,
25
- Chaincode : cscc .NewAsChaincode ,
26
- InvokableExternal : true , // cscc is invoked to join a channel
27
- },
28
- {
29
- Enabled : true ,
30
- Name : "lscc" ,
31
- Path : "github.com/hyperledger/fabric/core/scc/lscc" ,
32
- InitArgs : nil ,
33
- Chaincode : lscc .NewAsChaincode ,
34
- InvokableExternal : true , // lscc is invoked to deploy new chaincodes
35
- InvokableCC2CC : true , // lscc can be invoked by other chaincodes
36
- },
37
- {
38
- Enabled : true ,
39
- Name : "vscc" ,
40
- Path : "github.com/hyperledger/fabric/core/scc/vscc" ,
41
- InitArgs : nil ,
42
- Chaincode : vscc .NewAsChaincode ,
43
- },
44
- {
45
- Enabled : true ,
46
- Name : "qscc" ,
47
- Path : "github.com/hyperledger/fabric/core/chaincode/qscc" ,
48
- InitArgs : nil ,
49
- Chaincode : qscc .NewAsChaincode ,
50
- InvokableExternal : true , // qscc can be invoked to retrieve blocks
51
- InvokableCC2CC : true , // qscc can be invoked to retrieve blocks also by a cc
52
- },
17
+ func builtInSystemChaincodes (p * Provider ) []* SystemChaincode {
18
+ return []* SystemChaincode {
19
+ {
20
+ Enabled : true ,
21
+ Name : "cscc" ,
22
+ Path : "github.com/hyperledger/fabric/core/scc/cscc" ,
23
+ InitArgs : nil ,
24
+ Chaincode : cscc .New (p ),
25
+ InvokableExternal : true , // cscc is invoked to join a channel
26
+ },
27
+ {
28
+ Enabled : true ,
29
+ Name : "lscc" ,
30
+ Path : "github.com/hyperledger/fabric/core/scc/lscc" ,
31
+ InitArgs : nil ,
32
+ Chaincode : lscc .New (p ),
33
+ InvokableExternal : true , // lscc is invoked to deploy new chaincodes
34
+ InvokableCC2CC : true , // lscc can be invoked by other chaincodes
35
+ },
36
+ {
37
+ Enabled : true ,
38
+ Name : "vscc" ,
39
+ Path : "github.com/hyperledger/fabric/core/scc/vscc" ,
40
+ InitArgs : nil ,
41
+ Chaincode : vscc .New (p ),
42
+ },
43
+ {
44
+ Enabled : true ,
45
+ Name : "qscc" ,
46
+ Path : "github.com/hyperledger/fabric/core/chaincode/qscc" ,
47
+ InitArgs : nil ,
48
+ Chaincode : qscc .New (),
49
+ InvokableExternal : true , // qscc can be invoked to retrieve blocks
50
+ InvokableCC2CC : true , // qscc can be invoked to retrieve blocks also by a cc
51
+ },
52
+ }
53
53
}
54
54
55
55
//DeploySysCCs is the hook for system chaincodes where system chaincodes are registered with the fabric
56
56
//note the chaincode must still be deployed and launched like a user chaincode will be
57
- func DeploySysCCs (chainID string ) {
58
- for _ , sysCC := range systemChaincodes {
59
- deploySysCC (chainID , sysCC )
57
+ func ( p * Provider ) DeploySysCCs (chainID string ) {
58
+ for _ , sysCC := range p . SysCCs {
59
+ sysCC . deploySysCC (chainID )
60
60
}
61
61
}
62
62
63
63
//DeDeploySysCCs is used in unit tests to stop and remove the system chaincodes before
64
64
//restarting them in the same process. This allows clean start of the system
65
65
//in the same process
66
- func DeDeploySysCCs (chainID string ) {
67
- for _ , sysCC := range systemChaincodes {
68
- DeDeploySysCC (chainID , sysCC )
69
- }
70
- }
71
-
72
- //IsSysCC returns true if the name matches a system chaincode's
73
- //system chaincode names are system, chain wide
74
- func IsSysCC (name string ) bool {
75
- for _ , sysCC := range systemChaincodes {
76
- if sysCC .Name == name {
77
- return true
78
- }
79
- }
80
- return false
81
- }
82
-
83
- // IsSysCCAndNotInvokableExternal returns true if the chaincode
84
- // is a system chaincode and *CANNOT* be invoked through
85
- // a proposal to this peer
86
- func IsSysCCAndNotInvokableExternal (name string ) bool {
87
- for _ , sysCC := range systemChaincodes {
88
- if sysCC .Name == name {
89
- return ! sysCC .InvokableExternal
90
- }
66
+ func (p * Provider ) DeDeploySysCCs (chainID string ) {
67
+ for _ , sysCC := range p .SysCCs {
68
+ sysCC .deDeploySysCC (chainID )
91
69
}
92
- return false
93
- }
94
-
95
- // IsSysCCAndNotInvokableCC2CC returns true if the chaincode
96
- // is a system chaincode and *CANNOT* be invoked through
97
- // a cc2cc invocation
98
- func IsSysCCAndNotInvokableCC2CC (name string ) bool {
99
- for _ , sysCC := range systemChaincodes {
100
- if sysCC .Name == name {
101
- return ! sysCC .InvokableCC2CC
102
- }
103
- }
104
- return false
105
- }
106
-
107
- // MockRegisterSysCCs is used only for testing
108
- // This is needed to break import cycle
109
- func MockRegisterSysCCs (mockSysCCs []* SystemChaincode , ipRegistry * inproccontroller.Registry ) []* SystemChaincode {
110
- orig := systemChaincodes
111
- systemChaincodes = mockSysCCs
112
- RegisterSysCCs (ipRegistry )
113
- return orig
114
- }
115
-
116
- // MockResetSysCCs restore orig system ccs - is used only for testing
117
- func MockResetSysCCs (mockSysCCs []* SystemChaincode ) {
118
- systemChaincodes = mockSysCCs
119
70
}
0 commit comments