Skip to content

Commit

Permalink
FAB-16286 protolator understand ChaincodeHeaderExt
Browse files Browse the repository at this point in the history
The extension field of the ChannelHeader is treated as opaque, even when
the message type is known.  This properly decodes those bytes as a
chaincode header extension when the type is an endorser tx.

Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
Change-Id: I5b93f1146ac5e17692ac31435e5083cec3b2abdf
  • Loading branch information
Jason Yellick committed Nov 15, 2019
1 parent 048351a commit 59bad46
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 23 additions & 2 deletions common/tools/protolator/protoext/commonext/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ func (p *Payload) VariablyOpaqueFields() []string {
return []string{"data"}
}

var PayloadDataMap = map[int32]proto.Message{}

func (p *Payload) VariablyOpaqueFieldProto(name string) (proto.Message, error) {
if name != p.VariablyOpaqueFields()[0] {
return nil, fmt.Errorf("not a marshaled field: %s", name)
Expand Down Expand Up @@ -73,6 +71,29 @@ func (p *Payload) VariablyOpaqueFieldProto(name string) (proto.Message, error) {
}
}

type ChannelHeader struct{ *common.ChannelHeader }

func (ch *ChannelHeader) Underlying() proto.Message {
return ch.ChannelHeader
}

func (ch *ChannelHeader) VariablyOpaqueFields() []string {
return []string{"extension"}
}

func (ch *ChannelHeader) VariablyOpaqueFieldProto(name string) (proto.Message, error) {
if name != "extension" {
return nil, fmt.Errorf("not an opaque field")
}

switch ch.Type {
case int32(common.HeaderType_ENDORSER_TRANSACTION):
return &peer.ChaincodeHeaderExtension{}, nil
default:
return nil, fmt.Errorf("channel header extension only valid for endorser transactions")
}
}

type Header struct{ *common.Header }

func (h *Header) Underlying() proto.Message {
Expand Down
2 changes: 2 additions & 0 deletions common/tools/protolator/protoext/decorate.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func Decorate(msg proto.Message) proto.Message {
return &commonext.Envelope{Envelope: m}
case *common.Header:
return &commonext.Header{Header: m}
case *common.ChannelHeader:
return &commonext.ChannelHeader{ChannelHeader: m}
case *common.SignatureHeader:
return &commonext.SignatureHeader{SignatureHeader: m}
case *common.Payload:
Expand Down

0 comments on commit 59bad46

Please sign in to comment.