Java Code Examples for org.fisco.bcos.web3j.abi.TypeReference#create()

The following examples show how to use org.fisco.bcos.web3j.abi.TypeReference#create() . 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: AbiUtil.java    From WeBASE-Front with Apache License 2.0 6 votes vote down vote up
/**
 * output parameter format.
 * 
 * @param funOutputTypes list
 * @return
 */
public static List<TypeReference<?>> outputFormat(List<String> funOutputTypes)
        throws FrontException {
    List<TypeReference<?>> finalOutputs = new ArrayList<>();
    for (int i = 0; i < funOutputTypes.size(); i++) {
        Class<? extends Type> outputType = null;
        TypeReference<?> typeReference = null;
        if (funOutputTypes.get(i).contains("[")
                && funOutputTypes.get(i).contains("]")) {
            typeReference = ContractTypeUtil.getArrayType(
                    funOutputTypes.get(i).substring(0, funOutputTypes.get(i).indexOf("[")));
        } else {
            outputType = AbiTypes.getType(funOutputTypes.get(i));
            typeReference = TypeReference.create(outputType);
        }
        finalOutputs.add(typeReference);
    }
    return finalOutputs;
}
 
Example 2
Source File: ContractAbiUtil.java    From WeBASE-Transaction with Apache License 2.0 6 votes vote down vote up
/**
 * output parameter format.
 * 
 * @param funOutputTypes list
 * @return
 */
public static List<TypeReference<?>> outputFormat(List<String> funOutputTypes)
        throws BaseException {
    List<TypeReference<?>> finalOutputs = new ArrayList<>();
    for (int i = 0; i < funOutputTypes.size(); i++) {
        Class<? extends Type> outputType = null;
        TypeReference<?> typeReference = null;
        if (funOutputTypes.get(i).contains("[")
                && funOutputTypes.get(i).contains("]")) {
            typeReference = ContractTypeUtil.getArrayType(
                    funOutputTypes.get(i).substring(0, funOutputTypes.get(i).indexOf("[")));
        } else {
            outputType = ContractTypeUtil.getType(funOutputTypes.get(i));
            typeReference = TypeReference.create(outputType);
        }
        finalOutputs.add(typeReference);
    }
    return finalOutputs;
}
 
Example 3
Source File: TypeReferenceUtils.java    From WeBASE-Collect-Bee with Apache License 2.0 6 votes vote down vote up
public static TypeReference<?> getTypeRef(String solType) throws BaseException {
    AbiDefinition.NamedType.Type type = new AbiDefinition.NamedType.Type(solType);
    // 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(), false);
    } else if (type.staticArray()) {
        typeReference = StaticArrayReference.create(type.getBaseName(), type.getDimensions(), false);
    } else {
        typeReference = TypeReference.create(ContractTypeUtil.getType(solType), false);
    }
    return typeReference;
}
 
Example 4
Source File: TypeReferenceUtils.java    From WeBASE-Codegen-Monkey with Apache License 2.0 6 votes vote down vote up
public static TypeReference<?> getTypeRef(String solType) throws BaseException {
    AbiDefinition.NamedType.Type type = new AbiDefinition.NamedType.Type(solType);
    // 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(), false);
    } else if (type.staticArray()) {
        typeReference = StaticArrayReference.create(type.getBaseName(), type.getDimensions(), false);
    } else {
        typeReference = TypeReference.create(ContractTypeUtil.getType(solType), false);
    }
    return typeReference;
}
 
Example 5
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;
}