Skip to content

Commit 187bce9

Browse files
committed
[FAB-830] - enable transient field in CLI
This code change lets users of the golang CLI set the transient field in the transaction proposal message. While this change set is of idependent interest (because it is useful to quickly set the transient field for debug purposes using the CLI), it is deeply related to testing and debugging chaincode-level encryption: the transient field is indeed one of the recommended ways to pass cryptographic key material to chaincodes for the purpose of encrypting/decrypting state, arguments or results. Change-Id: I1f4f0dd9bf500cecabe525c00e867874577c762d Signed-off-by: Alessandro Sorniotti <ale.linux@sopit.net>
1 parent 07f1c8e commit 187bce9

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

peer/chaincode/chaincode.go

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func addFlags(cmd *cobra.Command) {
4040
flags.StringVarP(&orderingEndpoint, "orderer", "o", "", "Ordering service endpoint")
4141
flags.BoolVarP(&tls, "tls", "", false, "Use TLS when communicating with the orderer endpoint")
4242
flags.StringVarP(&caFile, "cafile", "", "", "Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint")
43+
flags.StringVarP(&transient, "transient", "", "", "Transient map of arguments in JSON encoding")
4344
}
4445

4546
// Cmd returns the cobra command for Chaincode
@@ -76,6 +77,7 @@ var (
7677
orderingEndpoint string
7778
tls bool
7879
caFile string
80+
transient string
7981
)
8082

8183
var chaincodeCmd = &cobra.Command{

peer/chaincode/common.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,16 @@ func ChaincodeInvokeOrQuery(
308308
funcName = "query"
309309
}
310310

311+
// extract the transient field if it exists
312+
var tMap map[string][]byte
313+
if transient != "" {
314+
if err := json.Unmarshal([]byte(transient), &tMap); err != nil {
315+
return nil, fmt.Errorf("Error parsing transient string: %s", err)
316+
}
317+
}
318+
311319
var prop *pb.Proposal
312-
prop, _, err = putils.CreateProposalFromCIS(pcommon.HeaderType_ENDORSER_TRANSACTION, cID, invocation, creator)
320+
prop, _, err = putils.CreateChaincodeProposalWithTransient(pcommon.HeaderType_ENDORSER_TRANSACTION, cID, invocation, creator, tMap)
313321
if err != nil {
314322
return nil, fmt.Errorf("Error creating proposal %s: %s", funcName, err)
315323
}

0 commit comments

Comments
 (0)