accounts/abi: simplify Arguments.Unpack (#24277)

Since len(nonIndexedArgs) is definitely 0 in this context, the code can be simplified.
This commit is contained in:
zhiqiangxu 2022-01-25 00:19:43 +08:00 committed by GitHub
parent f9ce40bb84
commit f39f068161
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -81,13 +81,7 @@ func (arguments Arguments) Unpack(data []byte) ([]interface{}, error) {
if len(arguments) != 0 { if len(arguments) != 0 {
return nil, fmt.Errorf("abi: attempting to unmarshall an empty string while arguments are expected") return nil, fmt.Errorf("abi: attempting to unmarshall an empty string while arguments are expected")
} }
// Nothing to unmarshal, return default variables return make([]interface{}, 0), nil
nonIndexedArgs := arguments.NonIndexed()
defaultVars := make([]interface{}, len(nonIndexedArgs))
for index, arg := range nonIndexedArgs {
defaultVars[index] = reflect.New(arg.Type.GetType())
}
return defaultVars, nil
} }
return arguments.UnpackValues(data) return arguments.UnpackValues(data)
} }