diff --git a/protos/common/common.go b/protos/common/common.go index c112a8e1a5f..b59a288f9a1 100644 --- a/protos/common/common.go +++ b/protos/common/common.go @@ -1,17 +1,7 @@ /* -Copyright IBM Corp. 2017 All Rights Reserved. +Copyright IBM Corp. All Rights Reserved. -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. +SPDX-License-Identifier: Apache-2.0 */ package common @@ -37,6 +27,11 @@ func (p *Payload) VariablyOpaqueFields() []string { return []string{"data"} } +var PayloadDataMap = map[int32]proto.Message{ + int32(HeaderType_CONFIG): &ConfigEnvelope{}, + int32(HeaderType_CONFIG_UPDATE): &ConfigUpdateEnvelope{}, +} + func (p *Payload) VariablyOpaqueFieldProto(name string) (proto.Message, error) { if name != p.VariablyOpaqueFields()[0] { return nil, fmt.Errorf("not a marshaled field: %s", name) @@ -49,15 +44,10 @@ func (p *Payload) VariablyOpaqueFieldProto(name string) (proto.Message, error) { return nil, fmt.Errorf("corrupt channel header: %s", err) } - switch ch.Type { - case int32(HeaderType_CONFIG): - return &ConfigEnvelope{}, nil - case int32(HeaderType_CONFIG_UPDATE): - return &ConfigUpdateEnvelope{}, nil - // TODO implement the other well known types, particularly endorser txs - default: - return nil, fmt.Errorf("decoding type %v is unimplemented", ch.Type) + if msg, ok := PayloadDataMap[ch.Type]; ok { + return msg, nil } + return nil, fmt.Errorf("decoding type %v is unimplemented", ch.Type) } func (h *Header) StaticallyOpaqueFields() []string { diff --git a/protos/peer/proposal.go b/protos/peer/proposal.go new file mode 100644 index 00000000000..ab0a6332a1e --- /dev/null +++ b/protos/peer/proposal.go @@ -0,0 +1,24 @@ +/* +Copyright IBM Corp. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package peer + +import ( + "fmt" + + "github.com/golang/protobuf/proto" +) + +func (cpp *ChaincodeProposalPayload) StaticallyOpaqueFields() []string { + return []string{"input"} +} + +func (cpp *ChaincodeProposalPayload) StaticallyOpaqueFieldProto(name string) (proto.Message, error) { + if name != cpp.StaticallyOpaqueFields()[0] { + return nil, fmt.Errorf("not a marshaled field: %s", name) + } + return &ChaincodeInvocationSpec{}, nil +} diff --git a/protos/peer/proposal.proto b/protos/peer/proposal.proto index 657266da82b..73f1d8e2185 100644 --- a/protos/peer/proposal.proto +++ b/protos/peer/proposal.proto @@ -240,6 +240,7 @@ message ChaincodeProposalPayload { // Input contains the arguments for this invocation. If this invocation // deploys a new chaincode, ESCC/VSCC are part of this field. + // This is usually a marshaled ChaincodeInvocationSpec bytes input = 1; // TransientMap contains data (e.g. cryptographic material) that might be used diff --git a/protos/peer/proposal_response.go b/protos/peer/proposal_response.go new file mode 100644 index 00000000000..184b1308500 --- /dev/null +++ b/protos/peer/proposal_response.go @@ -0,0 +1,24 @@ +/* +Copyright IBM Corp. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package peer + +import ( + "fmt" + + "github.com/golang/protobuf/proto" +) + +func (ppr *ProposalResponsePayload) StaticallyOpaqueFields() []string { + return []string{"extension"} +} + +func (ppr *ProposalResponsePayload) StaticallyOpaqueFieldProto(name string) (proto.Message, error) { + if name != ppr.StaticallyOpaqueFields()[0] { + return nil, fmt.Errorf("not a marshaled field: %s", name) + } + return &ChaincodeAction{}, nil +} diff --git a/protos/peer/transaction.go b/protos/peer/transaction.go new file mode 100644 index 00000000000..9aa8ab7bf3e --- /dev/null +++ b/protos/peer/transaction.go @@ -0,0 +1,56 @@ +/* +Copyright IBM Corp. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package peer + +import ( + "fmt" + + "github.com/hyperledger/fabric/protos/common" + + "github.com/golang/protobuf/proto" +) + +func init() { + common.PayloadDataMap[int32(common.HeaderType_ENDORSER_TRANSACTION)] = &Transaction{} +} + +func (ta *TransactionAction) StaticallyOpaqueFields() []string { + return []string{"header", "payload"} +} + +func (ta *TransactionAction) StaticallyOpaqueFieldProto(name string) (proto.Message, error) { + switch name { + case ta.StaticallyOpaqueFields()[0]: + return &common.SignatureHeader{}, nil + case ta.StaticallyOpaqueFields()[1]: + return &ChaincodeActionPayload{}, nil + default: + return nil, fmt.Errorf("not a marshaled field: %s", name) + } +} + +func (cap *ChaincodeActionPayload) StaticallyOpaqueFields() []string { + return []string{"chaincode_proposal_payload"} +} + +func (cap *ChaincodeActionPayload) StaticallyOpaqueFieldProto(name string) (proto.Message, error) { + if name != cap.StaticallyOpaqueFields()[0] { + return nil, fmt.Errorf("not a marshaled field: %s", name) + } + return &ChaincodeProposalPayload{}, nil +} + +func (cae *ChaincodeEndorsedAction) StaticallyOpaqueFields() []string { + return []string{"proposal_response_payload"} +} + +func (cae *ChaincodeEndorsedAction) StaticallyOpaqueFieldProto(name string) (proto.Message, error) { + if name != cae.StaticallyOpaqueFields()[0] { + return nil, fmt.Errorf("not a marshaled field: %s", name) + } + return &ProposalResponsePayload{}, nil +}