@@ -80,18 +80,6 @@ type nextStateInfo struct {
80
80
sendSync bool
81
81
}
82
82
83
- //chaincode registered name is of the form
84
- // <name>:<version>/<suffix>
85
- type ccParts struct {
86
- name string //the main name of the chaincode
87
- version string //the version param if any (used for upgrade)
88
- suffix string //for now just the chain name
89
- }
90
-
91
- func (p * ccParts ) String () string {
92
- return p .suffix + "." + p .name + "#" + p .version
93
- }
94
-
95
83
// Handler responsbile for management of Peer's side of chaincode stream
96
84
type Handler struct {
97
85
sync.RWMutex
@@ -100,7 +88,7 @@ type Handler struct {
100
88
ChatStream ccintf.ChaincodeStream
101
89
FSM * fsm.FSM
102
90
ChaincodeID * pb.ChaincodeID
103
- ccCompParts * ccParts
91
+ ccInstance * sysccprovider. ChaincodeInstance
104
92
105
93
chaincodeSupport * ChaincodeSupport
106
94
registered bool
@@ -124,26 +112,26 @@ func shorttxid(txid string) string {
124
112
return txid [0 :8 ]
125
113
}
126
114
127
- //gets component parts from the canonical name of the chaincode.
115
+ //gets chaincode instance from the canonical name of the chaincode.
128
116
//Called exactly once per chaincode when registering chaincode.
129
117
//This is needed for the "one-instance-per-chain" model when
130
118
//starting up the chaincode for each chain. It will still
131
119
//work for the "one-instance-for-all-chains" as the version
132
120
//and suffix will just be absent (also note that LSCC reserves
133
121
//"/:[]${}" as special chars mainly for such namespace uses)
134
122
func (handler * Handler ) decomposeRegisteredName (cid * pb.ChaincodeID ) {
135
- handler .ccCompParts = chaincodeIDParts (cid .Name )
123
+ handler .ccInstance = getChaincodeInstance (cid .Name )
136
124
}
137
125
138
- func chaincodeIDParts (ccName string ) * ccParts {
126
+ func getChaincodeInstance (ccName string ) * sysccprovider. ChaincodeInstance {
139
127
b := []byte (ccName )
140
- p := & ccParts {}
128
+ ci := & sysccprovider. ChaincodeInstance {}
141
129
142
130
//compute suffix (ie, chain name)
143
131
i := bytes .IndexByte (b , '/' )
144
132
if i >= 0 {
145
133
if i < len (b )- 1 {
146
- p . suffix = string (b [i + 1 :])
134
+ ci . ChainID = string (b [i + 1 :])
147
135
}
148
136
b = b [:i ]
149
137
}
@@ -152,18 +140,18 @@ func chaincodeIDParts(ccName string) *ccParts {
152
140
i = bytes .IndexByte (b , ':' )
153
141
if i >= 0 {
154
142
if i < len (b )- 1 {
155
- p . version = string (b [i + 1 :])
143
+ ci . ChaincodeVersion = string (b [i + 1 :])
156
144
}
157
145
b = b [:i ]
158
146
}
159
147
// remaining is the chaincode name
160
- p . name = string (b )
148
+ ci . ChaincodeName = string (b )
161
149
162
- return p
150
+ return ci
163
151
}
164
152
165
153
func (handler * Handler ) getCCRootName () string {
166
- return handler .ccCompParts . name
154
+ return handler .ccInstance . ChaincodeName
167
155
}
168
156
169
157
//serialSend serializes msgs so gRPC will be happy
@@ -246,11 +234,11 @@ func (handler *Handler) deleteQueryIterator(txContext *transactionContext, txid
246
234
}
247
235
248
236
// Check if the transactor is allow to call this chaincode on this channel
249
- func (handler * Handler ) checkACL (signedProp * pb.SignedProposal , proposal * pb.Proposal , calledCC * ccParts ) error {
237
+ func (handler * Handler ) checkACL (signedProp * pb.SignedProposal , proposal * pb.Proposal , ccIns * sysccprovider. ChaincodeInstance ) error {
250
238
// ensure that we don't invoke a system chaincode
251
239
// that is not invokable through a cc2cc invocation
252
- if sysccprovider .GetSystemChaincodeProvider ().IsSysCCAndNotInvokableCC2CC (calledCC . name ) {
253
- return fmt .Errorf ("System chaincode %s cannot be invoked with a cc2cc invocation" , calledCC . name )
240
+ if sysccprovider .GetSystemChaincodeProvider ().IsSysCCAndNotInvokableCC2CC (ccIns . ChaincodeName ) {
241
+ return fmt .Errorf ("System chaincode %s cannot be invoked with a cc2cc invocation" , ccIns . ChaincodeName )
254
242
}
255
243
256
244
// if we are here, all we know is that the invoked chaincode is either
@@ -260,17 +248,17 @@ func (handler *Handler) checkACL(signedProp *pb.SignedProposal, proposal *pb.Pro
260
248
// - an application chaincode (and we still need to determine
261
249
// whether the invoker can invoke it)
262
250
263
- if sysccprovider .GetSystemChaincodeProvider ().IsSysCC (calledCC . name ) {
251
+ if sysccprovider .GetSystemChaincodeProvider ().IsSysCC (ccIns . ChaincodeName ) {
264
252
// Allow this call
265
253
return nil
266
254
}
267
255
268
256
// A Nil signedProp will be rejected for non-system chaincodes
269
257
if signedProp == nil {
270
- return fmt .Errorf ("Signed Proposal must not be nil from caller [%s]" , calledCC .String ())
258
+ return fmt .Errorf ("Signed Proposal must not be nil from caller [%s]" , ccIns .String ())
271
259
}
272
260
273
- return handler .policyChecker .CheckPolicy (calledCC . suffix , policies .ChannelApplicationWriters , signedProp )
261
+ return handler .policyChecker .CheckPolicy (ccIns . ChainID , policies .ChannelApplicationWriters , signedProp )
274
262
}
275
263
276
264
//THIS CAN BE REMOVED ONCE WE FULL SUPPORT (Invoke) CONFIDENTIALITY WITH CC-CALLING-CC
@@ -1267,21 +1255,21 @@ func (handler *Handler) enterBusyState(e *fsm.Event, state string) {
1267
1255
// Get the chaincodeID to invoke. The chaincodeID to be called may
1268
1256
// contain composite info like "chaincode-name:version/channel-name"
1269
1257
// We are not using version now but default to the latest
1270
- calledCcParts := chaincodeIDParts (chaincodeSpec .ChaincodeId .Name )
1271
- chaincodeSpec .ChaincodeId .Name = calledCcParts . name
1272
- if calledCcParts . suffix == "" {
1258
+ calledCcIns := getChaincodeInstance (chaincodeSpec .ChaincodeId .Name )
1259
+ chaincodeSpec .ChaincodeId .Name = calledCcIns . ChaincodeName
1260
+ if calledCcIns . ChainID == "" {
1273
1261
// use caller's channel as the called chaincode is in the same channel
1274
- calledCcParts . suffix = txContext .chainID
1262
+ calledCcIns . ChainID = txContext .chainID
1275
1263
}
1276
1264
if chaincodeLogger .IsEnabledFor (logging .DEBUG ) {
1277
1265
chaincodeLogger .Debugf ("[%s] C-call-C %s on channel %s" ,
1278
- shorttxid (msg .Txid ), calledCcParts . name , calledCcParts . suffix )
1266
+ shorttxid (msg .Txid ), calledCcIns . ChaincodeName , calledCcIns . ChainID )
1279
1267
}
1280
1268
1281
- err := handler .checkACL (txContext .signedProp , txContext .proposal , calledCcParts )
1269
+ err := handler .checkACL (txContext .signedProp , txContext .proposal , calledCcIns )
1282
1270
if err != nil {
1283
1271
chaincodeLogger .Errorf ("[%s] C-call-C %s on channel %s failed check ACL [%v]: [%s]" ,
1284
- shorttxid (msg .Txid ), calledCcParts . name , calledCcParts . suffix , txContext .signedProp , err )
1272
+ shorttxid (msg .Txid ), calledCcIns . ChaincodeName , calledCcIns . ChainID , txContext .signedProp , err )
1285
1273
triggerNextStateMsg = & pb.ChaincodeMessage {Type : pb .ChaincodeMessage_ERROR ,
1286
1274
Payload : []byte (err .Error ()), Txid : msg .Txid }
1287
1275
return
@@ -1292,10 +1280,10 @@ func (handler *Handler) enterBusyState(e *fsm.Event, state string) {
1292
1280
ctxt := context .Background ()
1293
1281
txsim := txContext .txsimulator
1294
1282
historyQueryExecutor := txContext .historyQueryExecutor
1295
- if calledCcParts . suffix != txContext .chainID {
1296
- lgr := peer .GetLedger (calledCcParts . suffix )
1283
+ if calledCcIns . ChainID != txContext .chainID {
1284
+ lgr := peer .GetLedger (calledCcIns . ChainID )
1297
1285
if lgr == nil {
1298
- payload := "Failed to find ledger for called channel " + calledCcParts . suffix
1286
+ payload := "Failed to find ledger for called channel " + calledCcIns . ChainID
1299
1287
triggerNextStateMsg = & pb.ChaincodeMessage {Type : pb .ChaincodeMessage_ERROR ,
1300
1288
Payload : []byte (payload ), Txid : msg .Txid }
1301
1289
return
@@ -1314,19 +1302,19 @@ func (handler *Handler) enterBusyState(e *fsm.Event, state string) {
1314
1302
1315
1303
if chaincodeLogger .IsEnabledFor (logging .DEBUG ) {
1316
1304
chaincodeLogger .Debugf ("[%s] calling lscc to get chaincode data for %s on channel %s" ,
1317
- shorttxid (msg .Txid ), calledCcParts . name , calledCcParts . suffix )
1305
+ shorttxid (msg .Txid ), calledCcIns . ChaincodeName , calledCcIns . ChainID )
1318
1306
}
1319
1307
1320
1308
//Call LSCC to get the called chaincode artifacts
1321
1309
1322
1310
//is the chaincode a system chaincode ?
1323
- isscc := sysccprovider .GetSystemChaincodeProvider ().IsSysCC (calledCcParts . name )
1311
+ isscc := sysccprovider .GetSystemChaincodeProvider ().IsSysCC (calledCcIns . ChaincodeName )
1324
1312
1325
1313
var cd * ccprovider.ChaincodeData
1326
1314
if ! isscc {
1327
1315
//if its a user chaincode, get the details from LSCC
1328
1316
//Call LSCC to get the called chaincode artifacts
1329
- cd , err = GetChaincodeDataFromLSCC (ctxt , msg .Txid , txContext .signedProp , txContext .proposal , calledCcParts . suffix , calledCcParts . name )
1317
+ cd , err = GetChaincodeDataFromLSCC (ctxt , msg .Txid , txContext .signedProp , txContext .proposal , calledCcIns . ChainID , calledCcIns . ChaincodeName )
1330
1318
if err != nil {
1331
1319
payload := []byte (err .Error ())
1332
1320
chaincodeLogger .Debugf ("[%s]Failed to get chaincoed data (%s) for invoked chaincode. Sending %s" ,
@@ -1336,15 +1324,15 @@ func (handler *Handler) enterBusyState(e *fsm.Event, state string) {
1336
1324
}
1337
1325
} else {
1338
1326
//this is a system cc, just call it directly
1339
- cd = & ccprovider.ChaincodeData {Name : calledCcParts . name , Version : util .GetSysCCVersion ()}
1327
+ cd = & ccprovider.ChaincodeData {Name : calledCcIns . ChaincodeName , Version : util .GetSysCCVersion ()}
1340
1328
}
1341
1329
1342
- cccid := ccprovider .NewCCContext (calledCcParts . suffix , calledCcParts . name , cd .Version , msg .Txid , false , txContext .signedProp , txContext .proposal )
1330
+ cccid := ccprovider .NewCCContext (calledCcIns . ChainID , calledCcIns . ChaincodeName , cd .Version , msg .Txid , false , txContext .signedProp , txContext .proposal )
1343
1331
1344
1332
// Launch the new chaincode if not already running
1345
1333
if chaincodeLogger .IsEnabledFor (logging .DEBUG ) {
1346
1334
chaincodeLogger .Debugf ("[%s] launching chaincode %s on channel %s" ,
1347
- shorttxid (msg .Txid ), calledCcParts . name , calledCcParts . suffix )
1335
+ shorttxid (msg .Txid ), calledCcIns . ChaincodeName , calledCcIns . ChainID )
1348
1336
}
1349
1337
cciSpec := & pb.ChaincodeInvocationSpec {ChaincodeSpec : chaincodeSpec }
1350
1338
_ , chaincodeInput , launchErr := handler .chaincodeSupport .Launch (ctxt , cccid , cciSpec )
0 commit comments