org.web3j.abi.datatypes.DynamicArray Java Examples

The following examples show how to use org.web3j.abi.datatypes.DynamicArray. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UtilsTest.java    From web3j with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetTypeName() {
    assertEquals(Utils.getTypeName(new TypeReference<Uint>() {}), ("uint256"));
    assertEquals(Utils.getTypeName(new TypeReference<Int>() {}), ("int256"));
    assertEquals(Utils.getTypeName(new TypeReference<Ufixed>() {}), ("ufixed256"));
    assertEquals(Utils.getTypeName(new TypeReference<Fixed>() {}), ("fixed256"));

    assertEquals(Utils.getTypeName(new TypeReference<Uint64>() {}), ("uint64"));
    assertEquals(Utils.getTypeName(new TypeReference<Int64>() {}), ("int64"));
    assertEquals(Utils.getTypeName(new TypeReference<Bool>() {}), ("bool"));
    assertEquals(Utils.getTypeName(new TypeReference<Utf8String>() {}), ("string"));
    assertEquals(Utils.getTypeName(new TypeReference<DynamicBytes>() {}), ("bytes"));

    assertEquals(
            Utils.getTypeName(
                    new TypeReference.StaticArrayTypeReference<StaticArray<Uint>>(5) {}),
            ("uint256[5]"));
    assertEquals(Utils.getTypeName(new TypeReference<DynamicArray<Uint>>() {}), ("uint256[]"));
}
 
Example #2
Source File: TypeEncoderTest.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testDynamicArray() {
    DynamicArray<Uint> array = new DynamicArray<>(
            new Uint(BigInteger.ONE),
            new Uint(BigInteger.valueOf(2)),
            new Uint(BigInteger.valueOf(3))
    );

    assertThat(
            TypeEncoder.encodeDynamicArray(array),
            is("0000000000000000000000000000000000000000000000000000000000000003"
                    + "0000000000000000000000000000000000000000000000000000000000000001"
                    + "0000000000000000000000000000000000000000000000000000000000000002"
                    + "0000000000000000000000000000000000000000000000000000000000000003"
            ));
}
 
Example #3
Source File: OnChainPrivacyGroupManagementProxy.java    From besu with Apache License 2.0 6 votes vote down vote up
public RemoteFunctionCall<List> getParticipants(byte[] enclaveKey) {
  final Function function =
      new Function(
          FUNC_GETPARTICIPANTS,
          Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Bytes32(enclaveKey)),
          Arrays.<TypeReference<?>>asList(new TypeReference<DynamicArray<Bytes32>>() {}));
  return new RemoteFunctionCall<List>(
      function,
      new Callable<List>() {
        @Override
        @SuppressWarnings("unchecked")
        public List call() throws Exception {
          List<Type> result = (List<Type>) executeCallSingleValueReturn(function, List.class);
          return convertToNative(result);
        }
      });
}
 
Example #4
Source File: OnChainPrivacyGroupManagementInterface.java    From besu with Apache License 2.0 6 votes vote down vote up
public RemoteFunctionCall<List> getParticipants(byte[] enclaveKey) {
  final Function function =
      new Function(
          FUNC_GETPARTICIPANTS,
          Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Bytes32(enclaveKey)),
          Arrays.<TypeReference<?>>asList(new TypeReference<DynamicArray<Bytes32>>() {}));
  return new RemoteFunctionCall<List>(
      function,
      new Callable<List>() {
        @Override
        @SuppressWarnings("unchecked")
        public List call() throws Exception {
          List<Type> result = (List<Type>) executeCallSingleValueReturn(function, List.class);
          return convertToNative(result);
        }
      });
}
 
Example #5
Source File: TypeEncoder.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static String encode(Type parameter) {
    if (parameter instanceof NumericType) {
        return encodeNumeric(((NumericType) parameter));
    } else if (parameter instanceof Address) {
        return encodeAddress((Address) parameter);
    } else if (parameter instanceof Bool) {
        return encodeBool((Bool) parameter);
    } else if (parameter instanceof Bytes) {
        return encodeBytes((Bytes) parameter);
    } else if (parameter instanceof DynamicBytes) {
        return encodeDynamicBytes((DynamicBytes) parameter);
    } else if (parameter instanceof Utf8String) {
        return encodeString((Utf8String) parameter);
    } else if (parameter instanceof StaticArray) {
        return encodeArrayValues((StaticArray) parameter);
    } else if (parameter instanceof DynamicArray) {
        return encodeDynamicArray((DynamicArray) parameter);
    } else {
        throw new UnsupportedOperationException(
                "Type cannot be encoded: " + parameter.getClass());
    }
}
 
