org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType Java Examples

The following examples show how to use org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType. 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 web3sdk with Apache License 2.0 6 votes vote down vote up
public static String getInputOutputFunctionName(
        AbiDefinition functionDefinition, boolean input, boolean isOverLoad) {
    if (!isOverLoad) {
        return functionDefinition.getName();
    }

    List<NamedType> nameTypes =
            (input ? functionDefinition.getInputs() : functionDefinition.getOutputs());

    String name = functionDefinition.getName();
    for (int i = 0; i < nameTypes.size(); i++) {
        AbiDefinition.NamedType.Type type =
                new AbiDefinition.NamedType.Type(nameTypes.get(i).getType());
        List<Integer> depths = type.getDepthArray();
        name += Strings.capitaliseFirstLetter(type.getBaseName());
        for (int j = 0; j < depths.size(); j++) {
            name += "Array";
            if (0 != depths.get(j)) {
                name += String.valueOf(depths.get(j));
            }
        }
    }

    return name;
}
 
Example #2
Source File: MethodUtils.java    From WeBASE-Collect-Bee with Apache License 2.0 6 votes vote down vote up
/**
 * Translate NamedType list to TypeReference<Type> list.
 * 
 * @param list
 * @return List<TypeReference<Type>>
 * @throws BaseException
 */
public static List<TypeReference<Type>> getMethodTypeReferenceList(List<NamedType> list) {
    List<TypeReference<Type>> referencesTypeList = Lists.newArrayList();
    for (NamedType type : list) {
        TypeReference reference;
        try {
            reference = TypeReferenceUtils.getTypeRef(type.getType().split(" ")[0]);
            log.debug("type: {} TypeReference converted: {}", type.getType(), JacksonUtils.toJson(reference));
            referencesTypeList.add(reference);
        } catch (BaseException e) {
            log.error("BaseException: ", e);
            return null;
        }
    }
    return referencesTypeList;
}
 
Example #3
Source File: SolidityFunctionWrapper.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
private String addParameters(List<AbiDefinition.NamedType> namedTypes) {

        List<ParameterSpec> inputParameterTypes = buildParameterTypes(namedTypes);

        List<ParameterSpec> nativeInputParameterTypes = new ArrayList<>(inputParameterTypes.size());
        for (ParameterSpec parameterSpec : inputParameterTypes) {
            TypeName typeName = getWrapperType(parameterSpec.type);
            nativeInputParameterTypes.add(
                    ParameterSpec.builder(typeName, parameterSpec.name).build());
        }

        if (useNativeJavaTypes) {
            return Collection.join(
                    namedTypes,
                    ", \n",
                    // this results in fully qualified names being generated
                    this::createMappedParameterTypes);
        } else {
            return Collection.join(inputParameterTypes, ", ", parameterSpec -> parameterSpec.name);
        }
    }
 
Example #4
Source File: SolidityFunctionWrapper.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
private String addParameters(
        MethodSpec.Builder methodBuilder, List<AbiDefinition.NamedType> namedTypes) {

    List<ParameterSpec> inputParameterTypes = buildParameterTypes(namedTypes);

    List<ParameterSpec> nativeInputParameterTypes = new ArrayList<>(inputParameterTypes.size());
    for (ParameterSpec parameterSpec : inputParameterTypes) {
        TypeName typeName = getWrapperType(parameterSpec.type);
        nativeInputParameterTypes.add(
                ParameterSpec.builder(typeName, parameterSpec.name).build());
    }

    methodBuilder.addParameters(nativeInputParameterTypes);

    if (useNativeJavaTypes) {
        return Collection.join(
                namedTypes,
                ", \n",
                // this results in fully qualified names being generated
                this::createMappedParameterTypes);
    } else {
        return Collection.join(inputParameterTypes, ", ", parameterSpec -> parameterSpec.name);
    }
}
 
