Skip to content

Commit

Permalink
Merge "FAB-16286 protolator understand ChaincodeHeaderExt"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Yellick authored and Gerrit Code Review committed Nov 15, 2019
2 parents 33139a9 + 59bad46 commit 019c7ab
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 019c7ab

Please sign in to comment.