Skip to content

Commit 36bc31e

Browse files
committed
[FAB-9951] use *CCContext instead of interface{}
Change-Id: Iddad6dd0382391267e90c0ce1dc771cae14e6c2f Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
1 parent d97062a commit 36bc31e

File tree

5 files changed

+16
-40
lines changed

5 files changed

+16
-40
lines changed

core/chaincode/ccproviderimpl.go

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ type ccProviderImpl struct {
5454
cs *ChaincodeSupport
5555
}
5656

57-
// ccProviderContextImpl contains the state that is passed around to calls to methods of ccProviderImpl
58-
type ccProviderContextImpl struct {
59-
ctx *ccprovider.CCContext
60-
}
61-
6257
// GetContext returns a context for the supplied ledger, with the appropriate tx simulator
6358
func (c *ccProviderImpl) GetContext(ledger ledger.PeerLedger, txid string) (context.Context, ledger.TxSimulator, error) {
6459
var err error
@@ -71,36 +66,27 @@ func (c *ccProviderImpl) GetContext(ledger ledger.PeerLedger, txid string) (cont
7166
return ctxt, txsim, nil
7267
}
7368

74-
// GetCCContext returns an interface that encapsulates a
75-
// chaincode context; the interface is required to avoid
76-
// referencing the chaincode package from the interface definition
77-
func (c *ccProviderImpl) GetCCContext(cid, name, version, txid string, syscc bool, signedProp *pb.SignedProposal, prop *pb.Proposal) interface{} {
78-
ctx := ccprovider.NewCCContext(cid, name, version, txid, syscc, signedProp, prop)
79-
return &ccProviderContextImpl{ctx: ctx}
80-
}
81-
8269
// ExecuteChaincode executes the chaincode specified in the context with the specified arguments
83-
func (c *ccProviderImpl) ExecuteChaincode(ctxt context.Context, cccid interface{}, args [][]byte) (*pb.Response, *pb.ChaincodeEvent, error) {
84-
providerContext := cccid.(*ccProviderContextImpl)
70+
func (c *ccProviderImpl) ExecuteChaincode(ctxt context.Context, cccid *ccprovider.CCContext, args [][]byte) (*pb.Response, *pb.ChaincodeEvent, error) {
8571
invocationSpec := &pb.ChaincodeInvocationSpec{
8672
ChaincodeSpec: &pb.ChaincodeSpec{
8773
Type: pb.ChaincodeSpec_GOLANG,
88-
ChaincodeId: &pb.ChaincodeID{Name: providerContext.ctx.Name},
74+
ChaincodeId: &pb.ChaincodeID{Name: cccid.Name},
8975
Input: &pb.ChaincodeInput{Args: args},
9076
},
9177
}
92-
return c.cs.Execute(ctxt, providerContext.ctx, invocationSpec)
78+
return c.cs.Execute(ctxt, cccid, invocationSpec)
9379
}
9480

9581
// Execute executes the chaincode given context and spec (invocation or deploy)
96-
func (c *ccProviderImpl) Execute(ctxt context.Context, cccid interface{}, spec ccprovider.ChaincodeSpecGetter) (*pb.Response, *pb.ChaincodeEvent, error) {
97-
return c.cs.Execute(ctxt, cccid.(*ccProviderContextImpl).ctx, spec)
82+
func (c *ccProviderImpl) Execute(ctxt context.Context, cccid *ccprovider.CCContext, spec ccprovider.ChaincodeSpecGetter) (*pb.Response, *pb.ChaincodeEvent, error) {
83+
return c.cs.Execute(ctxt, cccid, spec)
9884
}
9985

10086
// Stop stops the chaincode given context and spec
101-
func (c *ccProviderImpl) Stop(ctxt context.Context, cccid interface{}, spec *pb.ChaincodeDeploymentSpec) error {
87+
func (c *ccProviderImpl) Stop(ctxt context.Context, cccid *ccprovider.CCContext, spec *pb.ChaincodeDeploymentSpec) error {
10288
if c.cs != nil {
103-
return c.cs.Stop(ctxt, cccid.(*ccProviderContextImpl).ctx, spec)
89+
return c.cs.Stop(ctxt, cccid, spec)
10490
}
10591
panic("ChaincodeSupport not initialized")
10692
}

core/committer/txvalidator/vscc_validator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ func (v *vsccValidatorImpl) VSCCValidateTxForCC(envBytes []byte, txid, chid, vsc
263263

264264
// get context to invoke VSCC
265265
vscctxid := coreUtil.GenerateUUID()
266-
cccid := v.ccprovider.GetCCContext(chid, vsccName, vsccVer, vscctxid, true, nil, nil)
266+
cccid := ccprovider.NewCCContext(chid, vsccName, vsccVer, vscctxid, true, nil, nil)
267267

268268
// invoke VSCC
269269
logger.Debug("Invoking VSCC txid", txid, "chaindID", chid)

core/common/ccprovider/ccprovider.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -495,14 +495,12 @@ type ChaincodeProvider interface {
495495
// caller's responsability to release the simulator by calling its
496496
// done method once it is no longer useful
497497
GetContext(ledger ledger.PeerLedger, txid string) (context.Context, ledger.TxSimulator, error)
498-
// GetCCContext returns an opaque chaincode context
499-
GetCCContext(cid, name, version, txid string, syscc bool, signedProp *pb.SignedProposal, prop *pb.Proposal) interface{}
500498
// ExecuteChaincode executes the chaincode given context and args
501-
ExecuteChaincode(ctxt context.Context, cccid interface{}, args [][]byte) (*pb.Response, *pb.ChaincodeEvent, error)
499+
ExecuteChaincode(ctxt context.Context, cccid *CCContext, args [][]byte) (*pb.Response, *pb.ChaincodeEvent, error)
502500
// Execute executes the chaincode given context and spec (invocation or deploy)
503-
Execute(ctxt context.Context, cccid interface{}, spec ChaincodeSpecGetter) (*pb.Response, *pb.ChaincodeEvent, error)
501+
Execute(ctxt context.Context, cccid *CCContext, spec ChaincodeSpecGetter) (*pb.Response, *pb.ChaincodeEvent, error)
504502
// Stop stops the chaincode given context and deployment spec
505-
Stop(ctxt context.Context, cccid interface{}, spec *pb.ChaincodeDeploymentSpec) error
503+
Stop(ctxt context.Context, cccid *CCContext, spec *pb.ChaincodeDeploymentSpec) error
506504
}
507505

508506
var ccFactory ChaincodeProviderFactory

core/mocks/ccprovider/ccprovider.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ type MockCcProviderImpl struct {
3737
ExecuteChaincodeResponse *peer.Response
3838
}
3939

40-
type mockCcProviderContextImpl struct {
41-
}
42-
4340
type MockTxSim struct {
4441
GetTxSimulationResultsRv *ledger.TxSimulationResults
4542
}
@@ -140,18 +137,13 @@ func (c *MockCcProviderImpl) GetContext(ledger ledger.PeerLedger, txid string) (
140137
return nil, &MockTxSim{}, nil
141138
}
142139

143-
// GetCCContext does nothing
144-
func (c *MockCcProviderImpl) GetCCContext(cid, name, version, txid string, syscc bool, signedProp *peer.SignedProposal, prop *peer.Proposal) interface{} {
145-
return &mockCcProviderContextImpl{}
146-
}
147-
148140
// GetCCValidationInfoFromLSCC does nothing
149141
func (c *MockCcProviderImpl) GetCCValidationInfoFromLSCC(ctxt context.Context, txid string, signedProp *peer.SignedProposal, prop *peer.Proposal, chainID string, chaincodeID string) (string, []byte, error) {
150142
return "vscc", nil, nil
151143
}
152144

153145
// ExecuteChaincode does nothing
154-
func (c *MockCcProviderImpl) ExecuteChaincode(ctxt context.Context, cccid interface{}, args [][]byte) (*peer.Response, *peer.ChaincodeEvent, error) {
146+
func (c *MockCcProviderImpl) ExecuteChaincode(ctxt context.Context, cccid *ccprovider.CCContext, args [][]byte) (*peer.Response, *peer.ChaincodeEvent, error) {
155147
if c.ExecuteResultProvider != nil {
156148
return c.ExecuteResultProvider.ExecuteChaincodeResult()
157149
}
@@ -163,12 +155,12 @@ func (c *MockCcProviderImpl) ExecuteChaincode(ctxt context.Context, cccid interf
163155
}
164156

165157
// Execute executes the chaincode given context and spec (invocation or deploy)
166-
func (c *MockCcProviderImpl) Execute(ctxt context.Context, cccid interface{}, spec ccprovider.ChaincodeSpecGetter) (*peer.Response, *peer.ChaincodeEvent, error) {
158+
func (c *MockCcProviderImpl) Execute(ctxt context.Context, cccid *ccprovider.CCContext, spec ccprovider.ChaincodeSpecGetter) (*peer.Response, *peer.ChaincodeEvent, error) {
167159
return &peer.Response{}, nil, nil
168160
}
169161

170162
// Stop stops the chaincode given context and deployment spec
171-
func (c *MockCcProviderImpl) Stop(ctxt context.Context, cccid interface{}, spec *peer.ChaincodeDeploymentSpec) error {
163+
func (c *MockCcProviderImpl) Stop(ctxt context.Context, cccid *ccprovider.CCContext, spec *peer.ChaincodeDeploymentSpec) error {
172164
return nil
173165
}
174166

core/scc/sysccapi.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func (syscc *SystemChaincode) deploySysCC(chainID string) error {
131131
// XXX This is an ugly hack, version should be tied to the chaincode instance, not he peer binary
132132
version := util.GetSysCCVersion()
133133

134-
cccid := ccprov.GetCCContext(chainID, chaincodeDeploymentSpec.ChaincodeSpec.ChaincodeId.Name, version, txid, true, nil, nil)
134+
cccid := ccprovider.NewCCContext(chainID, chaincodeDeploymentSpec.ChaincodeSpec.ChaincodeId.Name, version, txid, true, nil, nil)
135135

136136
resp, _, err := ccprov.Execute(ctxt, cccid, chaincodeDeploymentSpec)
137137
if err == nil && resp.Status != shim.OK {
@@ -157,7 +157,7 @@ func (syscc *SystemChaincode) deDeploySysCC(chainID string) error {
157157
// XXX This is an ugly hack, version should be tied to the chaincode instance, not he peer binary
158158
version := util.GetSysCCVersion()
159159

160-
cccid := ccprov.GetCCContext(chainID, syscc.Name, version, "", true, nil, nil)
160+
cccid := ccprovider.NewCCContext(chainID, syscc.Name, version, "", true, nil, nil)
161161

162162
err := ccprov.Stop(ctx, cccid, chaincodeDeploymentSpec)
163163

0 commit comments

Comments
 (0)