@@ -18,6 +18,7 @@ package abi
18
18
19
19
import (
20
20
"encoding/binary"
21
+ "encoding/hex"
21
22
"errors"
22
23
"fmt"
23
24
"math"
@@ -400,7 +401,12 @@ func toString(index int, t Type, output []byte) (interface{}, error) {
400
401
case StringTy : // variable arrays are written at the end of the return bytes
401
402
return string (output [begin : begin + length ]), nil
402
403
case IntTy , UintTy :
403
- return ReadInteger (t , returnOutput )
404
+ var n interface {}
405
+ n , err = ReadInteger (t , returnOutput )
406
+ if err != nil {
407
+ return nil , fmt .Errorf ("abi: cannot convert value as integer: %v" , returnOutput )
408
+ }
409
+ return fmt .Sprintf ("%d" , n ), nil
404
410
case BoolTy :
405
411
var b bool
406
412
b , err = readBool (returnOutput )
@@ -409,25 +415,25 @@ func toString(index int, t Type, output []byte) (interface{}, error) {
409
415
}
410
416
return strconv .FormatBool (b ), nil
411
417
case AddressTy :
412
- return string (common .BytesToAddress (returnOutput ).Bytes ()), nil
418
+ return hex . EncodeToString (common .BytesToAddress (returnOutput ).Bytes ()), nil
413
419
case HashTy :
414
- return string (common .BytesToHash (returnOutput ).Bytes ()), nil
420
+ return hex . EncodeToString (common .BytesToHash (returnOutput ).Bytes ()), nil
415
421
case BytesTy :
416
- return string (output [begin : begin + length ]), nil
422
+ return hex . EncodeToString (output [begin : begin + length ]), nil
417
423
case FixedBytesTy :
418
424
var b interface {}
419
425
b , err = ReadFixedBytes (t , returnOutput )
420
426
if err != nil {
421
427
return nil , fmt .Errorf ("abi: cannot convert value as fixed bytes array: %v" , returnOutput )
422
428
}
423
- return string (b .([]byte )), nil
429
+ return hex . EncodeToString (b .([]byte )), nil
424
430
case FunctionTy :
425
431
var f interface {}
426
432
f , err = ReadFixedBytes (t , returnOutput )
427
433
if err != nil {
428
434
return nil , fmt .Errorf ("abi: cannot convert value as function: %v" , returnOutput )
429
435
}
430
- return string (f .([]byte )), nil
436
+ return hex . EncodeToString (f .([]byte )), nil
431
437
default :
432
438
return nil , fmt .Errorf ("abi: unknown type %v" , t .T )
433
439
}
0 commit comments