Example #6
Source File: TypeDecoder.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
static <T extends Type> T decodeDynamicArray(
        String input, int offset, TypeReference<T> typeReference) {

    int length = decodeUintAsInt(input, offset);

    BiFunction<List<T>, String, T> function = (elements, typeName) -> {
        if (elements.isEmpty()) {
            return (T) DynamicArray.empty(typeName);
        } else {
            return (T) new DynamicArray<>(elements);
        }
    };

    int valueOffset = offset + MAX_BYTE_LENGTH_FOR_HEX_STRING;

    return decodeArrayElements(input, valueOffset, typeReference, length, function);
}
 
Example #7
Source File: UtilsTest.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetTypeName() throws ClassNotFoundException {
    assertThat(Utils.getTypeName(new TypeReference<Uint>(){}), is("uint256"));
    assertThat(Utils.getTypeName(new TypeReference<Int>(){}), is("int256"));
    assertThat(Utils.getTypeName(new TypeReference<Ufixed>(){}), is("ufixed256"));
    assertThat(Utils.getTypeName(new TypeReference<Fixed>(){}), is("fixed256"));

    assertThat(Utils.getTypeName(new TypeReference<Uint64>(){}), is("uint64"));
    assertThat(Utils.getTypeName(new TypeReference<Int64>(){}), is("int64"));
    assertThat(Utils.getTypeName(new TypeReference<Bool>(){}), is("bool"));
    assertThat(Utils.getTypeName(new TypeReference<Utf8String>(){}), is("string"));
    assertThat(Utils.getTypeName(new TypeReference<DynamicBytes>(){}), is("bytes"));

    assertThat(Utils.getTypeName(
            new TypeReference.StaticArrayTypeReference<StaticArray<Uint>>(5){}),
            is("uint256[5]"));
    assertThat(Utils.getTypeName(
            new TypeReference<DynamicArray<Uint>>(){}),
            is("uint256[]"));
}
 
Example #8
Source File: FunctionEncoderTest.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testFunctionMDynamicArrayEncode1() {
    Function function = new Function(
            "sam",
            Arrays.asList(
                new DynamicBytes("dave".getBytes()),
                new Bool(true),
                new DynamicArray<>(
                        new Uint(BigInteger.ONE),
                        new Uint(BigInteger.valueOf(2)),
                        new Uint(BigInteger.valueOf(3)))),
            Collections.<TypeReference<?>>emptyList()
    );

    assertThat(FunctionEncoder.encode(function),
            is("0xa5643bf2"
                    + "0000000000000000000000000000000000000000000000000000000000000060"
                    + "0000000000000000000000000000000000000000000000000000000000000001"
                    + "00000000000000000000000000000000000000000000000000000000000000a0"
                    + "0000000000000000000000000000000000000000000000000000000000000004"
                    + "6461766500000000000000000000000000000000000000000000000000000000"
                    + "0000000000000000000000000000000000000000000000000000000000000003"
                    + "0000000000000000000000000000000000000000000000000000000000000001"
                    + "0000000000000000000000000000000000000000000000000000000000000002"
                    + "0000000000000000000000000000000000000000000000000000000000000003"));
}
 
Example #9
Source File: TypeDecoder.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
static <T extends Type> T decodeDynamicArray(
        String input, int offset, TypeReference<T> typeReference) {

    int length = decodeUintAsInt(input, offset);

    BiFunction<List<T>, String, T> function = (elements, typeName) -> {
        if (elements.isEmpty()) {
            return (T) DynamicArray.empty(typeName);
        } else {
            return (T) new DynamicArray<>(elements);
        }
    };

    int valueOffset = offset + MAX_BYTE_LENGTH_FOR_HEX_STRING;

    return decodeArrayElements(input, valueOffset, typeReference, length, function);
}
 
