Java Code Examples for org.web3j.protocol.core.methods.response.AbiDefinition#isConstant()

The following examples show how to use org.web3j.protocol.core.methods.response.AbiDefinition#isConstant() . 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: SolidityFunctionWrapper.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
MethodSpec buildFunction(
        AbiDefinition functionDefinition) throws ClassNotFoundException {
    String functionName = functionDefinition.getName();

    MethodSpec.Builder methodBuilder =
            MethodSpec.methodBuilder(functionName)
                    .addModifiers(Modifier.PUBLIC);

    String inputParams = addParameters(methodBuilder, functionDefinition.getInputs());

    List<TypeName> outputParameterTypes = buildTypeNames(functionDefinition.getOutputs());
    if (functionDefinition.isConstant()) {
        buildConstantFunction(
                functionDefinition, methodBuilder, outputParameterTypes, inputParams);
    } else {
        buildTransactionFunction(
                functionDefinition, methodBuilder, inputParams);
    }

    return methodBuilder.build();
}
 
Example 2
Source File: SolidityFunctionWrapper.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
MethodSpec buildFunction(
        AbiDefinition functionDefinition) throws ClassNotFoundException {
    String functionName = functionDefinition.getName();

    MethodSpec.Builder methodBuilder =
            MethodSpec.methodBuilder(functionName)
                    .addModifiers(Modifier.PUBLIC);

    String inputParams = addParameters(methodBuilder, functionDefinition.getInputs());

    List<TypeName> outputParameterTypes = buildTypeNames(functionDefinition.getOutputs());
    if (functionDefinition.isConstant()) {
        buildConstantFunction(
                functionDefinition, methodBuilder, outputParameterTypes, inputParams);
    } else {
        buildTransactionFunction(
                functionDefinition, methodBuilder, inputParams);
    }

    return methodBuilder.build();
}
 
Example 3
Source File: SolidityFunctionWrapper.java    From web3j with Apache License 2.0 4 votes vote down vote up
List<MethodSpec> buildFunctions(AbiDefinition functionDefinition, boolean useUpperCase)
        throws ClassNotFoundException {

    List<MethodSpec> results = new ArrayList<>(2);
    String functionName = functionDefinition.getName();

    String stateMutability = functionDefinition.getStateMutability();
    boolean pureOrView = "pure".equals(stateMutability) || "view".equals(stateMutability);
    boolean isFunctionDefinitionConstant = functionDefinition.isConstant() || pureOrView;

    if (generateSendTxForCalls) {
        final String funcNamePrefix;
        if (isFunctionDefinitionConstant) {
            funcNamePrefix = "call";
        } else {
            funcNamePrefix = "send";
        }
        // Prefix function name to avoid naming collision
        functionName = funcNamePrefix + "_" + functionName;
    } else {
        // If the solidity function name is a reserved word
        // in the current java version prepend it with "_"
        if (!SourceVersion.isName(functionName)) {
            functionName = "_" + functionName;
        }
    }

    MethodSpec.Builder methodBuilder =
            MethodSpec.methodBuilder(functionName).addModifiers(Modifier.PUBLIC);

    final String inputParams = addParameters(methodBuilder, functionDefinition.getInputs());
    final List<TypeName> outputParameterTypes =
            buildTypeNames(functionDefinition.getOutputs(), useJavaPrimitiveTypes);

    if (isFunctionDefinitionConstant) {
        // Avoid generating runtime exception call
        if (functionDefinition.hasOutputs()) {
            buildConstantFunction(
                    functionDefinition,
                    methodBuilder,
                    outputParameterTypes,
                    inputParams,
                    useUpperCase);

            results.add(methodBuilder.build());
        }
        if (generateSendTxForCalls) {
            AbiDefinition sendFuncDefinition = new AbiDefinition(functionDefinition);
            sendFuncDefinition.setConstant(false);
            results.addAll(buildFunctions(sendFuncDefinition));
        }
    }

    if (!isFunctionDefinitionConstant) {
        buildTransactionFunction(functionDefinition, methodBuilder, inputParams, useUpperCase);
        results.add(methodBuilder.build());
    }

    return results;
}