Java Code Examples for org.web3j.protocol.core.methods.response.AbiDefinition#hasOutputs()
The following examples show how to use
org.web3j.protocol.core.methods.response.AbiDefinition#hasOutputs() .
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 | 5 votes |
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 2
Source File: SolidityFunctionWrapper.java From etherscan-explorer with GNU General Public License v3.0 | 5 votes |
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 3
Source File: SolidityFunctionWrapper.java From web3j with Apache License 2.0 | 4 votes |
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; }
Example 4
Source File: SolidityFunctionWrapper.java From web3j with Apache License 2.0 | 4 votes |
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)"); } }