Example #10
Source File: TypeEncoder.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static String encode(Type parameter) {
    if (parameter instanceof NumericType) {
        return encodeNumeric(((NumericType) parameter));
    } else if (parameter instanceof Address) {
        return encodeAddress((Address) parameter);
    } else if (parameter instanceof Bool) {
        return encodeBool((Bool) parameter);
    } else if (parameter instanceof Bytes) {
        return encodeBytes((Bytes) parameter);
    } else if (parameter instanceof DynamicBytes) {
        return encodeDynamicBytes((DynamicBytes) parameter);
    } else if (parameter instanceof Utf8String) {
        return encodeString((Utf8String) parameter);
    } else if (parameter instanceof StaticArray) {
        return encodeArrayValues((StaticArray) parameter);
    } else if (parameter instanceof DynamicArray) {
        return encodeDynamicArray((DynamicArray) parameter);
    } else {
        throw new UnsupportedOperationException(
                "Type cannot be encoded: " + parameter.getClass());
    }
}
 
Example #11
Source File: TypeEncoderTest.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testDynamicArray() {
    DynamicArray<Uint> array = new DynamicArray<>(
            new Uint(BigInteger.ONE),
            new Uint(BigInteger.valueOf(2)),
            new Uint(BigInteger.valueOf(3))
    );

    assertThat(
            TypeEncoder.encodeDynamicArray(array),
            is("0000000000000000000000000000000000000000000000000000000000000003"
                    + "0000000000000000000000000000000000000000000000000000000000000001"
                    + "0000000000000000000000000000000000000000000000000000000000000002"
                    + "0000000000000000000000000000000000000000000000000000000000000003"
            ));
}
 
Example #12
Source File: FunctionEncoderTest.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testFunctionMDynamicArrayEncode1() {
    Function function = new Function(
            "sam",
            Arrays.asList(
                new DynamicBytes("dave".getBytes()),
                new Bool(true),
                new DynamicArray<>(
                        new Uint(BigInteger.ONE),
                        new Uint(BigInteger.valueOf(2)),
                        new Uint(BigInteger.valueOf(3)))),
            Collections.<TypeReference<?>>emptyList()
    );

    assertThat(FunctionEncoder.encode(function),
            is("0xa5643bf2"
                    + "0000000000000000000000000000000000000000000000000000000000000060"
                    + "0000000000000000000000000000000000000000000000000000000000000001"
                    + "00000000000000000000000000000000000000000000000000000000000000a0"
                    + "0000000000000000000000000000000000000000000000000000000000000004"
                    + "6461766500000000000000000000000000000000000000000000000000000000"
                    + "0000000000000000000000000000000000000000000000000000000000000003"
                    + "0000000000000000000000000000000000000000000000000000000000000001"
                    + "0000000000000000000000000000000000000000000000000000000000000002"
                    + "0000000000000000000000000000000000000000000000000000000000000003"));
}
 
Example #13
Source File: Web3jEventParameterConverter.java    From eventeum with Apache License 2.0 6 votes vote down vote up
@Override
public EventParameter convert(Type toConvert) {
    final EventParameterConverter<Type> typeConverter = typeConverters.get(toConvert.getTypeAsString().toLowerCase());

    if (typeConverter == null) {
        //Type might be an array, in which case the type will be the array type class
        if (toConvert instanceof DynamicArray){
            final DynamicArray<?> theArray = (DynamicArray<?>) toConvert;
            return convertDynamicArray(theArray);
        }

        throw new TypeConversionException("Unsupported type: " + toConvert.getTypeAsString());
    }

    return typeConverter.convert(toConvert);
}
 
Example #14
Source File: Ticket.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
@Override
protected org.web3j.abi.datatypes.DynamicArray getDynArray(List<BigInteger> indices)
{
    DynamicArray dynArray;

    switch (contractType)
    {
        case ERC875_LEGACY:
            dynArray = new org.web3j.abi.datatypes.DynamicArray<>(
                    org.web3j.abi.datatypes.generated.Uint16.class,
                    org.web3j.abi.Utils.typeMap(indices, org.web3j.abi.datatypes.generated.Uint16.class));
            break;
        case ERC875:
        default:
            dynArray = new org.web3j.abi.datatypes.DynamicArray<>(
                    org.web3j.abi.datatypes.generated.Uint256.class,
                    org.web3j.abi.Utils.typeMap(indices, org.web3j.abi.datatypes.generated.Uint256.class));
            break;
    }

    return dynArray;
}
 
