@@ -52,8 +52,8 @@ type Support interface {
52
52
// GetTransactionByID retrieves a transaction by id
53
53
GetTransactionByID (chid , txID string ) (* pb.ProcessedTransaction , error )
54
54
55
- //IsSysCC returns true if the name matches a system chaincode's
56
- //system chaincode names are system, chain wide
55
+ // IsSysCC returns true if the name matches a system chaincode's
56
+ // system chaincode names are system, chain wide
57
57
IsSysCC (name string ) bool
58
58
59
59
//Execute - execute proposal, return original response of chaincode
@@ -62,8 +62,8 @@ type Support interface {
62
62
// GetChaincodeDefinition returns ccprovider.ChaincodeDefinition for the chaincode with the supplied name
63
63
GetChaincodeDefinition (ctx context.Context , chainID string , txid string , signedProp * pb.SignedProposal , prop * pb.Proposal , chaincodeID string , txsim ledger.TxSimulator ) (ccprovider.ChaincodeDefinition , error )
64
64
65
- //CheckACL checks the ACL for the resource for the Channel using the
66
- //SignedProposal from which an id can be extracted for testing against a policy
65
+ // CheckACL checks the ACL for the resource for the channel using the
66
+ // SignedProposal from which an id can be extracted for testing against a policy
67
67
CheckACL (signedProp * pb.SignedProposal , chdr * common.ChannelHeader , shdr * common.SignatureHeader , hdrext * pb.ChaincodeHeaderExtension ) error
68
68
69
69
// IsJavaCC returns true if the CDS package bytes describe a chaincode
@@ -111,7 +111,7 @@ func NewEndorserServer(privDist privateDataDistributor, s Support) *Endorser {
111
111
return e
112
112
}
113
113
114
- //call specified chaincode (system or user)
114
+ // call specified chaincode (system or user)
115
115
func (e * Endorser ) callChaincode (ctxt context.Context , chainID string , version string , txid string , signedProp * pb.SignedProposal , prop * pb.Proposal , cis * pb.ChaincodeInvocationSpec , cid * pb.ChaincodeID , txsim ledger.TxSimulator ) (* pb.Response , * pb.ChaincodeEvent , error ) {
116
116
endorserLogger .Debugf ("[%s][%s] Entry chaincode: %s version: %s" , chainID , txid , cid , version )
117
117
defer endorserLogger .Debugf ("[%s][%s] Exit" , chainID , txid )
@@ -123,37 +123,37 @@ func (e *Endorser) callChaincode(ctxt context.Context, chainID string, version s
123
123
ctxt = context .WithValue (ctxt , chaincode .TXSimulatorKey , txsim )
124
124
}
125
125
126
- //is this a system chaincode
126
+ // is this a system chaincode
127
127
scc := e .s .IsSysCC (cid .Name )
128
128
129
129
res , ccevent , err = e .s .Execute (ctxt , chainID , cid .Name , version , txid , scc , signedProp , prop , cis )
130
130
if err != nil {
131
131
return nil , nil , err
132
132
}
133
133
134
- //per doc anything < 400 can be sent as TX.
135
- //fabric errors will always be >= 400 (ie, unambiguous errors )
136
- //"lscc" will respond with status 200 or 500 (ie, unambiguous OK or ERROR)
134
+ // per doc anything < 400 can be sent as TX.
135
+ // fabric errors will always be >= 400 (ie, unambiguous errors )
136
+ // "lscc" will respond with status 200 or 500 (ie, unambiguous OK or ERROR)
137
137
if res .Status >= shim .ERRORTHRESHOLD {
138
138
return res , nil , nil
139
139
}
140
140
141
- //----- BEGIN - SECTION THAT MAY NEED TO BE DONE IN LSCC ------
142
- //if this a call to deploy a chaincode, We need a mechanism
143
- //to pass TxSimulator into LSCC. Till that is worked out this
144
- //special code does the actual deploy, upgrade here so as to collect
145
- //all state under one TxSimulator
141
+ // ----- BEGIN - SECTION THAT MAY NEED TO BE DONE IN LSCC ------
142
+ // if this a call to deploy a chaincode, We need a mechanism
143
+ // to pass TxSimulator into LSCC. Till that is worked out this
144
+ // special code does the actual deploy, upgrade here so as to collect
145
+ // all state under one TxSimulator
146
146
//
147
- //NOTE that if there's an error all simulation, including the chaincode
148
- //table changes in lscc will be thrown away
147
+ // NOTE that if there's an error all simulation, including the chaincode
148
+ // table changes in lscc will be thrown away
149
149
if cid .Name == "lscc" && len (cis .ChaincodeSpec .Input .Args ) >= 3 && (string (cis .ChaincodeSpec .Input .Args [0 ]) == "deploy" || string (cis .ChaincodeSpec .Input .Args [0 ]) == "upgrade" ) {
150
150
var cds * pb.ChaincodeDeploymentSpec
151
151
cds , err = putils .GetChaincodeDeploymentSpec (cis .ChaincodeSpec .Input .Args [2 ])
152
152
if err != nil {
153
153
return nil , nil , err
154
154
}
155
155
156
- //this should not be a system chaincode
156
+ // this should not be a system chaincode
157
157
if e .s .IsSysCC (cds .ChaincodeSpec .ChaincodeId .Name ) {
158
158
return nil , nil , errors .Errorf ("attempting to deploy a system chaincode %s/%s" , cds .ChaincodeSpec .ChaincodeId .Name , chainID )
159
159
}
@@ -163,25 +163,25 @@ func (e *Endorser) callChaincode(ctxt context.Context, chainID string, version s
163
163
return nil , nil , err
164
164
}
165
165
}
166
- //----- END -------
166
+ // ----- END -------
167
167
168
168
return res , ccevent , err
169
169
}
170
170
171
- //TO BE REMOVED WHEN JAVA CC IS ENABLED
172
- //disableJavaCCInst if trying to install, instantiate or upgrade Java CC
171
+ // TO BE REMOVED WHEN JAVA CC IS ENABLED
172
+ // disableJavaCCInst if trying to install, instantiate or upgrade Java CC
173
173
func (e * Endorser ) DisableJavaCCInst (cid * pb.ChaincodeID , cis * pb.ChaincodeInvocationSpec ) error {
174
- //if not lscc we don't care
174
+ // if not lscc we don't care
175
175
if cid .Name != "lscc" {
176
176
return nil
177
177
}
178
178
179
- //non-nil spec ? leave it to callers to handle error if this is an error
179
+ // non-nil spec ? leave it to callers to handle error if this is an error
180
180
if cis .ChaincodeSpec == nil || cis .ChaincodeSpec .Input == nil {
181
181
return nil
182
182
}
183
183
184
- //should at least have a command arg, leave it to callers if this is an error
184
+ // should at least have a command arg, leave it to callers if this is an error
185
185
if len (cis .ChaincodeSpec .Input .Args ) < 1 {
186
186
return nil
187
187
}
@@ -193,7 +193,7 @@ func (e *Endorser) DisableJavaCCInst(cid *pb.ChaincodeID, cis *pb.ChaincodeInvoc
193
193
case "deploy" , "upgrade" :
194
194
argNo = 2
195
195
default :
196
- //what else can it be ? leave it caller to handle it if error
196
+ // what else can it be ? leave it caller to handle it if error
197
197
return nil
198
198
}
199
199
@@ -205,7 +205,7 @@ func (e *Endorser) DisableJavaCCInst(cid *pb.ChaincodeID, cis *pb.ChaincodeInvoc
205
205
endorserLogger .Debug ("java chaincode enabled" )
206
206
} else {
207
207
endorserLogger .Debug ("java chaincode disabled" )
208
- //finally, if JAVA not enabled error out
208
+ // finally, if JAVA not enabled error out
209
209
isjava , err := e .s .IsJavaCC (cis .ChaincodeSpec .Input .Args [argNo ])
210
210
if err != nil {
211
211
return err
@@ -215,23 +215,23 @@ func (e *Endorser) DisableJavaCCInst(cid *pb.ChaincodeID, cis *pb.ChaincodeInvoc
215
215
}
216
216
}
217
217
218
- //not a java install, instantiate or upgrade op
218
+ // not a java install, instantiate or upgrade op
219
219
return nil
220
220
}
221
221
222
- //SimulateProposal simulates the proposal by calling the chaincode
222
+ // SimulateProposal simulates the proposal by calling the chaincode
223
223
func (e * Endorser ) SimulateProposal (ctx context.Context , chainID string , txid string , signedProp * pb.SignedProposal , prop * pb.Proposal , cid * pb.ChaincodeID , txsim ledger.TxSimulator ) (ccprovider.ChaincodeDefinition , * pb.Response , []byte , * pb.ChaincodeEvent , error ) {
224
224
endorserLogger .Debugf ("[%s][%s] Entry chaincode: %s" , chainID , shorttxid (txid ), cid )
225
225
defer endorserLogger .Debugf ("[%s][%s] Exit" , chainID , shorttxid (txid ))
226
- //we do expect the payload to be a ChaincodeInvocationSpec
227
- //if we are supporting other payloads in future, this be glaringly point
228
- //as something that should change
226
+ // we do expect the payload to be a ChaincodeInvocationSpec
227
+ // if we are supporting other payloads in future, this be glaringly point
228
+ // as something that should change
229
229
cis , err := putils .GetChaincodeInvocationSpec (prop )
230
230
if err != nil {
231
231
return nil , nil , nil , nil , err
232
232
}
233
233
234
- //disable Java install,instantiate,upgrade for now
234
+ // disable Java install,instantiate,upgrade for now
235
235
if err = e .DisableJavaCCInst (cid , cis ); err != nil {
236
236
return nil , nil , nil , nil , err
237
237
}
@@ -254,7 +254,7 @@ func (e *Endorser) SimulateProposal(ctx context.Context, chainID string, txid st
254
254
version = util .GetSysCCVersion ()
255
255
}
256
256
257
- //---3. execute the proposal and get simulation results
257
+ // ---3. execute the proposal and get simulation results
258
258
var simResult * ledger.TxSimulationResults
259
259
var pubSimResBytes []byte
260
260
var res * pb.Response
@@ -298,15 +298,15 @@ func (e *Endorser) SimulateProposal(ctx context.Context, chainID string, txid st
298
298
return cdLedger , res , pubSimResBytes , ccevent , nil
299
299
}
300
300
301
- //endorse the proposal by calling the ESCC
301
+ // endorse the proposal by calling the ESCC
302
302
func (e * Endorser ) endorseProposal (_ context.Context , chainID string , txid string , signedProp * pb.SignedProposal , proposal * pb.Proposal , response * pb.Response , simRes []byte , event * pb.ChaincodeEvent , visibility []byte , ccid * pb.ChaincodeID , txsim ledger.TxSimulator , cd ccprovider.ChaincodeDefinition ) (* pb.ProposalResponse , error ) {
303
303
endorserLogger .Debugf ("[%s][%s] Entry chaincode: %s" , chainID , shorttxid (txid ), ccid )
304
304
defer endorserLogger .Debugf ("[%s][%s] Exit" , chainID , shorttxid (txid ))
305
305
306
306
isSysCC := cd == nil
307
307
// 1) extract the name of the escc that is requested to endorse this chaincode
308
308
var escc string
309
- //ie, "lscc" or system chaincodes
309
+ // ie, "lscc" or system chaincodes
310
310
if isSysCC {
311
311
escc = "escc"
312
312
} else {
@@ -349,7 +349,7 @@ func (e *Endorser) endorseProposal(_ context.Context, chainID string, txid strin
349
349
return e .s .EndorseWithPlugin (ctx )
350
350
}
351
351
352
- //preProcess checks the tx proposal headers, uniqueness and ACL
352
+ // preProcess checks the tx proposal headers, uniqueness and ACL
353
353
func (e * Endorser ) preProcess (signedProp * pb.SignedProposal ) (* validateResult , error ) {
354
354
vr := & validateResult {}
355
355
// at first, we check whether the message is valid
@@ -424,10 +424,10 @@ func (e *Endorser) preProcess(signedProp *pb.SignedProposal) (*validateResult, e
424
424
// ProcessProposal process the Proposal
425
425
func (e * Endorser ) ProcessProposal (ctx context.Context , signedProp * pb.SignedProposal ) (* pb.ProposalResponse , error ) {
426
426
addr := util .ExtractRemoteAddress (ctx )
427
- endorserLogger .Debug ("Entering: Got request from" , addr )
428
- defer endorserLogger .Debugf ("Exit: request from" , addr )
427
+ endorserLogger .Debug ("Entering: request from" , addr )
428
+ defer endorserLogger .Debug ("Exit: request from" , addr )
429
429
430
- //0 -- check and validate
430
+ // 0 -- check and validate
431
431
vr , err := e .preProcess (signedProp )
432
432
if err != nil {
433
433
resp := vr .resp
@@ -462,14 +462,14 @@ func (e *Endorser) ProcessProposal(ctx context.Context, signedProp *pb.SignedPro
462
462
// around separately, since eventually it gets added to context anyways
463
463
ctx = context .WithValue (ctx , chaincode .HistoryQueryExecutorKey , historyQueryExecutor )
464
464
}
465
- //this could be a request to a chainless SysCC
465
+ // this could be a request to a chainless SysCC
466
466
467
467
// TODO: if the proposal has an extension, it will be of type ChaincodeAction;
468
468
// if it's present it means that no simulation is to be performed because
469
469
// we're trying to emulate a submitting peer. On the other hand, we need
470
470
// to validate the supplied action before endorsing it
471
471
472
- //1 -- simulate
472
+ // 1 -- simulate
473
473
cd , res , simulationResult , ccevent , err := e .SimulateProposal (ctx , chainID , txid , signedProp , prop , hdrExt .ChaincodeId , txsim )
474
474
if err != nil {
475
475
return & pb.ProposalResponse {Response : & pb.Response {Status : 500 , Message : err .Error ()}}, nil
@@ -493,11 +493,11 @@ func (e *Endorser) ProcessProposal(ctx context.Context, signedProp *pb.SignedPro
493
493
}
494
494
}
495
495
496
- //2 -- endorse and get a marshalled ProposalResponse message
496
+ // 2 -- endorse and get a marshalled ProposalResponse message
497
497
var pResp * pb.ProposalResponse
498
498
499
- //TODO till we implement global ESCC, CSCC for system chaincodes
500
- //chainless proposals (such as CSCC) don't have to be endorsed
499
+ // TODO till we implement global ESCC, CSCC for system chaincodes
500
+ // chainless proposals (such as CSCC) don't have to be endorsed
501
501
if chainID == "" {
502
502
pResp = & pb.ProposalResponse {Response : res }
503
503
} else {
0 commit comments