Skip to content

Commit

Permalink
[FAB-2030] Fix protos with uppercase abbreviations
Browse files Browse the repository at this point in the history
https://jira.hyperledger.org/browse/FAB-2030

According to the proto style guide, fields should be lower_underscored
which generally converts nicely to golang as LowerUnderscored.  However,
for certain cases, like chaincode_id, this converts to ChaincodeId
rather than as desired to ChaincodeID.  This change updates the
problematic fields to use the correct proto style, and updates the
golang to expect the appropriate (although odd) output.

Note, per the proto devs, golang/protobuf#53
there is no intent to modify the protoc generation to attempt to produce
upper case ID API, etc.

Still, the odd golang results seem worth following the style guide.

Note, this CR also changes chainID to channel_id as these lines were
already being affected and a community apparently came to a decision
that the world channel is preferable to the word chain.

https://jira.hyperledger.org/browse/FAB-2033

Change-Id: I9c5ebab88fc8d7f45335c904a56676c55a467e5d
Signed-off-by: Jason Yellick <[email protected]>
  • Loading branch information
Jason Yellick committed Feb 11, 2017
1 parent 31b9c40 commit 0045a79
Show file tree
Hide file tree
Showing 97 changed files with 611 additions and 609 deletions.
4 changes: 2 additions & 2 deletions bddtests/chaincode.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
func createChaincodeSpec(ccType string, path string, args [][]byte) *pb.ChaincodeSpec {
// make chaincode spec for chaincode to be deployed
ccSpec := &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value[ccType]),
ChaincodeID: &pb.ChaincodeID{Path: path},
ChaincodeId: &pb.ChaincodeID{Path: path},
Input: &pb.ChaincodeInput{Args: args}}
return ccSpec

Expand All @@ -46,7 +46,7 @@ func createProposalForChaincode(ccChaincodeDeploymentSpec *pb.ChaincodeDeploymen
return nil, fmt.Errorf("Error creating proposal from ChaincodeDeploymentSpec: %s", err)
}
lcChaincodeSpec := &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_GOLANG,
ChaincodeID: &pb.ChaincodeID{Name: "lccc"},
ChaincodeId: &pb.ChaincodeID{Name: "lccc"},
Input: &pb.ChaincodeInput{Args: [][]byte{[]byte("deploy"), []byte("default"), ccDeploymentSpecBytes}}}
lcChaincodeInvocationSpec := &pb.ChaincodeInvocationSpec{ChaincodeSpec: lcChaincodeSpec}

Expand Down
2 changes: 1 addition & 1 deletion common/cauthdsl/cauthdsl_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func SignedByMspMember(mspId string) *cb.SignaturePolicyEnvelope {
// specify the principal: it's a member of the msp we just found
principal := &cb.MSPPrincipal{
PrincipalClassification: cb.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&cb.MSPRole{Role: cb.MSPRole_MEMBER, MSPIdentifier: mspId})}
Principal: utils.MarshalOrPanic(&cb.MSPRole{Role: cb.MSPRole_MEMBER, MspIdentifier: mspId})}

// create the policy: it requires exactly 1 signature from the first (and only) principal
p := &cb.SignaturePolicyEnvelope{
Expand Down
2 changes: 1 addition & 1 deletion common/cauthdsl/policyparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func secondPass(args ...interface{}) (interface{}, error) {
/* build the principal we've been told */
p := &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&common.MSPRole{MSPIdentifier: subm[0][1], Role: r})}
Principal: utils.MarshalOrPanic(&common.MSPRole{MspIdentifier: subm[0][1], Role: r})}
ctx.principals = append(ctx.principals, p)

