accounts/abi: remove check for len%32==0 when unpacking events (#15670)

This change inlines the logic of bytesAreProper at its sole
callsite, ABI.Unpack, and applies the multiple-of-32 test only in
the case of unpacking methods. Event data is not required to be a
multiple of 32 bytes long.
This commit is contained in:
Bob Glickstein
2017-12-21 01:59:14 -08:00
committed by Felix Lange
parent 9f1007e554
commit e21aa0fda3
3 changed files with 47 additions and 13 deletions

View File

@ -74,13 +74,17 @@ func (abi ABI) Pack(name string, args ...interface{}) ([]byte, error) {
// Unpack output in v according to the abi specification
func (abi ABI) Unpack(v interface{}, name string, output []byte) (err error) {
if err = bytesAreProper(output); err != nil {
return err
if len(output) == 0 {
return fmt.Errorf("abi: unmarshalling empty output")
}
// since there can't be naming collisions with contracts and events,
// we need to decide whether we're calling a method or an event
var unpack unpacker
if method, ok := abi.Methods[name]; ok {
if len(output)%32 != 0 {
return fmt.Errorf("abi: improperly formatted output")
}
unpack = method
} else if event, ok := abi.Events[name]; ok {
unpack = event