@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"); solidityFunctionWrapper.buildEventFunctions(functionDefinition, builder); String expected = "class testClass {\n" + " public java.util.List<TransferEventResponse> getTransferEvents(com.citahub.cita.protocol.core.methods.response.TransactionReceipt transactionReceipt) {\n" + " final com.citahub.cita.abi.datatypes.Event event = new com.citahub.cita.abi.datatypes.Event(\"Transfer\", \n" + " java.util.Arrays.<com.citahub.cita.abi.TypeReference<?>>asList(new com.citahub.cita.abi.TypeReference<com.citahub.cita.abi.datatypes.Utf8String>() {}, new com.citahub.cita.abi.TypeReference<com.citahub.cita.abi.datatypes.Address>() {}, new com.citahub.cita.abi.TypeReference<com.citahub.cita.abi.datatypes.Address>() {}),\n" + " java.util.Arrays.<com.citahub.cita.abi.TypeReference<?>>asList(new com.citahub.cita.abi.TypeReference<com.citahub.cita.abi.datatypes.generated.Uint256>() {}, new com.citahub.cita.abi.TypeReference<com.citahub.cita.abi.datatypes.Utf8String>() {}));\n" + " java.util.List<com.citahub.cita.abi.EventValues> valueList = extractEventParameters(event, transactionReceipt);\n" + " java.util.ArrayList<TransferEventResponse> responses = new java.util.ArrayList<TransferEventResponse>(valueList.size());\n" + " for (com.citahub.cita.abi.EventValues eventValues : valueList) {\n" + " TransferEventResponse typedResponse = new TransferEventResponse();\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 io.reactivex.Flowable<TransferEventResponse> transferEventFlowable(com.citahub.cita.protocol.core.DefaultBlockParameter startBlock, com.citahub.cita.protocol.core.DefaultBlockParameter endBlock) {\n" + " final com.citahub.cita.abi.datatypes.Event event = new com.citahub.cita.abi.datatypes.Event(\"Transfer\", \n" + " java.util.Arrays.<com.citahub.cita.abi.TypeReference<?>>asList(new com.citahub.cita.abi.TypeReference<com.citahub.cita.abi.datatypes.Utf8String>() {}, new com.citahub.cita.abi.TypeReference<com.citahub.cita.abi.datatypes.Address>() {}, new com.citahub.cita.abi.TypeReference<com.citahub.cita.abi.datatypes.Address>() {}),\n" + " java.util.Arrays.<com.citahub.cita.abi.TypeReference<?>>asList(new com.citahub.cita.abi.TypeReference<com.citahub.cita.abi.datatypes.generated.Uint256>() {}, new com.citahub.cita.abi.TypeReference<com.citahub.cita.abi.datatypes.Utf8String>() {}));\n" + " com.citahub.cita.protocol.core.methods.request.AppFilter filter = new com.citahub.cita.protocol.core.methods.request.AppFilter(startBlock, endBlock, getContractAddress());\n" + " filter.addSingleTopic(com.citahub.cita.abi.EventEncoder.encode(event));\n" + " return citaj.appLogFlowable(filter).map(new io.reactivex.functions.Function<com.citahub.cita.protocol.core.methods.response.Log, TransferEventResponse>() {\n" + " @java.lang.Override\n" + " public TransferEventResponse apply(com.citahub.cita.protocol.core.methods.response.Log log) {\n" + " com.citahub.cita.abi.EventValues eventValues = extractEventParameters(event, log);\n" + " TransferEventResponse typedResponse = new TransferEventResponse();\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 static class TransferEventResponse {\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"; System.out.println("testBuildEventConstantMultipleValueReturn" + builder.build().toString()); assertThat(builder.build().toString(), is(expected)); }
void 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 NamedTypeName(namedType.getName(), buildTypeName(namedType.getType()))); } else { nonIndexedParameters.add( new NamedTypeName(namedType.getName(), buildTypeName(namedType.getType()))); } } classBuilder.addType(buildEventResponseObject(responseClassName, indexedParameters, nonIndexedParameters)); classBuilder.addMethod(buildEventTransactionReceiptFunction(responseClassName, functionName, indexedParameters, nonIndexedParameters)); classBuilder.addMethod(buildEventFlowableFunction(responseClassName, functionName, indexedParameters, nonIndexedParameters)); }
SolidityFunctionWrapper extends Generator { void 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 NamedTypeName(namedType.getName(), buildTypeName(namedType.getType()))); } else { nonIndexedParameters.add( new NamedTypeName(namedType.getName(), buildTypeName(namedType.getType()))); } } classBuilder.addType(buildEventResponseObject(responseClassName, indexedParameters, nonIndexedParameters)); classBuilder.addMethod(buildEventTransactionReceiptFunction(responseClassName, functionName, indexedParameters, nonIndexedParameters)); classBuilder.addMethod(buildEventFlowableFunction(responseClassName, functionName, indexedParameters, nonIndexedParameters)); } }
SolidityFunctionWrapper extends Generator { void 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 NamedTypeName(namedType.getName(), buildTypeName(namedType.getType()))); } else { nonIndexedParameters.add( new NamedTypeName(namedType.getName(), buildTypeName(namedType.getType()))); } } classBuilder.addType(buildEventResponseObject(responseClassName, indexedParameters, nonIndexedParameters)); classBuilder.addMethod(buildEventTransactionReceiptFunction(responseClassName, functionName, indexedParameters, nonIndexedParameters)); classBuilder.addMethod(buildEventFlowableFunction(responseClassName, functionName, indexedParameters, nonIndexedParameters)); } SolidityFunctionWrapper(boolean useNativeJavaTypes); }
SolidityFunctionWrapper extends Generator { void 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 NamedTypeName(namedType.getName(), buildTypeName(namedType.getType()))); } else { nonIndexedParameters.add( new NamedTypeName(namedType.getName(), buildTypeName(namedType.getType()))); } } classBuilder.addType(buildEventResponseObject(responseClassName, indexedParameters, nonIndexedParameters)); classBuilder.addMethod(buildEventTransactionReceiptFunction(responseClassName, functionName, indexedParameters, nonIndexedParameters)); classBuilder.addMethod(buildEventFlowableFunction(responseClassName, functionName, indexedParameters, nonIndexedParameters)); } SolidityFunctionWrapper(boolean useNativeJavaTypes); @SuppressWarnings("unchecked") void generateJavaFiles(
            String contractName, String bin, String abi, String destinationDir,
            String basePackageName); }
SolidityFunctionWrapper extends Generator { void 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 NamedTypeName(namedType.getName(), buildTypeName(namedType.getType()))); } else { nonIndexedParameters.add( new NamedTypeName(namedType.getName(), buildTypeName(namedType.getType()))); } } classBuilder.addType(buildEventResponseObject(responseClassName, indexedParameters, nonIndexedParameters)); classBuilder.addMethod(buildEventTransactionReceiptFunction(responseClassName, functionName, indexedParameters, nonIndexedParameters)); classBuilder.addMethod(buildEventFlowableFunction(responseClassName, functionName, indexedParameters, nonIndexedParameters)); } SolidityFunctionWrapper(boolean useNativeJavaTypes); @SuppressWarnings("unchecked") void generateJavaFiles(
            String contractName, String bin, String abi, String destinationDir,
            String basePackageName);  }