SolidityFunctionWrapper extends Generator { public List<MethodSpec> buildEventFunctions( AbiDefinition functionDefinition, TypeSpec.Builder classBuilder) throws ClassNotFoundException { String functionName = functionDefinition.getName(); List<AbiDefinition.NamedType> inputs = functionDefinition.getInputs(); String responseClassName = Strings.capitaliseFirstLetter(functionName) + "EventResponse"; List<NamedTypeName> indexedParameters = new ArrayList<>(); List<NamedTypeName> nonIndexedParameters = new ArrayList<>(); for (AbiDefinition.NamedType namedType : inputs) { if (namedType.isIndexed()) { indexedParameters.add( new com.peersafe.codegen.SolidityFunctionWrapper.NamedTypeName( namedType.getName(), buildTypeName(namedType.getType()))); } else { nonIndexedParameters.add( new com.peersafe.codegen.SolidityFunctionWrapper.NamedTypeName( namedType.getName(), buildTypeName(namedType.getType()))); } } classBuilder.addField(createEventDefinition(functionName, indexedParameters, nonIndexedParameters)); classBuilder.addType(buildEventResponseObject(responseClassName, indexedParameters, nonIndexedParameters)); List<MethodSpec> methods = new ArrayList<>(); methods.add(buildEventFunction(responseClassName, functionName, indexedParameters, nonIndexedParameters)); return methods; } SolidityFunctionWrapper(boolean useNativeJavaTypes);  SolidityFunctionWrapper(boolean useNativeJavaTypes, GenerationReporter reporter); @SuppressWarnings("unchecked") void generateJavaFiles(
            String contractName, String bin, String abi, String destinationDir,
            String basePackageName); Iterable<FieldSpec> buildFuncNameConstants(List<AbiDefinition> functionDefinitions); static TypeName getNativeType(TypeName typeName); static TypeName getNativeType(ParameterizedTypeName parameterizedTypeName); static TypeName getEventNativeType(TypeName typeName); static String createValidParamName(String name, int idx); static List<TypeName> buildTypeNames(List<AbiDefinition.NamedType> namedTypes); MethodSpec buildFunction(
            AbiDefinition functionDefinition); MethodSpec buildEventFunction(
            String responseClassName,
            String functionName,
            List<NamedTypeName> indexedParameters,
            List<NamedTypeName> nonIndexedParameters); List<MethodSpec> buildEventFunctions(
            AbiDefinition functionDefinition,
            TypeSpec.Builder classBuilder); CodeBlock buildTypedResponse(
            String objectName,
            List<com.peersafe.codegen.SolidityFunctionWrapper.NamedTypeName> indexedParameters,
            List<com.peersafe.codegen.SolidityFunctionWrapper.NamedTypeName> nonIndexedParameters,
            boolean observable); static TypeName buildTypeName(String typeDeclaration);  }
