@Test public void testDecodeIndexedStringValue() { Utf8String string = new Utf8String("some text"); String encoded = TypeEncoder.encodeString(string); String hash = Hash.sha3(encoded); assertThat(FunctionReturnDecoder.decodeIndexedValue( hash, new TypeReference<Utf8String>() {}), equalTo(new Bytes32(Numeric.hexStringToByteArray(hash)))); }
@SuppressWarnings("unchecked") public static <T extends Type> Type decodeIndexedValue( String rawInput, TypeReference<T> typeReference) { String input = Numeric.cleanHexPrefix(rawInput); try { Class<T> type = typeReference.getClassType(); if (Bytes.class.isAssignableFrom(type)) { return TypeDecoder.decodeBytes(input, (Class<Bytes>) Class.forName(type.getName())); } else if (Array.class.isAssignableFrom(type) || BytesType.class.isAssignableFrom(type) || Utf8String.class.isAssignableFrom(type)) { return TypeDecoder.decodeBytes(input, Bytes32.class); } else { return TypeDecoder.decode(input, type); } } catch (ClassNotFoundException e) { throw new UnsupportedOperationException("Invalid class reference provided", e); } }
FunctionReturnDecoder { @SuppressWarnings("unchecked") public static <T extends Type> Type decodeIndexedValue( String rawInput, TypeReference<T> typeReference) { String input = Numeric.cleanHexPrefix(rawInput); try { Class<T> type = typeReference.getClassType(); if (Bytes.class.isAssignableFrom(type)) { return TypeDecoder.decodeBytes(input, (Class<Bytes>) Class.forName(type.getName())); } else if (Array.class.isAssignableFrom(type) || BytesType.class.isAssignableFrom(type) || Utf8String.class.isAssignableFrom(type)) { return TypeDecoder.decodeBytes(input, Bytes32.class); } else { return TypeDecoder.decode(input, type); } } catch (ClassNotFoundException e) { throw new UnsupportedOperationException("Invalid class reference provided", e); } } }
FunctionReturnDecoder { @SuppressWarnings("unchecked") public static <T extends Type> Type decodeIndexedValue( String rawInput, TypeReference<T> typeReference) { String input = Numeric.cleanHexPrefix(rawInput); try { Class<T> type = typeReference.getClassType(); if (Bytes.class.isAssignableFrom(type)) { return TypeDecoder.decodeBytes(input, (Class<Bytes>) Class.forName(type.getName())); } else if (Array.class.isAssignableFrom(type) || BytesType.class.isAssignableFrom(type) || Utf8String.class.isAssignableFrom(type)) { return TypeDecoder.decodeBytes(input, Bytes32.class); } else { return TypeDecoder.decode(input, type); } } catch (ClassNotFoundException e) { throw new UnsupportedOperationException("Invalid class reference provided", e); } } private  FunctionReturnDecoder(); }
FunctionReturnDecoder { @SuppressWarnings("unchecked") public static <T extends Type> Type decodeIndexedValue( String rawInput, TypeReference<T> typeReference) { String input = Numeric.cleanHexPrefix(rawInput); try { Class<T> type = typeReference.getClassType(); if (Bytes.class.isAssignableFrom(type)) { return TypeDecoder.decodeBytes(input, (Class<Bytes>) Class.forName(type.getName())); } else if (Array.class.isAssignableFrom(type) || BytesType.class.isAssignableFrom(type) || Utf8String.class.isAssignableFrom(type)) { return TypeDecoder.decodeBytes(input, Bytes32.class); } else { return TypeDecoder.decode(input, type); } } catch (ClassNotFoundException e) { throw new UnsupportedOperationException("Invalid class reference provided", e); } } private  FunctionReturnDecoder(); static List<Type> decode(
            String rawInput, List<TypeReference<Type>> outputParameters); @SuppressWarnings("unchecked") static Type decodeIndexedValue(
            String rawInput, TypeReference<T> typeReference); }
FunctionReturnDecoder { @SuppressWarnings("unchecked") public static <T extends Type> Type decodeIndexedValue( String rawInput, TypeReference<T> typeReference) { String input = Numeric.cleanHexPrefix(rawInput); try { Class<T> type = typeReference.getClassType(); if (Bytes.class.isAssignableFrom(type)) { return TypeDecoder.decodeBytes(input, (Class<Bytes>) Class.forName(type.getName())); } else if (Array.class.isAssignableFrom(type) || BytesType.class.isAssignableFrom(type) || Utf8String.class.isAssignableFrom(type)) { return TypeDecoder.decodeBytes(input, Bytes32.class); } else { return TypeDecoder.decode(input, type); } } catch (ClassNotFoundException e) { throw new UnsupportedOperationException("Invalid class reference provided", e); } } private  FunctionReturnDecoder(); static List<Type> decode(
            String rawInput, List<TypeReference<Type>> outputParameters); @SuppressWarnings("unchecked") static Type decodeIndexedValue(
            String rawInput, TypeReference<T> typeReference);  }