Search in sources :

Example 1 with NamedType

use of org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType in project web3sdk by FISCO-BCOS.

the class SolidityFunctionWrapper method buildParameterTypes.

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;
}
Also used : NamedType(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType) ParameterSpec(com.squareup.javapoet.ParameterSpec) AbiDefinition(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition) ArrayList(java.util.ArrayList) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String)

Example 2 with NamedType

use of org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType in project web3sdk by FISCO-BCOS.

the class SolidityFunctionWrapper method getInputOutputFunctionName.

public static String getInputOutputFunctionName(AbiDefinition functionDefinition, boolean isOverLoad) {
    if (!isOverLoad) {
        return functionDefinition.getName();
    }
    List<NamedType> nameTypes = functionDefinition.getInputs();
    String name = functionDefinition.getName();
    for (int i = 0; i < nameTypes.size(); i++) {
        AbiDefinition.NamedType.Type type = new AbiDefinition.NamedType.Type(nameTypes.get(i).getType());
        name += Strings.capitaliseFirstLetter(type.getBaseName());
        List<Integer> depths = type.getDepthArray();
        for (int j = 0; j < depths.size(); j++) {
            name += "Array";
            if (0 != depths.get(j)) {
                name += String.valueOf(depths.get(j));
            }
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug(" name: {}, nameTypes: {}", name, nameTypes);
    }
    return name;
}
Also used : BigInteger(java.math.BigInteger) Type(org.fisco.bcos.web3j.abi.datatypes.Type) NamedType(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType) EncryptType(org.fisco.bcos.web3j.crypto.EncryptType) AbiDefinition(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition) NamedType(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String)

Example 3 with NamedType

use of org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType in project web3sdk by FISCO-BCOS.

the class SolidityFunctionWrapper method buildEventFunctions.

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;
}
Also used : NamedType(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType) AbiDefinition(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition) MethodSpec(com.squareup.javapoet.MethodSpec) NamedType(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType) ArrayList(java.util.ArrayList) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String)

Example 4 with NamedType

use of org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType in project web3sdk by FISCO-BCOS.

the class TransactionDecoderTest method decodeMethodSign.

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();
}
Also used : NamedType(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String)

Example 5 with NamedType

use of org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType in project web3sdk by FISCO-BCOS.

the class TransactionDecoder method decodeOutputReturnObject.

/**
 * @param input
 * @param output
 * @return
 * @throws BaseException
 */
public InputAndOutputResult decodeOutputReturnObject(String input, String output) throws 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);
}
Also used : NamedType(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType) ArrayList(java.util.ArrayList) Function(org.fisco.bcos.web3j.abi.datatypes.Function) CollectionType(com.fasterxml.jackson.databind.type.CollectionType) Type(org.fisco.bcos.web3j.abi.datatypes.Type) NamedType(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType) AbiDefinition(org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition) TypeReference(org.fisco.bcos.web3j.abi.TypeReference)

Aggregations

NamedType (org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType)10 AbiDefinition (org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition)8 ArrayList (java.util.ArrayList)7 Type (org.fisco.bcos.web3j.abi.datatypes.Type)6 Utf8String (org.fisco.bcos.web3j.abi.datatypes.Utf8String)5 CollectionType (com.fasterxml.jackson.databind.type.CollectionType)4 TypeReference (org.fisco.bcos.web3j.abi.TypeReference)4 Function (org.fisco.bcos.web3j.abi.datatypes.Function)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ParameterSpec (com.squareup.javapoet.ParameterSpec)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 EventEncoder (org.fisco.bcos.web3j.abi.EventEncoder)2 EventValues (org.fisco.bcos.web3j.abi.EventValues)2 FunctionEncoder (org.fisco.bcos.web3j.abi.FunctionEncoder)2