@Test public void testBuildEventConstantMultipleValueReturn() throws Exception { AbiDefinition.NamedType id = new AbiDefinition.NamedType("id", "string", true); AbiDefinition.NamedType fromAddress = new AbiDefinition.NamedType("from", "address"); AbiDefinition.NamedType toAddress = new AbiDefinition.NamedType("to", "address"); AbiDefinition.NamedType value = new AbiDefinition.NamedType("value", "uint256"); AbiDefinition.NamedType message = new AbiDefinition.NamedType("message", "string"); fromAddress.setIndexed(true); toAddress.setIndexed(true); AbiDefinition functionDefinition = new AbiDefinition( false, Arrays.asList(id, fromAddress, toAddress, value, message), "Transfer", new ArrayList<>(), "event", false); TypeSpec.Builder builder = TypeSpec.classBuilder("testClass"); builder.addMethods( solidityFunctionWrapper.buildEventFunctions(functionDefinition, builder)); String expected = "class testClass {\n" + " public static final com.peersafe.abi.datatypes.Event TRANSFER_EVENT = new com.peersafe.abi.datatypes.Event(\"Transfer\", \n" + " java.util.Arrays.<com.peersafe.abi.TypeReference<?>>asList(new com.peersafe.abi.TypeReference<com.peersafe.abi.datatypes.Utf8String>() {}, new com.peersafe.abi.TypeReference<com.peersafe.abi.datatypes.Address>() {}, new com.peersafe.abi.TypeReference<com.peersafe.abi.datatypes.Address>() {}),\n" + " java.util.Arrays.<com.peersafe.abi.TypeReference<?>>asList(new com.peersafe.abi.TypeReference<com.peersafe.abi.datatypes.generated.Uint256>() {}, new com.peersafe.abi.TypeReference<com.peersafe.abi.datatypes.Utf8String>() {}));\n ;\n\n" + " public java.util.List<TransferEventResponse> getTransferEvents(org.web3j.protocol.core.methods.response.TransactionReceipt transactionReceipt) {\n" + " java.util.List<org.web3j.tx.Contract.EventValuesWithLog> valueList = extractEventParametersWithLog(TRANSFER_EVENT, transactionReceipt);\n" + " java.util.ArrayList<TransferEventResponse> responses = new java.util.ArrayList<TransferEventResponse>(valueList.size());\n" + " for (org.web3j.tx.Contract.EventValuesWithLog eventValues : valueList) {\n" + " TransferEventResponse typedResponse = new TransferEventResponse();\n" + " typedResponse.log = eventValues.getLog();\n" + " typedResponse.id = (byte[]) eventValues.getIndexedValues().get(0).getValue();\n" + " typedResponse.from = (java.lang.String) eventValues.getIndexedValues().get(1).getValue();\n" + " typedResponse.to = (java.lang.String) eventValues.getIndexedValues().get(2).getValue();\n" + " typedResponse.value = (java.math.BigInteger) eventValues.getNonIndexedValues().get(0).getValue();\n" + " typedResponse.message = (java.lang.String) eventValues.getNonIndexedValues().get(1).getValue();\n" + " responses.add(typedResponse);\n" + " }\n" + " return responses;\n" + " }\n" + "\n" + " public rx.Observable<TransferEventResponse> transferEventObservable(org.web3j.protocol.core.methods.request.EthFilter filter) {\n" + " return web3j.ethLogObservable(filter).map(new rx.functions.Func1<org.web3j.protocol.core.methods.response.Log, TransferEventResponse>() {\n" + " @java.lang.Override\n" + " public TransferEventResponse call(org.web3j.protocol.core.methods.response.Log log) {\n" + " org.web3j.tx.Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(TRANSFER_EVENT, log);\n" + " TransferEventResponse typedResponse = new TransferEventResponse();\n" + " typedResponse.log = log;\n" + " typedResponse.id = (byte[]) eventValues.getIndexedValues().get(0).getValue();\n" + " typedResponse.from = (java.lang.String) eventValues.getIndexedValues().get(1).getValue();\n" + " typedResponse.to = (java.lang.String) eventValues.getIndexedValues().get(2).getValue();\n" + " typedResponse.value = (java.math.BigInteger) eventValues.getNonIndexedValues().get(0).getValue();\n" + " typedResponse.message = (java.lang.String) eventValues.getNonIndexedValues().get(1).getValue();\n" + " return typedResponse;\n" + " }\n" + " });\n" + " }\n" + "\n" + " public rx.Observable<TransferEventResponse> transferEventObservable(org.web3j.protocol.core.DefaultBlockParameter startBlock, org.web3j.protocol.core.DefaultBlockParameter endBlock) {\n" + " org.web3j.protocol.core.methods.request.EthFilter filter = new org.web3j.protocol.core.methods.request.EthFilter(startBlock, endBlock, getContractAddress());\n" + " filter.addSingleTopic(com.peersafe.abi.EventEncoder.encode(TRANSFER_EVENT));\n" + " return transferEventObservable(filter);\n" + " }\n" + "\n" + " public static class TransferEventResponse {\n" + " public org.web3j.protocol.core.methods.response.Log log;\n" + "\n" + " public byte[] id;\n" + "\n" + " public java.lang.String from;\n" + "\n" + " public java.lang.String to;\n" + "\n" + " public java.math.BigInteger value;\n" + "\n" + " public java.lang.String message;\n" + " }\n" + "}\n"; assertThat(builder.build().toString(), is(expected)); }