@@ -260,7 +260,7 @@ func (f FunctionArgType) EncodeInput(object Object) (EncodedItem, error) {
260260 case f .Tuple != nil :
261261 // Tuple is less complicated than arrays since we just iterate through each items
262262 if len (object .Tuple .Elements ) != len (f .Tuple .Elements ) {
263- return EncodedItem {}, fmt .Errorf ("Mismatched length of tuple elements. Expected: %d elements, received %d" , len (f .Tuple .Elements ), len (object .Tuple .Elements ))
263+ return EncodedItem {}, fmt .Errorf ("mismatched length of tuple elements. Expected: %d elements, received %d" , len (f .Tuple .Elements ), len (object .Tuple .Elements ))
264264 }
265265
266266 for idx , tupleItemObject := range object .Tuple .Elements {
@@ -285,49 +285,49 @@ func (f FunctionArgType) EncodeInput(object Object) (EncodedItem, error) {
285285 }
286286 convertedVal , conversionErr = ConvertString (stringVal )
287287 if conversionErr != nil {
288- return EncodedItem {}, fmt .Errorf ("Failed to convert %s to an %s type. %v" , object .Val , f .Type , conversionErr )
288+ return EncodedItem {}, fmt .Errorf ("failed to convert %s to an %s type. %v" , object .Val , f .Type , conversionErr )
289289 }
290290 return EncodedItem {Tail : convertedVal }, nil
291291 case f .Type == "bytes" :
292292 convertedVal , conversionErr = ConvertBytes (object .Val )
293293 if conversionErr != nil {
294- return EncodedItem {}, fmt .Errorf ("Failed to convert %s to an %s type. %v" , object .Val , f .Type , conversionErr )
294+ return EncodedItem {}, fmt .Errorf ("failed to convert %s to an %s type. %v" , object .Val , f .Type , conversionErr )
295295 }
296296 return EncodedItem {Tail : convertedVal }, nil
297297 case strings .HasPrefix (f .Type , "int" ):
298298 // TODO: validate input is within int<size> limit
299299 convertedVal , conversionErr = ConvertInt (object .Val )
300300 if conversionErr != nil {
301- return EncodedItem {}, fmt .Errorf ("Failed to convert %s to an %s type. %v" , object .Val , f .Type , conversionErr )
301+ return EncodedItem {}, fmt .Errorf ("failed to convert %s to an %s type. %v" , object .Val , f .Type , conversionErr )
302302 }
303303 return EncodedItem {Head : convertedVal }, nil
304304 case strings .HasPrefix (f .Type , "uint" ):
305305 // TODO: validate input is within uint<size> limit
306306 convertedVal , conversionErr = ConvertUint (object .Val )
307307 if conversionErr != nil {
308- return EncodedItem {}, fmt .Errorf ("Failed to convert %s to an %s type. %v" , object .Val , f .Type , conversionErr )
308+ return EncodedItem {}, fmt .Errorf ("failed to convert %s to an %s type. %v" , object .Val , f .Type , conversionErr )
309309 }
310310 return EncodedItem {Head : convertedVal }, nil
311311 case strings .Contains (f .Type , "bool" ):
312312 convertedVal , conversionErr = ConvertBool (object .Val )
313313 if conversionErr != nil {
314- return EncodedItem {}, fmt .Errorf ("Failed to convert %s to an %s type. %v" , object .Val , f .Type , conversionErr )
314+ return EncodedItem {}, fmt .Errorf ("failed to convert %s to an %s type. %v" , object .Val , f .Type , conversionErr )
315315 }
316316 return EncodedItem {Head : convertedVal }, nil
317317 case strings .HasPrefix (f .Type , "bytes" ):
318318 convertedVal , conversionErr = ConvertByteSize (object .Val , f .Type )
319319 if conversionErr != nil {
320- return EncodedItem {}, fmt .Errorf ("Failed to convert %s to an %s type. %v" , object .Val , f .Type , conversionErr )
320+ return EncodedItem {}, fmt .Errorf ("failed to convert %s to an %s type. %v" , object .Val , f .Type , conversionErr )
321321 }
322322 return EncodedItem {Head : convertedVal }, nil
323323 case f .Type == "address" :
324324 convertedVal , conversionErr = ConvertAddress (object .Val )
325325 if conversionErr != nil {
326- return EncodedItem {}, fmt .Errorf ("Failed to convert %s to an %s type. %v" , object .Val , f .Type , conversionErr )
326+ return EncodedItem {}, fmt .Errorf ("failed to convert %s to an %s type. %v" , object .Val , f .Type , conversionErr )
327327 }
328328 return EncodedItem {Head : convertedVal }, nil
329329 default :
330- return EncodedItem {}, fmt .Errorf ("Invalid type %s" , f .Type )
330+ return EncodedItem {}, fmt .Errorf ("invalid type %s" , f .Type )
331331 }
332332
333333 // backfill dynamic types...
@@ -433,13 +433,13 @@ func rightPadWithZeros(value string, targetLen int) string {
433433// ConvertInt converts an int input to the 32 byte hex encoding, left padded with 0s
434434func ConvertInt (value string ) (string , error ) {
435435 if len (value ) < 1 {
436- return "" , fmt .Errorf ("Error: expected at least one digit" )
436+ return "" , fmt .Errorf ("expected at least one digit" )
437437 }
438438 bigInt := new (big.Int )
439439
440440 _ , ok := bigInt .SetString (value , 10 )
441441 if ! ok {
442- return "" , fmt .Errorf ("Error: Invalid integer string. Failed to convert %s to big int" , value )
442+ return "" , fmt .Errorf ("invalid integer string, failed to convert %s to big int" , value )
443443 }
444444
445445 var hexString string
@@ -469,17 +469,17 @@ func ConvertInt(value string) (string, error) {
469469// ConvertUint converts a uint input to the 32 byte hex encoding, left padded with 0s
470470func ConvertUint (value string ) (string , error ) {
471471 if len (value ) < 1 {
472- return "" , fmt .Errorf ("Error: expected at least one digit" )
472+ return "" , fmt .Errorf ("expected at least one digit" )
473473 }
474474 if value [0 ] == '-' {
475- return "" , fmt .Errorf ("Error: Invalid integer string. %s can't be negative" , value )
475+ return "" , fmt .Errorf ("invalid integer string, %s can't be negative" , value )
476476 }
477477
478478 bigInt := new (big.Int )
479479
480480 _ , ok := bigInt .SetString (value , 10 )
481481 if ! ok {
482- return "" , fmt .Errorf ("Error: Invalid integer string. Failed to convert %s to big int" , value )
482+ return "" , fmt .Errorf ("invalid integer string, failed to convert %s to big int" , value )
483483 }
484484
485485 // Convert to hexadecimal representation
@@ -529,7 +529,7 @@ func ConvertString(value string) (string, error) {
529529// NOTE: this is similar to ConvertString but `value` is expected to be a hex input already
530530func ConvertBytes (value string ) (string , error ) {
531531 if len (value )% 2 != 0 {
532- return "" , fmt .Errorf ("Odd number of digits" )
532+ return "" , fmt .Errorf ("odd number of digits" )
533533 }
534534
535535 valueSize := len (value ) / 2 // it's hex so / 2 for actual length in bytes
@@ -561,8 +561,8 @@ func ConvertByteSize(value string, byteType string) (string, error) {
561561 return "" , err
562562 }
563563
564- if ! ( byteSize > 0 && byteSize <= 32 ) {
565- return "" , fmt .Errorf ("Invalid size for type %s" , byteType )
564+ if byteSize <= 0 || byteSize > 32 {
565+ return "" , fmt .Errorf ("invalid size for type %s" , byteType )
566566 }
567567
568568 value = strings .TrimPrefix (value , "0x" )
@@ -574,7 +574,7 @@ func ConvertByteSize(value string, byteType string) (string, error) {
574574 }
575575
576576 if len (value ) != byteSize * 2 {
577- return "" , fmt .Errorf ("Invalid string length %s" , value )
577+ return "" , fmt .Errorf ("invalid string length %s" , value )
578578 }
579579
580580 paddedHex := rightPadWithZeros (value , 64 )
@@ -601,7 +601,7 @@ func GetFunctionSignatureObject(functionSig string) (FunctionSignature, error) {
601601
602602 functionSigObject , err := FunctionSignatureParser .ParseString ("" , functionSig )
603603 if err != nil {
604- return FunctionSignature {}, fmt .Errorf ("Failed to parse function sig %s. Error : %v " , functionSig , err )
604+ return FunctionSignature {}, fmt .Errorf ("failed to parse function sig %s: %w " , functionSig , err )
605605 }
606606
607607 return * functionSigObject , nil
@@ -612,7 +612,7 @@ func GetFunctionSignatureObject(functionSig string) (FunctionSignature, error) {
612612// Input: "someFuncName(uint256,(string,string)[][],(uint256,(bool,string)))(uint,string)"
613613// Returns: "someFuncName(uint256,(string,string)[][],(uint256,(bool,string)))"
614614func ExtractFunctionNameAndFunctionArgs (input string ) (string , error ) {
615- input = strings .Replace (input , " " , "" , - 1 ) // remove spaces per solidity doc: https://docs.soliditylang.org/en/latest/abi-spec.html#function-selector
615+ input = strings .ReplaceAll (input , " " , "" ) // remove spaces per solidity doc: https://docs.soliditylang.org/en/latest/abi-spec.html#function-selector
616616
617617 var depth int
618618 var endIndex int
0 commit comments