func getStringValue(value interface{}, output Argument) (string, error) { typ := output.Type if typ.IsSlice || typ.IsArray { if typ.T == BytesTy || typ.T == FixedBytesTy { return string(bytes.Trim(value.([]byte), "\x00")[:]), nil } var val []string if typ.Elem.T == FixedBytesTy { byteVals := reflect.ValueOf(value) for i := 0; i < byteVals.Len(); i++ { val = append(val, string(bytes.Trim(byteVals.Index(i).Interface().([]byte), "\x00")[:])) } } else { val = strings.Split(fmt.Sprintf("%v", value), " ") } StringVal := strings.Join(val, ",") if typ.Elem.T == FixedBytesTy { StringVal = strings.Join([]string{"[", StringVal, "]"}, "") } return StringVal, nil } else { switch typ.T { case IntTy: switch typ.Size { case 8, 16, 32, 64: return fmt.Sprintf("%v", value), nil default: return common.S256(value.(*big.Int)).String(), nil } case UintTy: switch typ.Size { case 8, 16, 32, 64: return fmt.Sprintf("%v", value), nil default: return common.U256(value.(*big.Int)).String(), nil } case BoolTy: return strconv.FormatBool(value.(bool)), nil case StringTy: return value.(string), nil case AddressTy: return strings.ToUpper(Bytes2Hex(value.(Address).Bytes())), nil default: return "", fmt.Errorf("Could not unpack value %v", value) } } }
// U256 converts a big Int into a 256bit EVM number. func U256(n *big.Int) []byte { return common.LeftPadBytes(common.U256(n).Bytes(), 32) }