Example #15
Source File: Arrays.java    From web3j with Apache License 2.0 6 votes vote down vote up
public RemoteFunctionCall<List> multiDynamic(List<List<BigInteger>> input) {
    final Function function = new Function(FUNC_MULTIDYNAMIC, 
            java.util.Arrays.<Type>asList(new org.web3j.abi.datatypes.DynamicArray<org.web3j.abi.datatypes.generated.StaticArray2>(
                    org.web3j.abi.datatypes.generated.StaticArray2.class,
                    org.web3j.abi.Utils.typeMap(input, org.web3j.abi.datatypes.generated.StaticArray2.class,
            org.web3j.abi.datatypes.generated.Uint256.class))), 
            java.util.Arrays.<TypeReference<?>>asList(new TypeReference<DynamicArray<Uint256>>() {}));
    return new RemoteFunctionCall<List>(function,
            new Callable<List>() {
                @Override
                @SuppressWarnings("unchecked")
                public List call() throws Exception {
                    List<Type> result = (List<Type>) executeCallSingleValueReturn(function, List.class);
                    return convertToNative(result);
                }
            });
}
 
Example #16
Source File: UtilsTest.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testGetTypeName() throws ClassNotFoundException {
    assertThat(Utils.getTypeName(new TypeReference<Uint>(){}), is("uint256"));
    assertThat(Utils.getTypeName(new TypeReference<Int>(){}), is("int256"));
    assertThat(Utils.getTypeName(new TypeReference<Ufixed>(){}), is("ufixed256"));
    assertThat(Utils.getTypeName(new TypeReference<Fixed>(){}), is("fixed256"));

    assertThat(Utils.getTypeName(new TypeReference<Uint64>(){}), is("uint64"));
    assertThat(Utils.getTypeName(new TypeReference<Int64>(){}), is("int64"));
    assertThat(Utils.getTypeName(new TypeReference<Bool>(){}), is("bool"));
    assertThat(Utils.getTypeName(new TypeReference<Utf8String>(){}), is("string"));
    assertThat(Utils.getTypeName(new TypeReference<DynamicBytes>(){}), is("bytes"));

    assertThat(Utils.getTypeName(
            new TypeReference.StaticArrayTypeReference<StaticArray<Uint>>(5){}),
            is("uint256[5]"));
    assertThat(Utils.getTypeName(
            new TypeReference<DynamicArray<Uint>>(){}),
            is("uint256[]"));
}
 
Example #17
Source File: DefaultOnChainPrivacyGroupManagementContract.java    From besu with Apache License 2.0 6 votes vote down vote up
public RemoteFunctionCall<List> getParticipants(byte[] _enclaveKey) {
  final org.web3j.abi.datatypes.Function function =
      new org.web3j.abi.datatypes.Function(
          FUNC_GETPARTICIPANTS,
          Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Bytes32(_enclaveKey)),
          Arrays.<TypeReference<?>>asList(new TypeReference<DynamicArray<Bytes32>>() {}));
  return new RemoteFunctionCall<List>(
      function,
      new Callable<List>() {
        @Override
        @SuppressWarnings("unchecked")
        public List call() throws Exception {
          List<Type> result = (List<Type>) executeCallSingleValueReturn(function, List.class);
          return convertToNative(result);
        }
      });
}
 
Example #18
Source File: Arrays.java    From web3j with Apache License 2.0 6 votes vote down vote up
public RemoteFunctionCall<List> multiFixed(List<List<BigInteger>> input) {
    final Function function = new Function(FUNC_MULTIFIXED, 
            java.util.Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.StaticArray6<org.web3j.abi.datatypes.generated.StaticArray2>(
                    org.web3j.abi.datatypes.generated.StaticArray2.class,
                    org.web3j.abi.Utils.typeMap(input, org.web3j.abi.datatypes.generated.StaticArray2.class,
            org.web3j.abi.datatypes.generated.Uint256.class))), 
            java.util.Arrays.<TypeReference<?>>asList(new TypeReference<DynamicArray<Uint256>>() {}));
    return new RemoteFunctionCall<List>(function,
            new Callable<List>() {
                @Override
                @SuppressWarnings("unchecked")
                public List call() throws Exception {
                    List<Type> result = (List<Type>) executeCallSingleValueReturn(function, List.class);
                    return convertToNative(result);
                }
            });
}
 
