diff --git a/accounts/abi/error.go b/accounts/abi/error.go index 67739c21dc..afcd3dfed7 100644 --- a/accounts/abi/error.go +++ b/accounts/abi/error.go @@ -21,6 +21,10 @@ import ( "reflect" ) +var ( + errBadBool error = "abi: improperly encoded boolean value" +) + // formatSliceString formats the reflection kind with the given slice size // and returns a formatted string representation. func formatSliceString(kind reflect.Kind, sliceSize int) string { diff --git a/accounts/abi/unpack.go b/accounts/abi/unpack.go index 2bb5c98606..fc41c88ac7 100644 --- a/accounts/abi/unpack.go +++ b/accounts/abi/unpack.go @@ -164,10 +164,10 @@ func readBool(word []byte) (bool, error) { if len(word) != 32 { return false, fmt.Errorf("abi: fatal error: incorrect word length") } - improperEncoding := "abi: improperly encoded boolean value" + for i, b := range word { if b != 0 && i != 31 { - return false, fmt.Errorf(improperEncoding) + return false, errBadBool } } switch word[31] { @@ -176,7 +176,7 @@ func readBool(word []byte) (bool, error) { case 1: return true, nil default: - return false, fmt.Errorf(improperEncoding) + return false, errBadBool } }