Example #5
Source File: MethodParser.java    From WeBASE-Codegen-Monkey with Apache License 2.0 6 votes vote down vote up
public List<FieldVO> getOutputList(MethodMetaInfo method, List<NamedType> outputs) {
    if (CollectionUtils.isEmpty(outputs)) {
        return new ArrayList<FieldVO>();
    }
    List<FieldVO> list = Lists.newArrayListWithExpectedSize(outputs.size());
    for (int i = 0; i < outputs.size(); i++) {
        String javaName = "output" + (i + 1);
        String solType = outputs.get(i).getType();
        String length = PropertiesUtils.getGlobalProperty(ParserConstants.LENGTH, method.getContractName(),
                method.getName(), javaName, "0");
        String sqlName =
                systemEnvironmentConfig.getNamePrefix() + javaName + systemEnvironmentConfig.getNamePostfix();
        FieldVO vo = new FieldVO();
        vo.setJavaName(javaName).setJavaCapName(StringUtils.capitalize(javaName)).setSqlName(sqlName)
                .setSqlType(SolSqlTypeMappingUtils.fromSolBasicTypeToSqlType(solType)).setSolidityType(solType)
                .setJavaType(SolJavaTypeMappingUtils.fromSolBasicTypeToJavaType(solType))
                .setTypeMethod(SolTypeMethodMappingUtils.fromSolBasicTypeToTypeMethod(solType))
                .setLength(Integer.parseInt(length));
        list.add(vo);
    }
    return list;
}
 
Example #6
Source File: TransactionDecoder.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
/**
 * @param input
 * @param output
 * @return
 * @throws TransactionException
 * @throws BaseException
 */
public InputAndOutputResult decodeOutputReturnObject(String input, String output)
        throws TransactionException, BaseException {

    String updatedInput = addHexPrefixToString(input);
    String updatedOutput = addHexPrefixToString(output);

    // select abi
    AbiDefinition abiDefinition = selectAbiDefinition(updatedInput);
    // decode output
    List<NamedType> outputTypes = abiDefinition.getOutputs();
    List<TypeReference<?>> outputTypeReference = ContractAbiUtil.paramFormat(outputTypes);
    Function function = new Function(abiDefinition.getName(), null, outputTypeReference);
    List<Type> resultType =
            FunctionReturnDecoder.decode(updatedOutput, function.getOutputParameters());

    // set result to java bean
    List<ResultEntity> resultList = new ArrayList<>();
    for (int i = 0; i < outputTypes.size(); i++) {
        resultList.add(
                new ResultEntity(
                        outputTypes.get(i).getName(),
                        outputTypes.get(i).getType(),
                        resultType.get(i)));
    }
    String methodSign = decodeMethodSign(abiDefinition);

    return new InputAndOutputResult(
            methodSign, FunctionEncoder.buildMethodId(methodSign), resultList);
}
 
Example #7
Source File: TransactionDecoderTest.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
private static String decodeMethodSign(AbiDefinition abiDefinition) {
    List<NamedType> inputTypes = abiDefinition.getInputs();
    StringBuilder methodSign = new StringBuilder();
    methodSign.append(abiDefinition.getName());
    methodSign.append("(");
    String params =
            inputTypes.stream().map(NamedType::getType).collect(Collectors.joining(","));
    methodSign.append(params);
    methodSign.append(")");
    return methodSign.toString();
}
 
Example #8
Source File: SolidityFunctionWrapper.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
static List<TypeName> buildTypeNames(List<AbiDefinition.NamedType> namedTypes) {
    List<TypeName> result = new ArrayList<>(namedTypes.size());
    for (AbiDefinition.NamedType namedType : namedTypes) {
        result.add(buildTypeName(namedType.getType()));
    }
    return result;
}
 
Example #9
Source File: SolidityFunctionWrapper.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
static List<ParameterSpec> buildParameterTypes(List<AbiDefinition.NamedType> namedTypes) {
    List<ParameterSpec> result = new ArrayList<>(namedTypes.size());
    for (int i = 0; i < namedTypes.size(); i++) {
        AbiDefinition.NamedType namedType = namedTypes.get(i);

        String name = createValidParamName(namedType.getName(), i);
        String type = namedTypes.get(i).getType();
        namedType.setName(name);

        result.add(ParameterSpec.builder(buildTypeName(type), name).build());
    }
    return result;
}
 
Example #10
Source File: ContractAbiUtil.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
/**
 * @param paramTypes
 * @return
 * @throws BaseException
 */