Example #19
Source File: Arrays.java    From web3j with Apache License 2.0 6 votes vote down vote up
public RemoteFunctionCall<List> dynamicReverse(List<BigInteger> input) {
    final Function function = new Function(FUNC_DYNAMICREVERSE, 
            java.util.Arrays.<Type>asList(new org.web3j.abi.datatypes.DynamicArray<org.web3j.abi.datatypes.generated.Uint256>(
                    org.web3j.abi.datatypes.generated.Uint256.class,
                    org.web3j.abi.Utils.typeMap(input, org.web3j.abi.datatypes.generated.Uint256.class))), 
            java.util.Arrays.<TypeReference<?>>asList(new TypeReference<DynamicArray<Uint256>>() {}));
    return new RemoteFunctionCall<List>(function,
            new Callable<List>() {
                @Override
                @SuppressWarnings("unchecked")
                public List call() throws Exception {
                    List<Type> result = (List<Type>) executeCallSingleValueReturn(function, List.class);
                    return convertToNative(result);
                }
            });
}
 
Example #20
Source File: TypeDecoderTest.java    From web3j with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void multiDimArrays() throws Exception {
    byte[] bytes1d = new byte[] {1, 2, 3};
    byte[][] bytes2d = new byte[][] {bytes1d, bytes1d, bytes1d};
    final byte[][][] bytes3d = new byte[][][] {bytes2d, bytes2d, bytes2d};

    assertEquals(TypeDecoder.instantiateType("bytes", bytes1d), (new DynamicBytes(bytes1d)));

    Type twoDim = TypeDecoder.instantiateType("uint256[][3]", bytes2d);
    assertTrue(twoDim instanceof StaticArray3);
    StaticArray3<DynamicArray<Uint256>> staticArray3 =
            (StaticArray3<DynamicArray<Uint256>>) twoDim;
    assertEquals(staticArray3.getComponentType(), DynamicArray.class);
    DynamicArray<Uint256> row1 = staticArray3.getValue().get(1);
    assertEquals(row1.getValue().get(2), new Uint256(3));

    Type threeDim = TypeDecoder.instantiateType("uint256[][3][3]", bytes3d);
    assertTrue(threeDim instanceof StaticArray3);
    StaticArray3<StaticArray3<DynamicArray<Uint256>>> staticArray3StaticArray3 =
            (StaticArray3<StaticArray3<DynamicArray<Uint256>>>) threeDim;
    assertEquals(staticArray3StaticArray3.getComponentType(), StaticArray3.class);
    row1 = staticArray3StaticArray3.getValue().get(1).getValue().get(1);
    assertEquals(row1.getValue().get(1), (new Uint256(2)));
}
 
Example #21
Source File: TypeEncoderTest.java    From web3j with Apache License 2.0 6 votes vote down vote up
@Test
public void testDynamicArray() {
    DynamicArray<Uint> array =
            new DynamicArray<>(
                    Uint.class,
                    new Uint(BigInteger.ONE),
                    new Uint(BigInteger.valueOf(2)),
                    new Uint(BigInteger.valueOf(3)));

    assertEquals(
            TypeEncoder.encodeDynamicArray(array),
            ("0000000000000000000000000000000000000000000000000000000000000003"
                    + "0000000000000000000000000000000000000000000000000000000000000001"
                    + "0000000000000000000000000000000000000000000000000000000000000002"
                    + "0000000000000000000000000000000000000000000000000000000000000003"));
}
 
Example #22
Source File: OnChainPrivacyTransactionBuilder.java    From web3j with Apache License 2.0 5 votes vote down vote up
public static String getEncodedAddToGroupFunction(
        Base64String enclaveKey, List<byte[]> participants) {
    final Function function =
            new Function(
                    "addParticipants",
                    Arrays.asList(
                            new Bytes32(enclaveKey.raw()),
                            new DynamicArray<>(
                                    Bytes32.class, Utils.typeMap(participants, Bytes32.class))),
                    Collections.emptyList());
    return FunctionEncoder.encode(function);
}
 
Example #23
Source File: DefaultFunctionReturnDecoder.java    From web3j with Apache License 2.0 5 votes vote down vote up
private static <T extends Type> int getDataOffset(String input, int offset, Class<T> type) {
    if (DynamicBytes.class.isAssignableFrom(type)
            || Utf8String.class.isAssignableFrom(type)
            || DynamicArray.class.isAssignableFrom(type)) {
        return TypeDecoder.decodeUintAsInt(input, offset) << 1;
    } else {
        return offset;
    }
}
 
