Java Code Examples for org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition#getOutputs()

The following examples show how to use org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition#getOutputs() . 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: 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 3
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 4
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 5
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 6
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;
}