/* create a SignaturePolicy that requires a signature from
Expand Down
22 changes: 11 additions & 11 deletions common/cauthdsl/policyparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ func TestAnd(t *testing.T) {

principals = append(principals, &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MSPIdentifier: "A"})})
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MspIdentifier: "A"})})

principals = append(principals, &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MSPIdentifier: "B"})})
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MspIdentifier: "B"})})

p2 := &common.SignaturePolicyEnvelope{
Version: 0,
Expand All @@ -56,11 +56,11 @@ func TestOr(t *testing.T) {

principals = append(principals, &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MSPIdentifier: "A"})})
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MspIdentifier: "A"})})

principals = append(principals, &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MSPIdentifier: "B"})})
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MspIdentifier: "B"})})

p2 := &common.SignaturePolicyEnvelope{
Version: 0,
Expand All @@ -79,15 +79,15 @@ func TestComplex1(t *testing.T) {

principals = append(principals, &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MSPIdentifier: "B"})})
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MspIdentifier: "B"})})

principals = append(principals, &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MSPIdentifier: "C"})})
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MspIdentifier: "C"})})

principals = append(principals, &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MSPIdentifier: "A"})})
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MspIdentifier: "A"})})

p2 := &common.SignaturePolicyEnvelope{
Version: 0,
Expand All @@ -106,19 +106,19 @@ func TestComplex2(t *testing.T) {

principals = append(principals, &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MSPIdentifier: "A"})})
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MspIdentifier: "A"})})

principals = append(principals, &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MSPIdentifier: "B"})})
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MspIdentifier: "B"})})

principals = append(principals, &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_ADMIN, MSPIdentifier: "C"})})
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_ADMIN, MspIdentifier: "C"})})

principals = append(principals, &common.MSPPrincipal{
PrincipalClassification: common.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MSPIdentifier: "D"})})
Principal: utils.MarshalOrPanic(&common.MSPRole{Role: common.MSPRole_MEMBER, MspIdentifier: "D"})})

p2 := &common.SignaturePolicyEnvelope{
Version: 0,
Expand Down
12 changes: 6 additions & 6 deletions common/configtx/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ type configManager struct {
callOnUpdate []func(api.Manager)
}

// computeChainIDAndSequence returns the chain id and the sequence number for a config envelope
// computeChannelIdAndSequence returns the chain id and the sequence number for a config envelope
// or an error if there is a problem with the config envelope
func computeChainIDAndSequence(config *cb.Config) (string, uint64, error) {
func computeChannelIdAndSequence(config *cb.Config) (string, uint64, error) {
if len(config.Items) == 0 {
return "", 0, errors.New("Empty envelope unsupported")
}
Expand All @@ -72,11 +72,11 @@ func computeChainIDAndSequence(config *cb.Config) (string, uint64, error) {
return "", 0, fmt.Errorf("Header not set")
}

if config.Header.ChainID == "" {
if config.Header.ChannelId == "" {
return "", 0, fmt.Errorf("Header chainID was not set")
}

chainID := config.Header.ChainID
chainID := config.Header.ChannelId

if err := validateChainID(chainID); err != nil {
return "", 0, err
Expand Down Expand Up @@ -146,7 +146,7 @@ func NewManagerImpl(configtx *cb.ConfigEnvelope, initializer api.Initializer, ca
return nil, err
}

chainID, seq, err := computeChainIDAndSequence(config)
chainID, seq, err := computeChannelIdAndSequence(config)
if err != nil {
return nil, fmt.Errorf("Error computing chain ID and sequence: %s", err)
}
Expand Down Expand Up @@ -206,7 +206,7 @@ func (cm *configManager) processConfig(configtx *cb.ConfigEnvelope) (configMap m
return nil, err
}

chainID, seq, err := computeChainIDAndSequence(config)
chainID, seq, err := computeChannelIdAndSequence(config)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion common/configtx/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func makeConfigItem(id, modificationPolicy string, lastModified uint64, data []b

func makeMarshaledConfig(chainID string, configItems ...*cb.ConfigItem) []byte {
config := &cb.Config{
Header: &cb.ChainHeader{ChainID: chainID},
Header: &cb.ChainHeader{ChannelId: chainID},
Items: configItems,
}
return utils.MarshalOrPanic(config)
Expand Down
8 changes: 4 additions & 4 deletions common/configtx/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ func (st *simpleTemplate) Envelope(chainID string) (*cb.ConfigEnvelope, error) {

marshaledConfig, err := proto.Marshal(&cb.ConfigNext{
Header: &cb.ChainHeader{
ChainID: chainID,
Type: int32(cb.HeaderType_CONFIGURATION_ITEM),
ChannelId: chainID,
Type: int32(cb.HeaderType_CONFIGURATION_ITEM),
},
Channel: channel,
})
Expand Down Expand Up @@ -173,8 +173,8 @@ func (ct *compositeTemplate) Envelope(chainID string) (*cb.ConfigEnvelope, error

marshaledConfig, err := proto.Marshal(&cb.ConfigNext{
Header: &cb.ChainHeader{
ChainID: chainID,
Type: int32(cb.HeaderType_CONFIGURATION_ITEM),
ChannelId: chainID,
Type: int32(cb.HeaderType_CONFIGURATION_ITEM),
},
Channel: channel,
})
Expand Down
4 changes: 2 additions & 2 deletions common/configtx/test/msp.template
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ qp6CP8TFHZ9bw5nRtZxIEDAfBgNVHSMEGDAWgBQXZ0I9qp6CP8TFHZ9bw5nRtZxI
EDAKBggqhkjOPQQDAgNHADBEAiAHp5Rbp9Em1G/UmKn8WsCbqDfWecVbZPQj3RK4
oG5kQQIgQAe4OOKYhJdh3f7URaKfGTf492/nmRmtK+ySKjpHSrU=
-----END CERTIFICATE-----
�-----BEGIN CERTIFICATE-----
"�-----BEGIN CERTIFICATE-----
MIICYjCCAgmgAwIBAgIUB3CTDOU47sUC5K4kn/Caqnh114YwCgYIKoZIzj0EAwIw
fzELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh
biBGcmFuY2lzY28xHzAdBgNVBAoTFkludGVybmV0IFdpZGdldHMsIEluYy4xDDAK
Expand All @@ -30,7 +30,7 @@ qp6CP8TFHZ9bw5nRtZxIEDAfBgNVHSMEGDAWgBQXZ0I9qp6CP8TFHZ9bw5nRtZxI
EDAKBggqhkjOPQQDAgNHADBEAiAHp5Rbp9Em1G/UmKn8WsCbqDfWecVbZPQj3RK4
oG5kQQIgQAe4OOKYhJdh3f7URaKfGTf492/nmRmtK+ySKjpHSrU=
-----END CERTIFICATE-----
*
2
�-----BEGIN CERTIFICATE-----
MIICjDCCAjKgAwIBAgIUBEVwsSx0TmqdbzNwleNBBzoIT0wwCgYIKoZIzj0EAwIw
fzELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,5 @@ func extractTxID(txEnvelopBytes []byte) (string, error) {
if err != nil {
return "", nil
}
return txPayload.Header.ChainHeader.TxID, nil
return txPayload.Header.ChainHeader.TxId, nil
}
4 changes: 2 additions & 2 deletions core/chaincode/chaincode_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,11 @@ func (chaincodeSupport *ChaincodeSupport) Launch(context context.Context, cccid
}
}
if cds != nil {
cID = cds.ChaincodeSpec.ChaincodeID
cID = cds.ChaincodeSpec.ChaincodeId
cMsg = cds.ChaincodeSpec.Input
cLang = cds.ChaincodeSpec.Type
} else {
cID = ci.ChaincodeSpec.ChaincodeID
cID = ci.ChaincodeSpec.ChaincodeId
cMsg = ci.ChaincodeSpec.Input
}

Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/chaincodeexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
//create a chaincode invocation spec
func createCIS(ccname string, args [][]byte) (*pb.ChaincodeInvocationSpec, error) {
var err error
spec := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: 1, ChaincodeID: &pb.ChaincodeID{Name: ccname}, Input: &pb.ChaincodeInput{Args: args}}}
spec := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: 1, ChaincodeId: &pb.ChaincodeID{Name: ccname}, Input: &pb.ChaincodeInput{Args: args}}}
if nil != err {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions core/chaincode/concurrency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestExecuteConcurrentInvokes(t *testing.T) {

args := util.ToChaincodeArgs("init", "")

spec := &pb.ChaincodeSpec{Type: 1, ChaincodeID: chaincodeID, Input: &pb.ChaincodeInput{Args: args}}
spec := &pb.ChaincodeSpec{Type: 1, ChaincodeId: chaincodeID, Input: &pb.ChaincodeInput{Args: args}}

cccid := ccprovider.NewCCContext(chainID, "nkpi", "0", "", false, nil)

Expand Down Expand Up @@ -85,7 +85,7 @@ func TestExecuteConcurrentInvokes(t *testing.T) {
args = util.ToChaincodeArgs("get", newkey)
}

spec = &pb.ChaincodeSpec{Type: 1, ChaincodeID: chaincodeID, Input: &pb.ChaincodeInput{Args: args}}
spec = &pb.ChaincodeSpec{Type: 1, ChaincodeId: chaincodeID, Input: &pb.ChaincodeInput{Args: args}}

//start with a new background
_, _, results[qnum], err = invoke(context.Background(), chainID, spec)
Expand Down
4 changes: 2 additions & 2 deletions core/chaincode/exectransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ func Execute(ctxt context.Context, cccid *ccprovider.CCContext, spec interface{}
}

if resp.ChaincodeEvent != nil {
resp.ChaincodeEvent.ChaincodeID = cccid.Name
resp.ChaincodeEvent.TxID = cccid.TxID
resp.ChaincodeEvent.ChaincodeId = cccid.Name
resp.ChaincodeEvent.TxId = cccid.TxID
}

if resp.Type == pb.ChaincodeMessage_COMPLETED {
Expand Down
Loading

0 comments on commit 0045a79

Please sign in to comment.