Skip to content

Commit 7f51840

Browse files
author
Srinivasan Muralidharan
committed
FAB-1357 simpl. cc API param passing using a ctxt obj
https://jira.hyperledger.org/browse/FAB-1357 List of parameters to many of the chaincode APIs is growing . chaincode name . chain ID . version (needed for upgrade) . Proposal . txid Before getting into the meat of upgrade, simplify the APIs using a CCContext structure. In addition to cleaning and simplifying APIs, this will make the upgrade CR easier to follow Change-Id: Ic7ea5f4e082d347cda3072fc2e39077006d866c1 Signed-off-by: Srinivasan Muralidharan <[email protected]>
1 parent ce296d2 commit 7f51840

14 files changed

+334
-180
lines changed

core/chaincode/chaincode_support.go

+87-36
Large diffs are not rendered by default.

core/chaincode/chaincodeexec.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,20 @@ func createCIS(ccname string, args [][]byte) (*pb.ChaincodeInvocationSpec, error
3636

3737
// GetCDSFromLCCC gets chaincode deployment spec from LCCC
3838
func GetCDSFromLCCC(ctxt context.Context, txid string, prop *pb.Proposal, chainID string, chaincodeID string) ([]byte, error) {
39-
payload, _, err := ExecuteChaincode(ctxt, chainID, txid, prop, "lccc", [][]byte{[]byte("getdepspec"), []byte(chainID), []byte(chaincodeID)})
39+
cccid := NewCCContext(chainID, "lccc", "", txid, true, prop)
40+
payload, _, err := ExecuteChaincode(ctxt, cccid, [][]byte{[]byte("getdepspec"), []byte(chainID), []byte(chaincodeID)})
4041
return payload, err
4142
}
4243

4344
// ExecuteChaincode executes a given chaincode given chaincode name and arguments
44-
func ExecuteChaincode(ctxt context.Context, chainID string, txid string, prop *pb.Proposal, ccname string, args [][]byte) ([]byte, *pb.ChaincodeEvent, error) {
45+
func ExecuteChaincode(ctxt context.Context, cccid *CCContext, args [][]byte) ([]byte, *pb.ChaincodeEvent, error) {
4546
var spec *pb.ChaincodeInvocationSpec
4647
var err error
4748
var b []byte
4849
var ccevent *pb.ChaincodeEvent
4950

50-
spec, err = createCIS(ccname, args)
51-
b, ccevent, err = Execute(ctxt, chainID, txid, prop, spec)
51+
spec, err = createCIS(cccid.Name, args)
52+
b, ccevent, err = Execute(ctxt, cccid, spec)
5253
if err != nil {
5354
return nil, nil, fmt.Errorf("Error deploying chaincode: %s", err)
5455
}

core/chaincode/exectransaction.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
)
2929

3030
//Execute - execute proposal
31-
func Execute(ctxt context.Context, chainID string, txid string, prop *pb.Proposal, spec interface{}) ([]byte, *pb.ChaincodeEvent, error) {
31+
func Execute(ctxt context.Context, cccid *CCContext, spec interface{}) ([]byte, *pb.ChaincodeEvent, error) {
3232
var err error
3333
var cds *pb.ChaincodeDeploymentSpec
3434
var ci *pb.ChaincodeInvocationSpec
@@ -39,18 +39,18 @@ func Execute(ctxt context.Context, chainID string, txid string, prop *pb.Proposa
3939
}
4040

4141
if cds != nil {
42-
_, err := theChaincodeSupport.Deploy(ctxt, chainID, cds)
42+
_, err := theChaincodeSupport.Deploy(ctxt, cccid, cds)
4343
if err != nil {
4444
return nil, nil, fmt.Errorf("Failed to deploy chaincode spec(%s)", err)
4545
}
4646

47-
_, _, err = theChaincodeSupport.Launch(ctxt, chainID, txid, prop, cds)
47+
_, _, err = theChaincodeSupport.Launch(ctxt, cccid, cds)
4848
if err != nil {
4949
return nil, nil, fmt.Errorf("%s", err)
5050
}
5151
} else {
5252
//will launch if necessary (and wait for ready)
53-
cID, cMsg, err := theChaincodeSupport.Launch(ctxt, chainID, txid, prop, ci)
53+
cID, cMsg, err := theChaincodeSupport.Launch(ctxt, cccid, ci)
5454
if err != nil {
5555
return nil, nil, fmt.Errorf("Failed to launch chaincode spec(%s)", err)
5656
}
@@ -70,22 +70,22 @@ func Execute(ctxt context.Context, chainID string, txid string, prop *pb.Proposa
7070
}
7171

7272
var ccMsg *pb.ChaincodeMessage
73-
ccMsg, err = createTransactionMessage(txid, cMsg)
73+
ccMsg, err = createTransactionMessage(cccid.TxID, cMsg)
7474
if err != nil {
7575
return nil, nil, fmt.Errorf("Failed to transaction message(%s)", err)
7676
}
7777

78-
resp, err := theChaincodeSupport.Execute(ctxt, chainID, chaincode, ccMsg, timeout, prop)
78+
resp, err := theChaincodeSupport.Execute(ctxt, cccid, ccMsg, timeout)
7979
if err != nil {
8080
// Rollback transaction
8181
return nil, nil, fmt.Errorf("Failed to execute transaction (%s)", err)
8282
} else if resp == nil {
8383
// Rollback transaction
84-
return nil, nil, fmt.Errorf("Failed to receive a response for (%s)", txid)
84+
return nil, nil, fmt.Errorf("Failed to receive a response for (%s)", cccid.TxID)
8585
} else {
8686
if resp.ChaincodeEvent != nil {
87-
resp.ChaincodeEvent.ChaincodeID = chaincode
88-
resp.ChaincodeEvent.TxID = txid
87+
resp.ChaincodeEvent.ChaincodeID = cccid.Name
88+
resp.ChaincodeEvent.TxID = cccid.TxID
8989
}
9090

9191
if resp.Type == pb.ChaincodeMessage_COMPLETED {
@@ -95,7 +95,7 @@ func Execute(ctxt context.Context, chainID string, txid string, prop *pb.Proposa
9595
// Rollback transaction
9696
return nil, resp.ChaincodeEvent, fmt.Errorf("Transaction returned with failure: %s", string(resp.Payload))
9797
}
98-
return resp.Payload, nil, fmt.Errorf("receive a response for (%s) but in invalid state(%d)", txid, resp.Type)
98+
return resp.Payload, nil, fmt.Errorf("receive a response for (%s) but in invalid state(%d)", cccid.TxID, resp.Type)
9999
}
100100

101101
}

0 commit comments

Comments
 (0)