@@ -11,6 +11,8 @@ import (
1111
1212const nullAddress = "0x0000000000000000000000000000000000000000"
1313
14+ // packFeeParameter encodes integrator and resolver fee details into a single 48-bit value with error checks on input ranges.
15+ // Returns the packed 48-bit value and an error if any input values exceed their allowed ranges.
1416func packFeeParameter (integratorFee * IntegratorFee , resolverFee * ResolverFee ) (uint64 , error ) {
1517 var integratorFeeValue uint64 = 0
1618 var integratorShare uint64 = 0
@@ -49,6 +51,8 @@ func packFeeParameter(integratorFee *IntegratorFee, resolverFee *ResolverFee) (u
4951 return packed , nil
5052}
5153
54+ // encodeWhitelist encodes a list of Ethereum addresses into a single *big.Int value with a specific bit layout.
55+ // Returns an error if any address is invalid, has more than 255 addresses, or encounters issues during encoding.
5256func encodeWhitelist (whitelist []string ) (* big.Int , error ) {
5357 if len (whitelist ) == 0 {
5458 return big .NewInt (0 ), nil
@@ -64,7 +68,7 @@ func encodeWhitelist(whitelist []string) (*big.Int, error) {
6468
6569 for _ , address := range whitelist {
6670 address = strings .TrimPrefix (address , "0x" )
67- address = strings .TrimPrefix (address , "0X" )
71+ address = strings .TrimPrefix (address , "0X" ) // Check for capital x too
6872
6973 addressInt := new (big.Int )
7074 _ , success := addressInt .SetString (address , 16 )
@@ -116,6 +120,7 @@ func concatFeeAndWhitelist(whitelist []string, integratorFee *IntegratorFee, res
116120 return feeAndWhitelist , totalBitLength , nil
117121}
118122
123+ // buildFeePostInteractionData encodes interaction data combining receiver, fee, whitelist, and optional interaction inputs into a byte array.
119124func buildFeePostInteractionData (params * buildFeePostInteractionDataParams ) ([]byte , error ) {
120125
121126 if params .Whitelist == nil {
@@ -278,22 +283,16 @@ func BuildOrderExtensionBytes(params *BuildOrderExtensionBytesParams) (string, e
278283
279284// buildExtensionFromBytes builds an extension hex string from byte slices
280285func buildExtensionFromBytes (interactions [][]byte ) string {
281- // Calculate offsets for first 8 interactions only
282286 var byteCounts []int
283287 var dataBytes []byte
284288
285- // Process first 8 interactions (excluding customData)
286- mainInteractions := interactions
287- if len (interactions ) > 8 {
288- mainInteractions = interactions [:8 ]
289- }
290-
291- for _ , interaction := range mainInteractions {
292- byteCounts = append (byteCounts , len (interaction ))
293- dataBytes = append (dataBytes , interaction ... )
289+ // Process first 8 interactions (these are used in the cumulative sum calculation)
290+ for i := 0 ; i < len (interactions ) && i < 8 ; i ++ {
291+ byteCounts = append (byteCounts , len (interactions [i ]))
292+ dataBytes = append (dataBytes , interactions [i ]... )
294293 }
295294
296- // Add customData if present (9th element )
295+ // Add customData if present (no offset data )
297296 if len (interactions ) > 8 {
298297 dataBytes = append (dataBytes , interactions [8 ]... )
299298 }
@@ -308,15 +307,13 @@ func buildExtensionFromBytes(interactions [][]byte) string {
308307 offsets = append (offsetBytes , offsets ... )
309308 }
310309
311- // If no data, return empty extension
310+ // If no data, return an empty extension
312311 if len (dataBytes ) == 0 {
313312 return "0x"
314313 }
315314
316- // Encode offsets and data to hex
317315 offsetsHex := hex .EncodeToString (offsets )
318316 dataHex := hex .EncodeToString (dataBytes )
319317
320- // Concatenate with "0x" prefix
321318 return "0x" + offsetsHex + dataHex
322319}
0 commit comments