Skip to content

Commit

Permalink
[FAB-9725] collection config upgrade -- peer CLI
Browse files Browse the repository at this point in the history
This CR allows a collection config package to be passed
to the peer chaincode upgrade command using --collection-config
flag

Change-Id: I1f6e833b04949b55a38ff00641f8165fae7e2041
Signed-off-by: senthil <cendhu@gmail.com>
  • Loading branch information
cendhu committed May 3, 2018
1 parent 3f782c9 commit 5a04cf5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/committer/txvalidator/txvalidator_test.go
Expand Up @@ -289,7 +289,7 @@ func createCCUpgradeEnvelope(chainID, chaincodeName, chaincodeVersion string, si
}

cds := &peer.ChaincodeDeploymentSpec{ChaincodeSpec: spec, CodePackage: []byte{}}
prop, _, err := utils.CreateUpgradeProposalFromCDS(chainID, cds, creator, []byte{}, []byte{}, []byte{})
prop, _, err := utils.CreateUpgradeProposalFromCDS(chainID, cds, creator, []byte{}, []byte{}, []byte{}, nil)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion peer/chaincode/upgrade.go
Expand Up @@ -45,6 +45,7 @@ func upgradeCmd(cf *ChaincodeCmdFactory) *cobra.Command {
"peerAddresses",
"tlsRootCertFiles",
"connectionProfile",
"collections-config",
}
attachFlags(chaincodeUpgradeCmd, flagList)

Expand All @@ -68,7 +69,7 @@ func upgrade(cmd *cobra.Command, cf *ChaincodeCmdFactory) (*protcommon.Envelope,
return nil, fmt.Errorf("Error serializing identity for %s: %s", cf.Signer.GetIdentifier(), err)
}

prop, _, err := utils.CreateUpgradeProposalFromCDS(channelID, cds, creator, policyMarshalled, []byte(escc), []byte(vscc))
prop, _, err := utils.CreateUpgradeProposalFromCDS(channelID, cds, creator, policyMarshalled, []byte(escc), []byte(vscc), collectionConfigBytes)
if err != nil {
return nil, fmt.Errorf("Error creating proposal %s: %s", chainFuncName, err)
}
Expand Down
15 changes: 13 additions & 2 deletions protos/utils/proputils.go
Expand Up @@ -465,8 +465,19 @@ func CreateDeployProposalFromCDS(
}

// CreateUpgradeProposalFromCDS returns a upgrade proposal given a serialized identity and a ChaincodeDeploymentSpec
func CreateUpgradeProposalFromCDS(chainID string, cds *peer.ChaincodeDeploymentSpec, creator []byte, policy []byte, escc []byte, vscc []byte) (*peer.Proposal, string, error) {
return createProposalFromCDS(chainID, cds, creator, "upgrade", policy, escc, vscc)
func CreateUpgradeProposalFromCDS(
chainID string,
cds *peer.ChaincodeDeploymentSpec,
creator []byte,
policy []byte,
escc []byte,
vscc []byte,
collectionConfig []byte) (*peer.Proposal, string, error) {
if collectionConfig == nil {
return createProposalFromCDS(chainID, cds, creator, "upgrade", policy, escc, vscc)
} else {
return createProposalFromCDS(chainID, cds, creator, "upgrade", policy, escc, vscc, collectionConfig)
}
}

// createProposalFromCDS returns a deploy or upgrade proposal given a serialized identity and a ChaincodeDeploymentSpec
Expand Down
2 changes: 1 addition & 1 deletion protos/utils/proputils_test.go
Expand Up @@ -216,7 +216,7 @@ func TestCDSProposals(t *testing.T) {
assert.NotEqual(t, "", txid, "txid should not be empty")

// upgrade
prop, txid, err = utils.CreateUpgradeProposalFromCDS(chainID, cds, creator, policy, escc, vscc)
prop, txid, err = utils.CreateUpgradeProposalFromCDS(chainID, cds, creator, policy, escc, vscc, nil)
assert.NotNil(t, prop, "Upgrade proposal should not be nil")
assert.NoError(t, err, "Unexpected error creating upgrade proposal")
assert.NotEqual(t, "", txid, "txid should not be empty")
Expand Down

0 comments on commit 5a04cf5

Please sign in to comment.