@@ -826,10 +826,10 @@ func formatPrimitiveValue(encType string, encValue interface{}) (string, error)
826826 return fmt .Sprintf ("%t" , boolValue ), nil
827827 }
828828 case "bytes" , "string" :
829- return fmt . Sprintf ( "%s" , encValue ), nil
829+ return stringifyPrimitive ( encType , encValue )
830830 }
831831 if strings .HasPrefix (encType , "bytes" ) {
832- return fmt . Sprintf ( "%s" , encValue ), nil
832+ return stringifyPrimitive ( encType , encValue )
833833 }
834834 if strings .HasPrefix (encType , "uint" ) || strings .HasPrefix (encType , "int" ) {
835835 if b , err := parseInteger (encType , encValue ); err != nil {
@@ -841,6 +841,21 @@ func formatPrimitiveValue(encType string, encValue interface{}) (string, error)
841841 return "" , fmt .Errorf ("unhandled type %v" , encType )
842842}
843843
844+ func stringifyPrimitive (encType string , encValue interface {}) (string , error ) {
845+ switch v := encValue .(type ) {
846+ case string :
847+ return v , nil
848+ case []byte :
849+ return string (v ), nil
850+ case hexutil.Bytes :
851+ return v .String (), nil
852+ case fmt.Stringer :
853+ return v .String (), nil
854+ default :
855+ return "" , fmt .Errorf ("could not format value %v as %s" , encValue , encType )
856+ }
857+ }
858+
844859// validate checks if the types object is conformant to the specs
845860func (t Types ) validate () error {
846861 for typeKey , typeArr := range t {
0 commit comments