mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
accounts/abi: fix boolean decode function
Signed-off-by: RJ Catalano <rj@monax.io>
This commit is contained in:
parent
07e2f0f3b1
commit
c9920a7c6e
1 changed files with 6 additions and 7 deletions
|
|
@ -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 allZero(b []byte) bool {
|
||||
for _, byte := range b {
|
||||
if byte != 0 {
|
||||
return false
|
||||
func getBoolValue(b []byte) (bool, error) {
|
||||
for i, byte := range b {
|
||||
if byte != 0 && i != 31 {
|
||||
return false, fmt.Errorf("abi: Improperly encoded boolean value.")
|
||||
}
|
||||
}
|
||||
return true
|
||||
return bool(b[31]), nil
|
||||
}
|
||||
|
||||
// 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:
|
||||
return readInteger(t.Type.Kind, returnOutput), nil
|
||||
case BoolTy:
|
||||
return !allZero(returnOutput), nil
|
||||
return getBoolValue(returnOutput)
|
||||
case AddressTy:
|
||||
return common.BytesToAddress(returnOutput), nil
|
||||
case HashTy:
|
||||
|
|
|
|||
Loading…
Reference in a new issue