Example #24
Source File: OnChainPrivacyGroupManagementProxy.java    From besu with Apache License 2.0 5 votes vote down vote up
public RemoteFunctionCall<TransactionReceipt> addParticipants(
    byte[] enclaveKey, List<byte[]> participants) {
  final Function function =
      new Function(
          FUNC_ADDPARTICIPANTS,
          Arrays.<Type>asList(
              new org.web3j.abi.datatypes.generated.Bytes32(enclaveKey),
              new org.web3j.abi.datatypes.DynamicArray<org.web3j.abi.datatypes.generated.Bytes32>(
                  org.web3j.abi.datatypes.generated.Bytes32.class,
                  org.web3j.abi.Utils.typeMap(
                      participants, org.web3j.abi.datatypes.generated.Bytes32.class))),
          Collections.<TypeReference<?>>emptyList());
  return executeRemoteCallTransaction(function);
}
 
Example #25
Source File: Arrays.java    From web3j with Apache License 2.0 5 votes vote down vote up
public RemoteFunctionCall<List> returnArray() {
    final Function function = new Function(FUNC_RETURNARRAY, 
            java.util.Arrays.<Type>asList(), 
            java.util.Arrays.<TypeReference<?>>asList(new TypeReference<DynamicArray<Address>>() {}));
    return new RemoteFunctionCall<List>(function,
            new Callable<List>() {
                @Override
                @SuppressWarnings("unchecked")
                public List call() throws Exception {
                    List<Type> result = (List<Type>) executeCallSingleValueReturn(function, List.class);
                    return convertToNative(result);
                }
            });
}
 
Example #26
Source File: FunctionReturnDecoder.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
private static <T extends Type> int getDataOffset(String input, int offset, Class<T> type) {
    if (DynamicBytes.class.isAssignableFrom(type)
            || Utf8String.class.isAssignableFrom(type)
            || DynamicArray.class.isAssignableFrom(type)) {
        return TypeDecoder.decodeUintAsInt(input, offset) << 1;
    } else {
        return offset;
    }
}
 
Example #27
Source File: TypeDecoder.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
public static <T extends Array> T decode(
        String input, int offset, TypeReference<T> typeReference) {
    Class cls = ((ParameterizedType) typeReference.getType()).getRawType().getClass();
    if (StaticArray.class.isAssignableFrom(cls)) {
        return decodeStaticArray(input, offset, typeReference, 1);
    } else if (DynamicArray.class.isAssignableFrom(cls)) {
        return decodeDynamicArray(input, offset, typeReference);
    } else {
        throw new UnsupportedOperationException("Unsupported TypeReference: "
                + cls.getName() + ", only Array types can be passed as TypeReferences");
    }
}
 
Example #28
Source File: Web3jEventParameterConverter.java    From eventeum with Apache License 2.0 5 votes vote down vote up
private EventParameter<?> convertDynamicArray(DynamicArray<?> toConvert) {
    final ArrayList<EventParameter<?>> convertedArray = new ArrayList<>();

    toConvert.getValue().forEach(arrayEntry -> convertedArray.add(convert(arrayEntry)));

    return new ArrayParameter(toConvert.getValue().get(0).getTypeAsString().toLowerCase(),
            toConvert.getComponentType(), convertedArray);
}
 
Example #29
Source File: SolidityFunctionWrapperTest.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testGetEventNativeTypeParameterized() {
    assertThat(getEventNativeType(
            ParameterizedTypeName.get(
                    ClassName.get(DynamicArray.class), TypeName.get(Address.class))),
            equalTo(TypeName.get(byte[].class)));
}
 
Example #30
Source File: TypeDecoder.java    From web3j with Apache License 2.0 5 votes vote down vote up
public static <T extends Array> T decode(
        String input, int offset, TypeReference<T> typeReference) {
    Class cls = ((ParameterizedType) typeReference.getType()).getRawType().getClass();
    if (StaticArray.class.isAssignableFrom(cls)) {
        return decodeStaticArray(input, offset, typeReference, 1);
    } else if (DynamicArray.class.isAssignableFrom(cls)) {
        return decodeDynamicArray(input, offset, typeReference);
    } else {
        throw new UnsupportedOperationException(
                "Unsupported TypeReference: "
                        + cls.getName()
                        + ", only Array types can be passed as TypeReferences");
    }
}