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)"); } }
@Override public int hashCode() { int result = (isConstant() ? 1 : 0); result = 31 * result + (getInputs() != null ? getInputs().hashCode() : 0); result = 31 * result + (getName() != null ? getName().hashCode() : 0); result = 31 * result + (getOutputs() != null ? getOutputs().hashCode() : 0); result = 31 * result + (getType() != null ? getType().hashCode() : 0); result = 31 * result + (isPayable() ? 1 : 0); result = 31 * result + (getStateMutability() != null ? getStateMutability().hashCode() : 0); return result; }
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); } }
@Test public void testParseConvertLib() throws Exception { Contract mc = parseContractJson(contractBaseDir, "MetaCoin", "ConvertLib"); assertEquals("Unexpected contract name", "ConvertLib", mc.getContractName()); assertEquals("Unexpected number of functions", 1, mc.abi.size()); AbiDefinition abi = mc.abi.get(0); assertEquals("Unexpected function name", "convert", abi.getName()); assertTrue("Expected function to be 'constant'", abi.isConstant()); assertFalse("Expected function to not be 'payable'", abi.isPayable()); assertEquals("Expected abi to represent a function", "function", abi.getType()); assertEquals("Expected the 'pure' for the state mutability setting", "pure", abi.getStateMutability()); } }
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)"); } }
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); } }