1
1
/*
2
- Copyright IBM Corp. 2017 All Rights Reserved.
2
+ Copyright IBM Corp. All Rights Reserved.
3
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.
4
+ SPDX-License-Identifier: Apache-2.0
15
5
*/
16
6
17
7
package ccprovider
@@ -35,7 +25,7 @@ var ccproviderLogger = flogging.MustGetLogger("ccprovider")
35
25
36
26
var chaincodeInstallPath string
37
27
38
- //CCPackage encapsulates a chaincode package which can be
28
+ // CCPackage encapsulates a chaincode package which can be
39
29
// raw ChaincodeDeploymentSpec
40
30
// SignedChaincodeDeploymentSpec
41
31
// Attempt to keep the interface at a level with minimal
@@ -71,7 +61,7 @@ type CCPackage interface {
71
61
GetId () []byte
72
62
}
73
63
74
- //SetChaincodesPath sets the chaincode path for this peer
64
+ // SetChaincodesPath sets the chaincode path for this peer
75
65
func SetChaincodesPath (path string ) {
76
66
if s , err := os .Stat (path ); err != nil {
77
67
if os .IsNotExist (err ) {
@@ -88,7 +78,7 @@ func SetChaincodesPath(path string) {
88
78
chaincodeInstallPath = path
89
79
}
90
80
91
- //GetChaincodePackage returns the chaincode package from the file system
81
+ // GetChaincodePackage returns the chaincode package from the file system
92
82
func GetChaincodePackage (ccname string , ccversion string ) ([]byte , error ) {
93
83
path := fmt .Sprintf ("%s/%s.%s" , chaincodeInstallPath , ccname , ccversion )
94
84
var ccbytes []byte
@@ -99,7 +89,7 @@ func GetChaincodePackage(ccname string, ccversion string) ([]byte, error) {
99
89
return ccbytes , nil
100
90
}
101
91
102
- //ChaincodePackageExists returns whether the chaincode package exists in the file system
92
+ // ChaincodePackageExists returns whether the chaincode package exists in the file system
103
93
func ChaincodePackageExists (ccname string , ccversion string ) (bool , error ) {
104
94
path := filepath .Join (chaincodeInstallPath , ccname + "." + ccversion )
105
95
_ , err := os .Stat (path )
@@ -111,7 +101,7 @@ func ChaincodePackageExists(ccname string, ccversion string) (bool, error) {
111
101
}
112
102
113
103
type CCCacheSupport interface {
114
- //GetChaincode is needed by the cache to get chaincode data
104
+ // GetChaincode is needed by the cache to get chaincode data
115
105
GetChaincode (ccname string , ccversion string ) (CCPackage , error )
116
106
}
117
107
@@ -121,11 +111,11 @@ type CCInfoFSImpl struct{}
121
111
122
112
// GetChaincodeFromFS this is a wrapper for hiding package implementation.
123
113
func (* CCInfoFSImpl ) GetChaincode (ccname string , ccversion string ) (CCPackage , error ) {
124
- //try raw CDS
114
+ // try raw CDS
125
115
cccdspack := & CDSPackage {}
126
116
_ , _ , err := cccdspack .InitFromFS (ccname , ccversion )
127
117
if err != nil {
128
- //try signed CDS
118
+ // try signed CDS
129
119
ccscdspack := & SignedCDSPackage {}
130
120
_ , _ , err = ccscdspack .InitFromFS (ccname , ccversion )
131
121
if err != nil {
@@ -243,10 +233,10 @@ func CheckInstantiationPolicy(name, version string, cdLedger *ChaincodeData) err
243
233
// GetCCPackage tries each known package implementation one by one
244
234
// till the right package is found
245
235
func GetCCPackage (buf []byte ) (CCPackage , error ) {
246
- //try raw CDS
236
+ // try raw CDS
247
237
cccdspack := & CDSPackage {}
248
238
if _ , err := cccdspack .InitFromBuffer (buf ); err != nil {
249
- //try signed CDS
239
+ // try signed CDS
250
240
ccscdspack := & SignedCDSPackage {}
251
241
if _ , err := ccscdspack .InitFromBuffer (buf ); err != nil {
252
242
return nil , err
@@ -314,97 +304,105 @@ func GetInstalledChaincodes() (*pb.ChaincodeQueryResponse, error) {
314
304
return cqr , nil
315
305
}
316
306
317
- //CCContext pass this around instead of string of args
307
+ // CCContext pass this around instead of string of args
318
308
type CCContext struct {
319
- //ChainID chain id
309
+ // ChainID chain id
320
310
ChainID string
321
311
322
- //Name chaincode name
312
+ // Name chaincode name
323
313
Name string
324
314
325
- //Version used to construct the chaincode image and register
315
+ // Version used to construct the chaincode image and register
326
316
Version string
327
317
328
- //TxID is the transaction id for the proposal (if any)
318
+ // TxID is the transaction id for the proposal (if any)
329
319
TxID string
330
320
331
- //Syscc is this a system chaincode
321
+ // Syscc is this a system chaincode
332
322
Syscc bool
333
323
334
- //SignedProposal for this invoke (if any)
335
- //this is kept here for access control and in case we need to pass something
336
- //from this to the chaincode
324
+ // SignedProposal for this invoke (if any) this is kept here for access
325
+ // control and in case we need to pass something from this to the chaincode
337
326
SignedProposal * pb.SignedProposal
338
327
339
- //Proposal for this invoke (if any)
340
- //this is kept here just in case we need to pass something
341
- //from this to the chaincode
328
+ // Proposal for this invoke (if any) this is kept here just in case we need to
329
+ // pass something from this to the chaincode
342
330
Proposal * pb.Proposal
343
331
344
- //this is not set but computed (note that this is not exported. use GetCanonicalName)
332
+ // canonicalName is not set but computed
345
333
canonicalName string
346
334
347
335
// this is additional data passed to the chaincode
348
336
ProposalDecorations map [string ][]byte
349
337
}
350
338
351
- //NewCCContext just construct a new struct with whatever args
352
- func NewCCContext (cid , name , version , txid string , syscc bool , signedProp * pb.SignedProposal , prop * pb.Proposal ) * CCContext {
353
- //version CANNOT be empty. The chaincode namespace has to use version and chain name.
354
- //All system chaincodes share the same version given by utils.GetSysCCVersion. Note
355
- //that neither Chain Name or Version are stored in a chaincodes state on the ledger
356
- if version == "" {
357
- panic (fmt .Sprintf ("---empty version---(chain=%s,chaincode=%s,version=%s,txid=%s,syscc=%t,proposal=%p" , cid , name , version , txid , syscc , prop ))
339
+ // NewCCContext just construct a new struct with whatever args
340
+ func NewCCContext (cname , name , version , txid string , syscc bool , signedProp * pb.SignedProposal , prop * pb.Proposal ) * CCContext {
341
+ cccid := & CCContext {
342
+ ChainID : cname ,
343
+ Name : name ,
344
+ Version : version ,
345
+ TxID : txid ,
346
+ Syscc : syscc ,
347
+ SignedProposal : signedProp ,
348
+ Proposal : prop ,
349
+ canonicalName : name + ":" + version ,
350
+ ProposalDecorations : nil ,
358
351
}
359
352
360
- canName := name + ":" + version
361
-
362
- cccid := & CCContext { cid , name , version , txid , syscc , signedProp , prop , canName , nil }
363
-
364
- ccproviderLogger . Debugf ( "NewCCCC (chain=%s,chaincode=%s,version=%s,txid=%s,syscc=%t,proposal=%p,canname=%s" , cid , name , version , txid , syscc , prop , cccid . canonicalName )
353
+ // The version CANNOT be empty. The chaincode namespace has to use version and chain name.
354
+ // Note that neither channel name nor version are stored on the ledger.
355
+ if version == "" {
356
+ panic ( fmt . Sprintf ( "---empty version---(%s)" , cccid ))
357
+ }
365
358
359
+ ccproviderLogger .Debugf ("NewCCCC(%s)" , cccid )
366
360
return cccid
367
361
}
368
362
369
- //GetCanonicalName returns the canonical name associated with the proposal context
363
+ func (cccid * CCContext ) String () string {
364
+ return fmt .Sprintf ("chain=%s,chaincode=%s,version=%s,txid=%s,syscc=%t,proposal=%p,canname=%s" ,
365
+ cccid .ChainID , cccid .Name , cccid .Version , cccid .TxID , cccid .Syscc , cccid .Proposal , cccid .canonicalName )
366
+ }
367
+
368
+ // GetCanonicalName returns the canonical name associated with the proposal context
370
369
func (cccid * CCContext ) GetCanonicalName () string {
371
370
if cccid .canonicalName == "" {
372
- panic (fmt .Sprintf ("cccid not constructed using NewCCContext(chain=%s,chaincode=%s,version=%s,txid=%s,syscc=%t) " , cccid . ChainID , cccid . Name , cccid . Version , cccid . TxID , cccid . Syscc ))
371
+ panic (fmt .Sprintf ("missing canonical name: %s " , cccid ))
373
372
}
374
373
375
374
return cccid .canonicalName
376
375
}
377
376
378
377
//-------- ChaincodeData is stored on the LSCC -------
379
378
380
- //ChaincodeData defines the datastructure for chaincodes to be serialized by proto
381
- //Type provides an additional check by directing to use a specific package after instantiation
382
- //Data is Type specifc (see CDSPackage and SignedCDSPackage)
379
+ // ChaincodeData defines the datastructure for chaincodes to be serialized by proto
380
+ // Type provides an additional check by directing to use a specific package after instantiation
381
+ // Data is Type specifc (see CDSPackage and SignedCDSPackage)
383
382
type ChaincodeData struct {
384
- //Name of the chaincode
383
+ // Name of the chaincode
385
384
Name string `protobuf:"bytes,1,opt,name=name"`
386
385
387
- //Version of the chaincode
386
+ // Version of the chaincode
388
387
Version string `protobuf:"bytes,2,opt,name=version"`
389
388
390
- //Escc for the chaincode instance
389
+ // Escc for the chaincode instance
391
390
Escc string `protobuf:"bytes,3,opt,name=escc"`
392
391
393
- //Vscc for the chaincode instance
392
+ // Vscc for the chaincode instance
394
393
Vscc string `protobuf:"bytes,4,opt,name=vscc"`
395
394
396
- //Policy endorsement policy for the chaincode instance
395
+ // Policy endorsement policy for the chaincode instance
397
396
Policy []byte `protobuf:"bytes,5,opt,name=policy,proto3"`
398
397
399
- //Data data specific to the package
398
+ // Data data specific to the package
400
399
Data []byte `protobuf:"bytes,6,opt,name=data,proto3"`
401
400
402
- //Id of the chaincode that's the unique fingerprint for the CC
403
- //This is not currently used anywhere but serves as a good
404
- //eyecatcher
401
+ // Id of the chaincode that's the unique fingerprint for the CC This is not
402
+ // currently used anywhere but serves as a good eyecatcher
405
403
Id []byte `protobuf:"bytes,7,opt,name=id,proto3"`
406
404
407
- //InstantiationPolicy for the chaincode
405
+ // InstantiationPolicy for the chaincode
408
406
InstantiationPolicy []byte `protobuf:"bytes,8,opt,name=instantiation_policy,proto3"`
409
407
}
410
408
@@ -439,15 +437,15 @@ func (cd *ChaincodeData) Endorsement() string {
439
437
return cd .Escc
440
438
}
441
439
442
- //implement functions needed from proto.Message for proto's mar/unmarshal functions
440
+ // implement functions needed from proto.Message for proto's mar/unmarshal functions
443
441
444
- //Reset resets
442
+ // Reset resets
445
443
func (cd * ChaincodeData ) Reset () { * cd = ChaincodeData {} }
446
444
447
- //String converts to string
445
+ // String converts to string
448
446
func (cd * ChaincodeData ) String () string { return proto .CompactTextString (cd ) }
449
447
450
- //ProtoMessage just exists to make proto happy
448
+ // ProtoMessage just exists to make proto happy
451
449
func (* ChaincodeData ) ProtoMessage () {}
452
450
453
451
// ChaincodeProvider provides an abstraction layer that is
0 commit comments