@@ -98,17 +98,19 @@ func (t *TransactionInvocationTarget) Bytes() ([]byte, error) {
9898 return nil , err
9999 }
100100
101- var protocolMajorBytes []byte
102101 if t .ByPackageHash .ProtocolVersionMajor != nil {
103- versionBytes = []byte {1 } // Option Some tag
104- bytes , _ := encoding .NewU32ToBytesEncoder (* t .ByPackageHash .ProtocolVersionMajor ).Bytes ()
105- protocolMajorBytes = append (versionBytes , bytes ... )
106- } else {
107- protocolMajorBytes = []byte {0 } // Option none tag
108- }
109-
110- if err = builder .AddField (ByPackageHashProtocolVersionMajorIndex , protocolMajorBytes ); err != nil {
111- return nil , err
102+ var protocolMajorBytes []byte
103+ if t .ByPackageHash .ProtocolVersionMajor != nil {
104+ versionBytes = []byte {1 } // Option Some tag
105+ bytes , _ := encoding .NewU32ToBytesEncoder (* t .ByPackageHash .ProtocolVersionMajor ).Bytes ()
106+ protocolMajorBytes = append (versionBytes , bytes ... )
107+ } else {
108+ protocolMajorBytes = []byte {0 } // Option none tag
109+ }
110+
111+ if err = builder .AddField (ByPackageHashProtocolVersionMajorIndex , protocolMajorBytes ); err != nil {
112+ return nil , err
113+ }
112114 }
113115 case t .ByPackageName != nil :
114116 if err = builder .AddField (TagFieldIndex , []byte {ByPackageNameVariant }); err != nil {
@@ -133,17 +135,19 @@ func (t *TransactionInvocationTarget) Bytes() ([]byte, error) {
133135 return nil , err
134136 }
135137
136- var protocolMajorBytes []byte
137138 if t .ByPackageName .ProtocolVersionMajor != nil {
138- versionBytes = []byte {1 } // Option Some tag
139- bytes , _ := encoding .NewU32ToBytesEncoder (* t .ByPackageName .ProtocolVersionMajor ).Bytes ()
140- protocolMajorBytes = append (versionBytes , bytes ... )
141- } else {
142- protocolMajorBytes = []byte {0 } // Option none tag
143- }
144-
145- if err = builder .AddField (ByPackageNameProtocolVersionMajorIndex , protocolMajorBytes ); err != nil {
146- return nil , err
139+ var protocolMajorBytes []byte
140+ if t .ByPackageName .ProtocolVersionMajor != nil {
141+ versionBytes = []byte {1 } // Option Some tag
142+ bytes , _ := encoding .NewU32ToBytesEncoder (* t .ByPackageName .ProtocolVersionMajor ).Bytes ()
143+ protocolMajorBytes = append (versionBytes , bytes ... )
144+ } else {
145+ protocolMajorBytes = []byte {0 } // Option none tag
146+ }
147+
148+ if err = builder .AddField (ByPackageNameProtocolVersionMajorIndex , protocolMajorBytes ); err != nil {
149+ return nil , err
150+ }
147151 }
148152 default :
149153 return nil , errors .New ("unknown transaction invocation target" )
@@ -175,34 +179,36 @@ func (t *TransactionInvocationTarget) serializedFieldLengths() []int {
175179 versionSerializedLength = encoding .U32SerializedLength
176180 }
177181
178- var protocolMajorSerializedLength int
179- if t .ByPackageHash .ProtocolVersionMajor != nil {
180- protocolMajorSerializedLength = encoding .U32SerializedLength
181- }
182-
183- return []int {
182+ serializedLength := []int {
184183 encoding .U8SerializedLength ,
185184 key .ByteHashLen ,
186185 encoding .U8SerializedLength + versionSerializedLength ,
187- encoding .U8SerializedLength + protocolMajorSerializedLength ,
188186 }
187+
188+ if t .ByPackageHash .ProtocolVersionMajor != nil {
189+ protocolMajorSerializedLength := encoding .U32SerializedLength
190+ serializedLength = append (serializedLength , encoding .U8SerializedLength + protocolMajorSerializedLength )
191+ }
192+
193+ return serializedLength
189194 case t .ByPackageName != nil :
190195 var versionSerializedLength int
191196 if t .ByPackageName .Version != nil {
192197 versionSerializedLength = encoding .U32SerializedLength
193198 }
194199
195- var protocolMajorSerializedLength int
196- if t .ByPackageName .ProtocolVersionMajor != nil {
197- protocolMajorSerializedLength = encoding .U32SerializedLength
198- }
199-
200- return []int {
200+ serializedLength := []int {
201201 encoding .U8SerializedLength ,
202202 encoding .StringSerializedLength (t .ByPackageName .Name ),
203203 encoding .U8SerializedLength + versionSerializedLength ,
204- encoding .U8SerializedLength + protocolMajorSerializedLength ,
205204 }
205+
206+ if t .ByPackageName .ProtocolVersionMajor != nil {
207+ protocolMajorSerializedLength := encoding .U32SerializedLength
208+ serializedLength = append (serializedLength , encoding .U8SerializedLength + protocolMajorSerializedLength )
209+ }
210+
211+ return serializedLength
206212 default :
207213 return []int {}
208214 }
0 commit comments