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

The following examples show how to use org.web3j.protocol.core.methods.response.AbiDefinition#isPayable() . 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
private MethodSpec buildDeploy(
        String className, AbiDefinition functionDefinition,
        Class authType, String authName, boolean withGasProvider) {

    boolean isPayable = functionDefinition.isPayable();

    MethodSpec.Builder methodBuilder = getDeployMethodSpec(
            className, authType, authName, isPayable, withGasProvider);
    String inputParams = addParameters(methodBuilder, functionDefinition.getInputs());

    if (!inputParams.isEmpty()) {
        return buildDeployWithParams(
                methodBuilder, className, inputParams, authName,
                isPayable, withGasProvider);
    } else {
        return buildDeployNoParams(methodBuilder, className, authName,
                isPayable, withGasProvider);
    }
}
 
Example 2
Source File: SolidityFunctionWrapper.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
private MethodSpec buildDeploy(
        String className, AbiDefinition functionDefinition,
        Class authType, String authName) {

    boolean isPayable = functionDefinition.isPayable();

    MethodSpec.Builder methodBuilder = getDeployMethodSpec(
            className, authType, authName, isPayable);
    String inputParams = addParameters(methodBuilder, functionDefinition.getInputs());

    if (!inputParams.isEmpty()) {
        return buildDeployWithParams(
                methodBuilder, className, inputParams, authName, isPayable);
    } else {
        return buildDeployNoParams(methodBuilder, className, authName, isPayable);
    }
}
 
Example 3
Source File: SolidityFunctionWrapper.java    From web3j with Apache License 2.0 6 votes vote down vote up
private MethodSpec buildDeploy(
        String className,
        AbiDefinition functionDefinition,
        Class authType,
        String authName,
        boolean withGasProvider)
        throws ClassNotFoundException {

    boolean isPayable = functionDefinition.isPayable();

    MethodSpec.Builder methodBuilder =
            getDeployMethodSpec(className, authType, authName, isPayable, withGasProvider);
    String inputParams = addParameters(methodBuilder, functionDefinition.getInputs());

    if (!inputParams.isEmpty()) {
        return buildDeployWithParams(
                methodBuilder, className, inputParams, authName, isPayable, withGasProvider);
    } else {
        return buildDeployNoParams(
                methodBuilder, className, authName, isPayable, withGasProvider);
    }
}
 
Example 4
Source File: SolidityFunctionWrapper.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
private void buildTransactionFunction(
        AbiDefinition functionDefinition,
        MethodSpec.Builder methodBuilder,
        String inputParams) throws ClassNotFoundException {

    if (functionDefinition.hasOutputs()) {
        //CHECKSTYLE:OFF
        reporter.report(String.format(
                "Definition of the function %s returns a value but is not defined as a view function. "
                        + "Please ensure it contains the view modifier if you want to read the return value",
                functionDefinition.getName()));
        //CHECKSTYLE:ON
    }

    if (functionDefinition.isPayable()) {
        methodBuilder.addParameter(BigInteger.class, WEI_VALUE);
    }

    String functionName = functionDefinition.getName();

    methodBuilder.returns(buildRemoteCall(TypeName.get(TransactionReceipt.class)));

    methodBuilder.addStatement("final $T function = new $T(\n$N, \n$T.<$T>asList($L), \n$T"
                    + ".<$T<?>>emptyList())",
            Function.class, Function.class, funcNameToConst(functionName),
            Arrays.class, Type.class, inputParams, Collections.class,
            TypeReference.class);
    if (functionDefinition.isPayable()) {
        methodBuilder.addStatement(
                "return executeRemoteCallTransaction(function, $N)", WEI_VALUE);
    } else {
        methodBuilder.addStatement("return executeRemoteCallTransaction(function)");
    }
}
 
Example 5
Source File: SolidityFunctionWrapper.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
private void buildTransactionFunction(
        AbiDefinition functionDefinition,
        MethodSpec.Builder methodBuilder,
        String inputParams) throws ClassNotFoundException {

    if (functionDefinition.hasOutputs()) {
        //CHECKSTYLE:OFF
        reporter.report(String.format(
                "Definition of the function %s returns a value but is not defined as a view function. "
                        + "Please ensure it contains the view modifier if you want to read the return value",
                functionDefinition.getName()));
        //CHECKSTYLE:ON
    }

    if (functionDefinition.isPayable()) {
        methodBuilder.addParameter(BigInteger.class, WEI_VALUE);
    }

    String functionName = functionDefinition.getName();

    methodBuilder.returns(buildRemoteCall(TypeName.get(TransactionReceipt.class)));

    methodBuilder.addStatement("final $T function = new $T(\n$S, \n$T.<$T>asList($L), \n$T"
                    + ".<$T<?>>emptyList())",
            Function.class, Function.class, functionName,
            Arrays.class, Type.class, inputParams, Collections.class,
            TypeReference.class);
    if (functionDefinition.isPayable()) {
        methodBuilder.addStatement(
                "return executeRemoteCallTransaction(function, $N)", WEI_VALUE);
    } else {
        methodBuilder.addStatement("return executeRemoteCallTransaction(function)");
    }
}
 
Example 6
Source File: SolidityFunctionWrapper.java    From web3j with Apache License 2.0 4 votes vote down vote up
private void buildTransactionFunction(
        AbiDefinition functionDefinition,
        MethodSpec.Builder methodBuilder,
        String inputParams,
        boolean useUpperCase)
        throws ClassNotFoundException {

    if (functionDefinition.hasOutputs()) {
        reporter.report(
                String.format(
                        "Definition of the function %s returns a value but is not defined as a view function. "
                                + "Please ensure it contains the view modifier if you want to read the return value",
                        functionDefinition.getName()));
    }

    if (functionDefinition.isPayable()) {
        methodBuilder.addParameter(BigInteger.class, WEI_VALUE);
    }

    String functionName = functionDefinition.getName();

    methodBuilder.returns(buildRemoteFunctionCall(TypeName.get(TransactionReceipt.class)));

    methodBuilder.addStatement(
            "final $T function = new $T(\n$N, \n$T.<$T>asList($L), \n$T"
                    + ".<$T<?>>emptyList())",
            Function.class,
            Function.class,
            funcNameToConst(functionName, useUpperCase),
            Arrays.class,
            Type.class,
            inputParams,
            Collections.class,
            TypeReference.class);
    if (functionDefinition.isPayable()) {
        methodBuilder.addStatement(
                "return executeRemoteCallTransaction(function, $N)", WEI_VALUE);
    } else {
        methodBuilder.addStatement("return executeRemoteCallTransaction(function)");
    }
}