mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +00:00
Update types.go
This commit is contained in:
parent
7805e203f0
commit
de38537efc
1 changed files with 17 additions and 2 deletions
|
|
@ -826,10 +826,10 @@ func formatPrimitiveValue(encType string, encValue interface{}) (string, error)
|
|||
return fmt.Sprintf("%t", boolValue), nil
|
||||
}
|
||||
case "bytes", "string":
|
||||
return fmt.Sprintf("%s", encValue), nil
|
||||
return stringifyPrimitive(encType, encValue)
|
||||
}
|
||||
if strings.HasPrefix(encType, "bytes") {
|
||||
return fmt.Sprintf("%s", encValue), nil
|
||||
return stringifyPrimitive(encType, encValue)
|
||||
}
|
||||
if strings.HasPrefix(encType, "uint") || strings.HasPrefix(encType, "int") {
|
||||
if b, err := parseInteger(encType, encValue); err != nil {
|
||||
|
|
@ -841,6 +841,21 @@ func formatPrimitiveValue(encType string, encValue interface{}) (string, error)
|
|||
return "", fmt.Errorf("unhandled type %v", encType)
|
||||
}
|
||||
|
||||
func stringifyPrimitive(encType string, encValue interface{}) (string, error) {
|
||||
switch v := encValue.(type) {
|
||||
case string:
|
||||
return v, nil
|
||||
case []byte:
|
||||
return string(v), nil
|
||||
case hexutil.Bytes:
|
||||
return v.String(), nil
|
||||
case fmt.Stringer:
|
||||
return v.String(), nil
|
||||
default:
|
||||
return "", fmt.Errorf("could not format value %v as %s", encValue, encType)
|
||||
}
|
||||
}
|
||||
|
||||
// validate checks if the types object is conformant to the specs
|
||||
func (t Types) validate() error {
|
||||
for typeKey, typeArr := range t {
|
||||
|
|
|
|||
Loading…
Reference in a new issue