public static List<TypeReference<?>> paramFormat(List<NamedType> paramTypes)
        throws BaseException {
    List<TypeReference<?>> finalOutputs = new ArrayList<>();

    for (int i = 0; i < paramTypes.size(); i++) {

        AbiDefinition.NamedType.Type type =
                new AbiDefinition.NamedType.Type(paramTypes.get(i).getType());
        // nested array , not support now.
        if (type.getDepth() > 1) {
            throw new BaseException(
                    201202,
                    String.format("type:%s unsupported array decoding", type.getName()));
        }

        TypeReference<?> typeReference = null;
        if (type.dynamicArray()) {
            typeReference =
                    DynamicArrayReference.create(
                            type.getBaseName(), paramTypes.get(i).isIndexed());
        } else if (type.staticArray()) {
            typeReference =
                    StaticArrayReference.create(
                            type.getBaseName(),
                            type.getDimensions(),
                            paramTypes.get(i).isIndexed());
        } else {
            typeReference =
                    TypeReference.create(
                            ContractTypeUtil.getType(paramTypes.get(i).getType()),
                            paramTypes.get(i).isIndexed());
        }

        finalOutputs.add(typeReference);
    }
    return finalOutputs;
}
 
Example #11
Source File: ContractAbiUtil.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
/**
 * @param abiDefinition
 * @return
 */
public static List<String> getFuncOutputType(AbiDefinition abiDefinition) {
    List<String> outputList = new ArrayList<>();
    List<NamedType> outputs = abiDefinition.getOutputs();
    for (NamedType output : outputs) {
        outputList.add(output.getType());
    }
    return outputList;
}
 
Example #12
Source File: ContractAbiUtil.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
/**
 * @param abiDefinition
 * @return
 */
public static List<String> getFuncInputType(AbiDefinition abiDefinition) {
    List<String> inputList = new ArrayList<>();
    if (abiDefinition != null) {
        List<NamedType> inputs = abiDefinition.getInputs();
        for (NamedType input : inputs) {
            inputList.add(input.getType());
        }
    }
    return inputList;
}
 
Example #13
Source File: TransactionDecoder.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
/**
 * @param abiDefinition
 * @return
 */
private String decodeMethodSign(AbiDefinition abiDefinition) {
    List<NamedType> inputTypes = abiDefinition.getInputs();
    StringBuilder methodSign = new StringBuilder();
    methodSign.append(abiDefinition.getName());
    methodSign.append("(");
    String params =
            inputTypes.stream().map(NamedType::getType).collect(Collectors.joining(","));
    methodSign.append(params);
    methodSign.append(")");
    return methodSign.toString();
}
 
Example #14
Source File: AbiUtil.java    From WeBASE-Front with Apache License 2.0 5 votes vote down vote up
/**
 * getFuncInputType.
 * 
 * @param abiDefinition abiDefinition
 * @return
 */
public static List<String> getFuncInputType(AbiDefinition abiDefinition) {
    List<String> inputList = new ArrayList<>();
    if (abiDefinition != null) {
        List<NamedType> inputs = abiDefinition.getInputs();
        for (NamedType input : inputs) {
            inputList.add(input.getType());
        }
    }
    return inputList;
}
 
Example #15
Source File: TransactionDecoder.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
/**
 * @param input
 * @return
 * @throws BaseException
 * @throws TransactionException
 */
public InputAndOutputResult decodeInputReturnObject(String input)
        throws BaseException, TransactionException {

    String updatedInput = addHexPrefixToString(input);

    // select abi
    AbiDefinition abiDefinition = selectAbiDefinition(updatedInput);

    // decode input
    List<NamedType> inputTypes = abiDefinition.getInputs();
    List<TypeReference<?>> inputTypeReferences = ContractAbiUtil.paramFormat(inputTypes);
    Function function = new Function(abiDefinition.getName(), null, inputTypeReferences);
    List<Type> resultType =
            FunctionReturnDecoder.decode(
                    updatedInput.substring(10), function.getOutputParameters());

    // set result to java bean
    List<ResultEntity> resultList = new ArrayList<ResultEntity>();
    for (int i = 0; i < inputTypes.size(); i++) {
        resultList.add(
                new ResultEntity(
                        inputTypes.get(i).getName(),
                        inputTypes.get(i).getType(),
                        resultType.get(i)));
    }
    String methodSign = decodeMethodSign(abiDefinition);

    return new InputAndOutputResult(
            methodSign, FunctionEncoder.buildMethodId(methodSign), resultList);
}
 
Example #16
Source File: MethodParserTest.java    From WeBASE-Codegen-Monkey with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testGetField() throws BaseException, ClassNotFoundException {
    String methodMetaInfoStr =
            "{\"contractName\":\"AccessRestriction\",\"name\":\"revokeUser\",\"shardingNO\":1,\"list\":null}";
    String inputsAddress = "[{\"name\":\"_user\",\"type\":\"address\",\"type0\":null,\"indexed\":false}]";
    String fieldList =
            "[{\"sqlName\":\"_user_\",\"solidityName\":\"_user\",\"javaName\":\"_user\",\"sqlType\":\"varchar(255)\",\"solidityType\":\"Address\",\"javaType\":\"String\",\"entityType\":null,\"typeMethod\":\"AddressUtils.bigIntegerToString\",\"javaCapName\":\"_user\",\"length\":0}]";
    MethodMetaInfo mmi = JacksonUtils.fromJson(methodMetaInfoStr, MethodMetaInfo.class);
    List<NamedType> nt = JacksonUtils.fromJson(inputsAddress, List.class, NamedType.class);
    List<FieldVO> list = methodParser.getFieldList(mmi, nt);
    
    String methodMetaInfoStaticArrayStr =
            "{\"contractName\":\"RecordData\",\"name\":\"insertRecord\",\"shardingNO\":1,\"list\":null}";
    String inputsStaticArray = "[{\"name\":\"record\",\"type\":\"bytes[]\",\"type0\":null,\"indexed\":false}]";
    String fieldList2 =
            "[{\"sqlName\":\"_record_\",\"solidityName\":\"record\",\"javaName\":\"record\",\"sqlType\":\"varchar(10240)\",\"solidityType\":\"DynamicArray<bytes>\",\"javaType\":\"String\",\"entityType\":null,\"typeMethod\":\"BytesUtils.dynamicBytesListObjectToString\",\"javaCapName\":\"Record\",\"length\":0}]";
    MethodMetaInfo mmi2 = JacksonUtils.fromJson(methodMetaInfoStaticArrayStr, MethodMetaInfo.class);
    List<NamedType> nt2 = JacksonUtils.fromJson(inputsStaticArray, List.class, NamedType.class);
    List<FieldVO> list2 = methodParser.getFieldList(mmi2, nt2);
    
    List<TypeReference<?>> listOfTypeReference = ContractAbiUtil.paramFormat(nt);
    System.out.println(JacksonUtils.toJson(listOfTypeReference));
    System.out.println(JacksonUtils.toJson(ContractAbiUtil.paramFormat(nt2)));
    
    for(NamedType n : nt2) {
       Type type = new Type(n.getType());
       System.out.println(JacksonUtils.toJson(type));
       TypeReference<?> tr = DynamicArrayReference.create(type.getBaseName(), n.isIndexed());
       System.out.println(tr.getClass().getSimpleName());
    }     
}
 
Example #17
Source File: MethodParser.java    From WeBASE-Codegen-Monkey with Apache License 2.0 5 votes vote down vote up
public List<MethodMetaInfo> parseToInfoList(Class<?> clazz) {
    AbiDefinition[] abiDefinitions = getContractAbiList(clazz);
    if (ArrayUtil.isEmpty(abiDefinitions)) {
        return null;
    }
    List<MethodMetaInfo> lists = Lists.newArrayList();
    for (AbiDefinition abiDefinition : abiDefinitions) {
        String abiType = abiDefinition.getType();
        if (abiType.equals(AbiTypeConstants.ABI_EVENT_TYPE) || abiDefinition.isConstant()) {
            continue;
        }
        List<NamedType> inputs = abiDefinition.getInputs();
        if (CollectionUtils.isEmpty(inputs) || StringUtils.isEmpty(inputs.get(0).getName())) {
            continue;
        }
        List<NamedType> outputs = abiDefinition.getOutputs();
        MethodMetaInfo method = new MethodMetaInfo();
        method.setType("method").setContractName(clazz.getSimpleName());
        log.debug("method name : {}", abiDefinition.getName());
        if (abiType.equals(AbiTypeConstants.ABI_CONSTRUCTOR_TYPE)) {
            method.setName(clazz.getSimpleName());
        } else {
            method.setName(abiDefinition.getName());
        }
        String generatedFlag = PropertiesUtils.getGlobalProperty(ParserConstants.MONITOR, method.getContractName(),
                method.getName(), "generated", "on");
        if (generatedFlag != null && generatedFlag.equalsIgnoreCase("off")) {
            continue;
        }
        int shardingNO = Integer.parseInt(PropertiesUtils.getGlobalProperty(ParserConstants.SYSTEM,
                method.getContractName(), method.getName(), ParserConstants.SHARDINGNO, "1"));
        method.setShardingNO(shardingNO).setList(getFieldList(method, inputs))
                .setOutputList(getOutputList(method, outputs));
        lists.add(method);
    }
    return lists;
}
 
Example #18
Source File: ContractParser.java    From WeBASE-Collect-Bee with Apache License 2.0 5 votes vote down vote up
/**
 * Translate all contract info of ContractMethodInfo's objects to methodIdMap, methodFiledsMap and
 * contractBinaryMap.
 * 
 * @param contractMethodInfos: contractMethodInfos contains methodIdMap, methodFiledsMap and contractBinaryMap.
 * @return ContractMapsInfo
 */
@Bean
public ContractMapsInfo transContractMethodInfo2ContractMapsInfo() {
    List<ContractMethodInfo> contractMethodInfos = initContractMethodInfo();
    ContractMapsInfo contractMapsInfo = new ContractMapsInfo();
    Map<String, NameValueVO<String>> methodIdMap = new HashMap<>();
    Map<String, List<NamedType>> methodFiledsMap = new HashMap<>();
    Map<String, List<NamedType>> outputMethodFiledsMap = new HashMap<>();
    Map<String, String> contractBinaryMap = new HashMap<>();
    for (ContractMethodInfo contractMethodInfo : contractMethodInfos) {
        contractBinaryMap.put(contractMethodInfo.getContractBinary(), contractMethodInfo.getContractName());
        for (MethodMetaInfo methodMetaInfo : contractMethodInfo.getMethodMetaInfos()) {
            NameValueVO<String> nameValue = new NameValueVO<>();
            nameValue.setName(contractMethodInfo.getContractName());
            nameValue.setValue(methodMetaInfo.getMethodName());
            methodIdMap.put(methodMetaInfo.getMethodId(), nameValue);
            methodFiledsMap.put(methodMetaInfo.getMethodName(), methodMetaInfo.getFieldsList());
            outputMethodFiledsMap.put(methodMetaInfo.getMethodName(), methodMetaInfo.getOutputFieldsList());
        }
    }
    log.info("Init sync block: find {} contract constructors.", contractBinaryMap.size());
    contractMapsInfo.setContractBinaryMap(contractBinaryMap);
    contractMapsInfo.setMethodFiledsMap(methodFiledsMap);
    contractMapsInfo.setOutputMethodFiledsMap(outputMethodFiledsMap);
    log.info("Init sync block: find {} contract methods.", methodIdMap.size());
    contractMapsInfo.setMethodIdMap(methodIdMap);
    return contractMapsInfo;
}
 
Example #19
Source File: MethodUtils.java    From WeBASE-Collect-Bee with Apache License 2.0 5 votes vote down vote up
/**
 * build contract method signature
 * 
 * @param methodName
 * @param parameters
 * @return String
 */
public static String buildMethodSignature(String methodName, List<NamedType> parameters) {
    StringBuilder result = new StringBuilder();
    result.append(methodName);
    result.append("(");
    String params = parameters.stream().map(NamedType::getType).collect(Collectors.joining(","));
    result.append(params);
    result.append(")");
    log.debug("methodName: {}, joint method paras: {}", methodName, result);
    return result.toString();
}
 
Example #20
Source File: ContractAbiUtil.java    From WeBASE-Transaction with Apache License 2.0 5 votes vote down vote up
/**
 * getFuncOutputType.
 * 
 * @param abiDefinition abiDefinition
 * @return
 */
public static List<String> getFuncOutputType(AbiDefinition abiDefinition) {
    List<String> outputList = new ArrayList<>();
    List<NamedType> outputs = abiDefinition.getOutputs();
    for (NamedType output : outputs) {
        outputList.add(output.getType());
    }
    return outputList;
}
 
Example #21
Source File: ContractAbiUtil.java    From WeBASE-Transaction with Apache License 2.0 5 votes vote down vote up
/**
 * getFuncInputType.
 * 
 * @param abiDefinition abiDefinition
 * @return
 */
