accounts/abi: fix boolean decode function

Signed-off-by: RJ Catalano <rj@monax.io>
This commit is contained in:
RJ Catalano 2017-06-13 18:23:55 -05:00
parent 07e2f0f3b1
commit c9920a7c6e
No known key found for this signature in database
GPG key ID: D4AB109D9B5D6386

View file

@ -156,14 +156,13 @@ func readInteger(kind reflect.Kind, b []byte) interface{} {
} }
} }
// todo: this is inefficient for a bool, just look at the last cell, save yourself 32 iterations func getBoolValue(b []byte) (bool, error) {
func allZero(b []byte) bool { for i, byte := range b {
for _, byte := range b { if byte != 0 && i != 31 {
if byte != 0 { return false, fmt.Errorf("abi: Improperly encoded boolean value.")
return false
} }
} }
return true return bool(b[31]), nil
} }
// toGoType parses the input and casts it to the proper type defined by the ABI // toGoType parses the input and casts it to the proper type defined by the ABI
@ -206,7 +205,7 @@ func toGoType(i int, t Argument, output []byte) (interface{}, error) {
case IntTy, UintTy: case IntTy, UintTy:
return readInteger(t.Type.Kind, returnOutput), nil return readInteger(t.Type.Kind, returnOutput), nil
case BoolTy: case BoolTy:
return !allZero(returnOutput), nil return getBoolValue(returnOutput)
case AddressTy: case AddressTy:
return common.BytesToAddress(returnOutput), nil return common.BytesToAddress(returnOutput), nil
case HashTy: case HashTy: