Java Code Examples for org.web3j.utils.Collection

The following examples show how to use org.web3j.utils.Collection. These examples are extracted from open source projects. 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 Project: web3j   Source File: SolidityFunctionWrapper.java    License: Apache License 2.0 6 votes vote down vote up
private java.util.Collection<? extends AbiDefinition.NamedType> extractNested(
        final AbiDefinition.NamedType namedType) {
    if (namedType.getComponents().size() == 0) {
        return new ArrayList<>();
    } else {
        List<AbiDefinition.NamedType> nestedStructs = new ArrayList<>();
        namedType
                .getComponents()
                .forEach(
                        nestedNamedStruct -> {
                            nestedStructs.add(nestedNamedStruct);
                            nestedStructs.addAll(extractNested(nestedNamedStruct));
                        });
        return nestedStructs;
    }
}
 
Example 2
Source Project: client-sdk-java   Source File: WasmFunctionWrapper.java    License: Apache License 2.0 5 votes vote down vote up
String addParameters(MethodSpec.Builder methodBuilder, List<WasmAbiDefinition.NamedType> namedTypes, Set<String> customTypes) {
	List<ParameterSpec> inputParameterTypes = buildParameterTypes(namedTypes, customTypes);
	methodBuilder.addParameters(inputParameterTypes);
	String inputParams = Collection.join(inputParameterTypes, ",", parameterSpec -> parameterSpec.name);

	if (inputParameterTypes.size() == 1 && inputParameterTypes.get(0).type instanceof ArrayTypeName) {
		inputParams += ", Void.class";
	}
	return inputParams;
}
 
Example 3
Source Project: client-sdk-java   Source File: SolidityFunctionWrapper.java    License: Apache License 2.0 5 votes vote down vote up
String addParameters(
        MethodSpec.Builder methodBuilder, List<AbiDefinition.NamedType> namedTypes) {

    List<ParameterSpec> inputParameterTypes = buildParameterTypes(namedTypes);

    List<ParameterSpec> nativeInputParameterTypes =
            new ArrayList<>(inputParameterTypes.size());
    for (ParameterSpec parameterSpec : inputParameterTypes) {
        TypeName typeName = getWrapperType(parameterSpec.type);
        nativeInputParameterTypes.add(
                ParameterSpec.builder(typeName, parameterSpec.name).build());
    }

    methodBuilder.addParameters(nativeInputParameterTypes);

    if (useNativeJavaTypes) {
        return Collection.join(
                inputParameterTypes,
                ", \n",
                // this results in fully qualified names being generated
                this::createMappedParameterTypes);
    } else {
        return Collection.join(
                inputParameterTypes,
                ", ",
                parameterSpec -> parameterSpec.name);
    }
}
 
Example 4
Source Project: client-sdk-java   Source File: SolidityFunctionWrapper.java    License: Apache License 2.0 5 votes vote down vote up
private static void buildVariableLengthReturnFunctionConstructor(
        MethodSpec.Builder methodBuilder, String functionName, String inputParameters,
        List<TypeName> outputParameterTypes) throws ClassNotFoundException {

    List<Object> objects = new ArrayList<>();
    objects.add(Function.class);
    objects.add(Function.class);
    objects.add(funcNameToConst(functionName));

    objects.add(Arrays.class);
    objects.add(Type.class);
    objects.add(inputParameters);

    objects.add(Arrays.class);
    objects.add(TypeReference.class);
    for (TypeName outputParameterType : outputParameterTypes) {
        objects.add(TypeReference.class);
        objects.add(outputParameterType);
    }

    String asListParams = Collection.join(
            outputParameterTypes,
            ", ",
            typeName -> "new $T<$T>() {}");

    methodBuilder.addStatement("final $T function = new $T($N, \n$T.<$T>asList($L), \n$T"
            + ".<$T<?>>asList("
            + asListParams + "))", objects.toArray());
}
 
Example 5
String addParameters(
        MethodSpec.Builder methodBuilder, List<AbiDefinition.NamedType> namedTypes) {

    List<ParameterSpec> inputParameterTypes = buildParameterTypes(namedTypes);

    List<ParameterSpec> nativeInputParameterTypes =
            new ArrayList<>(inputParameterTypes.size());
    for (ParameterSpec parameterSpec : inputParameterTypes) {
        TypeName typeName = getWrapperType(parameterSpec.type);
        nativeInputParameterTypes.add(
                ParameterSpec.builder(typeName, parameterSpec.name).build());
    }

    methodBuilder.addParameters(nativeInputParameterTypes);

    if (useNativeJavaTypes) {
        return Collection.join(
                inputParameterTypes,
                ", \n",
                // this results in fully qualified names being generated
                this::createMappedParameterTypes);
    } else {
        return Collection.join(
                inputParameterTypes,
                ", ",
                parameterSpec -> parameterSpec.name);
    }
}
 
Example 6
private static void buildVariableLengthReturnFunctionConstructor(
        MethodSpec.Builder methodBuilder, String functionName, String inputParameters,
        List<TypeName> outputParameterTypes) throws ClassNotFoundException {

    List<Object> objects = new ArrayList<>();
    objects.add(Function.class);
    objects.add(Function.class);
    objects.add(functionName);

    objects.add(Arrays.class);
    objects.add(Type.class);
    objects.add(inputParameters);

    objects.add(Arrays.class);
    objects.add(TypeReference.class);
    for (TypeName outputParameterType : outputParameterTypes) {
        objects.add(TypeReference.class);
        objects.add(outputParameterType);
    }

    String asListParams = Collection.join(
            outputParameterTypes,
            ", ",
            typeName -> "new $T<$T>() {}");

    methodBuilder.addStatement("final $T function = new $T($S, \n$T.<$T>asList($L), \n$T"
            + ".<$T<?>>asList("
            + asListParams + "))", objects.toArray());
}
 
Example 7
Source Project: web3j   Source File: SolidityFunctionWrapper.java    License: Apache License 2.0 5 votes vote down vote up
String addParameters(MethodSpec.Builder methodBuilder, List<AbiDefinition.NamedType> namedTypes)
        throws ClassNotFoundException {

    final List<ParameterSpec> inputParameterTypes =
            buildParameterTypes(namedTypes, useJavaPrimitiveTypes);

    final List<ParameterSpec> nativeInputParameterTypes =
            new ArrayList<>(inputParameterTypes.size());

    for (int i = 0; i < inputParameterTypes.size(); ++i) {
        final TypeName typeName;
        if (namedTypes.get(i).getType().equals("tuple")) {
            typeName = structClassNameMap.get(namedTypes.get(i).structIdentifier());
        } else {
            typeName = getWrapperType(inputParameterTypes.get(i).type);
        }
        nativeInputParameterTypes.add(
                ParameterSpec.builder(typeName, inputParameterTypes.get(i).name).build());
    }

    methodBuilder.addParameters(nativeInputParameterTypes);

    if (useNativeJavaTypes) {
        return Collection.join(
                inputParameterTypes,
                ", \n",
                // this results in fully qualified names being generated
                this::createMappedParameterTypes);
    } else {
        return Collection.join(inputParameterTypes, ", ", parameterSpec -> parameterSpec.name);
    }
}
 
Example 8
Source Project: web3j   Source File: SolidityFunctionWrapper.java    License: Apache License 2.0 5 votes vote down vote up
private static void buildVariableLengthReturnFunctionConstructor(
        MethodSpec.Builder methodBuilder,
        String functionName,
        String inputParameters,
        List<TypeName> outputParameterTypes,
        boolean useUpperCase)
        throws ClassNotFoundException {

    List<Object> objects = new ArrayList<>();
    objects.add(Function.class);
    objects.add(Function.class);
    objects.add(funcNameToConst(functionName, useUpperCase));

    objects.add(Arrays.class);
    objects.add(Type.class);
    objects.add(inputParameters);

    objects.add(Arrays.class);
    objects.add(TypeReference.class);
    for (TypeName outputParameterType : outputParameterTypes) {
        objects.add(TypeReference.class);
        objects.add(outputParameterType);
    }

    String asListParams =
            Collection.join(outputParameterTypes, ", ", typeName -> "new $T<$T>() {}");

    methodBuilder.addStatement(
            "final $T function = new $T($N, \n$T.<$T>asList($L), \n$T"
                    + ".<$T<?>>asList("
                    + asListParams
                    + "))",
            objects.toArray());
}