public static List<String> getFuncInputType(AbiDefinition abiDefinition) {
    List<String> inputList = new ArrayList<>();
    if (abiDefinition != null) {
        List<NamedType> inputs = abiDefinition.getInputs();
        for (NamedType input : inputs) {
            inputList.add(input.getType());
        }
    }
    return inputList;
}
 
Example #22
Source File: AbiUtil.java    From WeBASE-Front with Apache License 2.0 5 votes vote down vote up
/**
 * getFuncOutputType.
 * 
 * @param abiDefinition abiDefinition
 * @return
 */
public static List<String> getFuncOutputType(AbiDefinition abiDefinition) {
    List<String> outputList = new ArrayList<>();
    List<NamedType> outputs = abiDefinition.getOutputs();
    for (NamedType output : outputs) {
        outputList.add(output.getType());
    }
    return outputList;
}
 
Example #23
Source File: ContractParser.java    From WeBASE-Collect-Bee with Apache License 2.0 4 votes vote down vote up
/**
 * Parsing single class object of contract java code file, and storage contract info into ContractMethodInfo object,
 * firstly, remove event function, query function and functions that param's null, compute methodId and save method
 * info into ContractMethodInfo object.
 * 
 * @param clazz: class object of contract java code file.
 * @return ContractMethodInfo
 */
public ContractMethodInfo parse(Class<?> clazz) {
    AbiDefinition[] abiDefinitions = MethodUtils.getContractAbiList(clazz);
    if (abiDefinitions == null || abiDefinitions.length == 0) {
        return null;
    }
    String className = clazz.getSimpleName();
    String binary = MethodUtils.getContractBinary(clazz);
    ContractMethodInfo contractMethodInfo = new ContractMethodInfo();
    contractMethodInfo.setContractName(className);
    contractMethodInfo.setContractBinary(binary);

    List<MethodMetaInfo> methodIdList = Lists.newArrayList();
    contractMethodInfo.setMethodMetaInfos(methodIdList);

    for (AbiDefinition abiDefinition : abiDefinitions) {
        String abiType = abiDefinition.getType();
        // remove event function and query function
        if (abiType.equals(AbiTypeConstants.ABI_EVENT_TYPE) || abiDefinition.isConstant()) {
            continue;
        }
        // remove functions that input'params is null
        List<NamedType> inputs = abiDefinition.getInputs();
        if (inputs == null || inputs.isEmpty()) {
            continue;
        }
        String methodName = abiDefinition.getName();
        if (abiType.equals(AbiTypeConstants.ABI_CONSTRUCTOR_TYPE)) {
            methodName = clazz.getSimpleName();
        }
        // compute method id by method name and method input's params.
        String methodId = FunctionEncoder.buildMethodId(MethodUtils.buildMethodSignature(methodName, inputs));
        log.debug("methodId {} , methodName {}", methodId, methodName);
        MethodMetaInfo metaInfo = new MethodMetaInfo();
        metaInfo.setMethodId(methodId);
        methodName = className + StringUtils.capitalize(methodName);
        metaInfo.setMethodName(methodName);
        metaInfo.setFieldsList(inputs);
        metaInfo.setOutputFieldsList(abiDefinition.getOutputs());
        methodIdList.add(metaInfo);
    }
    return contractMethodInfo;
}
 
Example #24
Source File: SolidityFunctionWrapper.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
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> parameters = new ArrayList<>();
    List<NamedTypeName> indexedParameters = new ArrayList<>();
    List<NamedTypeName> nonIndexedParameters = new ArrayList<>();

    for (AbiDefinition.NamedType namedType : inputs) {
        NamedTypeName parameter =
                new NamedTypeName(
                        namedType.getName(),
                        buildTypeName(namedType.getType()),
                        namedType.isIndexed());
        if (namedType.isIndexed()) {
            indexedParameters.add(parameter);
        } else {
            nonIndexedParameters.add(parameter);
        }
        parameters.add(parameter);
    }

    classBuilder.addField(createEventDefinition(functionName, parameters));

    classBuilder.addType(
            buildEventResponseObject(
                    responseClassName, indexedParameters, nonIndexedParameters));

    List<MethodSpec> methods = new ArrayList<>();
    methods.add(
            buildEventTransactionReceiptFunction(
                    responseClassName, functionName, indexedParameters, nonIndexedParameters));

    methods.add(buildRegisterEventLogPushFunction(functionName));
    methods.add(buildDefaultRegisterEventLogPushFunction(functionName));

    return methods;
}