@@ -33,6 +33,7 @@ import (
33
33
34
34
"github.com/hyperledger/fabric/common/flogging"
35
35
"github.com/hyperledger/fabric/core/chaincode/shim"
36
+ "github.com/hyperledger/fabric/core/common/ccprovider"
36
37
"github.com/hyperledger/fabric/core/container"
37
38
"github.com/hyperledger/fabric/core/container/ccintf"
38
39
"github.com/hyperledger/fabric/core/ledger"
@@ -66,59 +67,6 @@ func getTxSimulator(context context.Context) ledger.TxSimulator {
66
67
return nil
67
68
}
68
69
69
- //CCContext pass this around instead of string of args
70
- type CCContext struct {
71
- //ChainID chain id
72
- ChainID string
73
-
74
- //Name chaincode name
75
- Name string
76
-
77
- //Version used to construct the chaincode image and register
78
- Version string
79
-
80
- //TxID is the transaction id for the proposal (if any)
81
- TxID string
82
-
83
- //Syscc is this a system chaincode
84
- Syscc bool
85
-
86
- //Proposal for this invoke (if any)
87
- //this is kept here just in case we need to pass something
88
- //from this to the chaincode
89
- Proposal * pb.Proposal
90
-
91
- //this is not set but computed (note that this is not exported. use GetCanonicalName)
92
- canonicalName string
93
- }
94
-
95
- //NewCCContext just construct a new struct with whatever args
96
- func NewCCContext (cid , name , version , txid string , syscc bool , prop * pb.Proposal ) * CCContext {
97
- //version CANNOT be empty. The chaincode namespace has to use version and chain name.
98
- //All system chaincodes share the same version given by utils.GetSysCCVersion. Note
99
- //that neither Chain Name or Version are stored in a chaincodes state on the ledger
100
- if version == "" {
101
- panic (fmt .Sprintf ("---empty version---(chain=%s,chaincode=%s,version=%s,txid=%s,syscc=%t,proposal=%p" , cid , name , version , txid , syscc , prop ))
102
- }
103
-
104
- canName := name + ":" + version + "/" + cid
105
-
106
- cccid := & CCContext {cid , name , version , txid , syscc , prop , canName }
107
-
108
- chaincodeLogger .Infof ("NewCCCC (chain=%s,chaincode=%s,version=%s,txid=%s,syscc=%t,proposal=%p,canname=%s" , cid , name , version , txid , syscc , prop , cccid .canonicalName )
109
-
110
- return cccid
111
- }
112
-
113
- //GetCanonicalName returns the canonical name associated with the proposal context
114
- func (cccid * CCContext ) GetCanonicalName () string {
115
- if cccid .canonicalName == "" {
116
- 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 ))
117
- }
118
-
119
- return cccid .canonicalName
120
- }
121
-
122
70
//
123
71
//chaincode runtime environment encapsulates handler and container environment
124
72
//This is where the VM that's running the chaincode would hook in
@@ -317,7 +265,7 @@ func (chaincodeSupport *ChaincodeSupport) deregisterHandler(chaincodehandler *Ha
317
265
}
318
266
319
267
// Based on state of chaincode send either init or ready to move to ready state
320
- func (chaincodeSupport * ChaincodeSupport ) sendInitOrReady (context context.Context , cccid * CCContext , initArgs [][]byte , timeout time.Duration ) error {
268
+ func (chaincodeSupport * ChaincodeSupport ) sendInitOrReady (context context.Context , cccid * ccprovider. CCContext , initArgs [][]byte , timeout time.Duration ) error {
321
269
canName := cccid .GetCanonicalName ()
322
270
chaincodeSupport .runningChaincodes .Lock ()
323
271
//if its in the map, there must be a connected stream...nothing to do
@@ -362,7 +310,7 @@ func (chaincodeSupport *ChaincodeSupport) sendInitOrReady(context context.Contex
362
310
}
363
311
364
312
//get args and env given chaincodeID
365
- func (chaincodeSupport * ChaincodeSupport ) getArgsAndEnv (cccid * CCContext , cLang pb.ChaincodeSpec_Type ) (args []string , envs []string , err error ) {
313
+ func (chaincodeSupport * ChaincodeSupport ) getArgsAndEnv (cccid * ccprovider. CCContext , cLang pb.ChaincodeSpec_Type ) (args []string , envs []string , err error ) {
366
314
canName := cccid .GetCanonicalName ()
367
315
envs = []string {"CORE_CHAINCODE_ID_NAME=" + canName }
368
316
//if TLS is enabled, pass TLS material to chaincode
@@ -407,7 +355,7 @@ func (chaincodeSupport *ChaincodeSupport) getArgsAndEnv(cccid *CCContext, cLang
407
355
}
408
356
409
357
// launchAndWaitForRegister will launch container if not already running. Use the targz to create the image if not found
410
- func (chaincodeSupport * ChaincodeSupport ) launchAndWaitForRegister (ctxt context.Context , cccid * CCContext , cds * pb.ChaincodeDeploymentSpec , cLang pb.ChaincodeSpec_Type , targz io.Reader ) error {
358
+ func (chaincodeSupport * ChaincodeSupport ) launchAndWaitForRegister (ctxt context.Context , cccid * ccprovider. CCContext , cds * pb.ChaincodeDeploymentSpec , cLang pb.ChaincodeSpec_Type , targz io.Reader ) error {
411
359
canName := cccid .GetCanonicalName ()
412
360
if canName == "" {
413
361
return fmt .Errorf ("chaincode name not set" )
@@ -472,7 +420,7 @@ func (chaincodeSupport *ChaincodeSupport) launchAndWaitForRegister(ctxt context.
472
420
}
473
421
474
422
//Stop stops a chaincode if running
475
- func (chaincodeSupport * ChaincodeSupport ) Stop (context context.Context , cccid * CCContext , cds * pb.ChaincodeDeploymentSpec ) error {
423
+ func (chaincodeSupport * ChaincodeSupport ) Stop (context context.Context , cccid * ccprovider. CCContext , cds * pb.ChaincodeDeploymentSpec ) error {
476
424
canName := cccid .GetCanonicalName ()
477
425
if canName == "" {
478
426
return fmt .Errorf ("chaincode name not set" )
@@ -504,7 +452,7 @@ func (chaincodeSupport *ChaincodeSupport) Stop(context context.Context, cccid *C
504
452
}
505
453
506
454
// Launch will launch the chaincode if not running (if running return nil) and will wait for handler of the chaincode to get into FSM ready state.
507
- func (chaincodeSupport * ChaincodeSupport ) Launch (context context.Context , cccid * CCContext , spec interface {}) (* pb.ChaincodeID , * pb.ChaincodeInput , error ) {
455
+ func (chaincodeSupport * ChaincodeSupport ) Launch (context context.Context , cccid * ccprovider. CCContext , spec interface {}) (* pb.ChaincodeID , * pb.ChaincodeInput , error ) {
508
456
//build the chaincode
509
457
var cID * pb.ChaincodeID
510
458
var cMsg * pb.ChaincodeInput
@@ -622,7 +570,7 @@ func (chaincodeSupport *ChaincodeSupport) getVMType(cds *pb.ChaincodeDeploymentS
622
570
}
623
571
624
572
// Deploy deploys the chaincode if not in development mode where user is running the chaincode.
625
- func (chaincodeSupport * ChaincodeSupport ) Deploy (context context.Context , cccid * CCContext , cds * pb.ChaincodeDeploymentSpec ) (* pb.ChaincodeDeploymentSpec , error ) {
573
+ func (chaincodeSupport * ChaincodeSupport ) Deploy (context context.Context , cccid * ccprovider. CCContext , cds * pb.ChaincodeDeploymentSpec ) (* pb.ChaincodeDeploymentSpec , error ) {
626
574
cLang := cds .ChaincodeSpec .Type
627
575
canName := cccid .GetCanonicalName ()
628
576
@@ -682,7 +630,7 @@ func createTransactionMessage(txid string, cMsg *pb.ChaincodeInput) (*pb.Chainco
682
630
}
683
631
684
632
// Execute executes a transaction and waits for it to complete until a timeout value.
685
- func (chaincodeSupport * ChaincodeSupport ) Execute (ctxt context.Context , cccid * CCContext , msg * pb.ChaincodeMessage , timeout time.Duration ) (* pb.ChaincodeMessage , error ) {
633
+ func (chaincodeSupport * ChaincodeSupport ) Execute (ctxt context.Context , cccid * ccprovider. CCContext , msg * pb.ChaincodeMessage , timeout time.Duration ) (* pb.ChaincodeMessage , error ) {
686
634
canName := cccid .GetCanonicalName ()
687
635
chaincodeSupport .runningChaincodes .Lock ()
688
636
//we expect the chaincode to be running... sanity check
0 commit comments