Search in sources :

Example 1 with Type

use of org.fisco.bcos.web3j.abi.datatypes.Type 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 2 with Type

use of org.fisco.bcos.web3j.abi.datatypes.Type in project web3sdk by FISCO-BCOS.

the class FunctionReturnDecoder method build.

private static List<Type> build(String input, List<TypeReference<Type>> outputParameters) {
    List<Type> results = new ArrayList<>(outputParameters.size());
    int offset = 0;
    for (TypeReference<?> typeReference : outputParameters) {
        try {
            @SuppressWarnings("unchecked") Class<Type> cls = (Class<Type>) typeReference.getClassType();
            int hexStringDataOffset = getDataOffset(input, offset, typeReference.getType());
            Type result;
            if (DynamicArray.class.isAssignableFrom(cls)) {
                result = TypeDecoder.decodeDynamicArray(input, hexStringDataOffset, typeReference.getType());
            } else if (StaticArray.class.isAssignableFrom(cls)) {
                int length = Integer.parseInt(cls.getSimpleName().substring(StaticArray.class.getSimpleName().length()));
                result = TypeDecoder.decodeStaticArray(input, hexStringDataOffset, typeReference.getType(), length);
            } else {
                result = TypeDecoder.decode(input, hexStringDataOffset, cls);
            }
            results.add(result);
            offset += Utils.getOffset(typeReference.getType()) * TypeDecoder.MAX_BYTE_LENGTH_FOR_HEX_STRING;
        } catch (ClassNotFoundException e) {
            throw new UnsupportedOperationException("Invalid class reference provided", e);
        }
    }
    return results;
}
Also used : StaticArray(org.fisco.bcos.web3j.abi.datatypes.StaticArray) BytesType(org.fisco.bcos.web3j.abi.datatypes.BytesType) Type(org.fisco.bcos.web3j.abi.datatypes.Type) ArrayList(java.util.ArrayList)

Example 3 with Type

use of org.fisco.bcos.web3j.abi.datatypes.Type in project web3sdk by FISCO-BCOS.

the class TypeDecoder method decodeArrayElements.

@SuppressWarnings("rawtypes")
private static <T extends Type> T decodeArrayElements(String input, int offset, java.lang.reflect.Type type, int length, BiFunction<List<T>, String, T> consumer) {
    try {
        List<T> elements = new ArrayList<>(length);
        java.lang.reflect.Type[] types = ((ParameterizedType) type).getActualTypeArguments();
        Class<T> paraType = Utils.getClassType(types[0]);
        for (int i = 0; i < length; ++i) {
            int currEleOffset = offset + (i * MAX_BYTE_LENGTH_FOR_HEX_STRING * Utils.getOffset(types[0]));
            T t = null;
            if (Array.class.isAssignableFrom(paraType)) {
                // nest array
                int size = 0;
                if (StaticArray.class.isAssignableFrom(paraType)) {
                    size = Integer.parseInt(Utils.getClassType(types[0]).getSimpleName().substring(StaticArray.class.getSimpleName().length()));
                    t = decodeStaticArray(input, currEleOffset, types[0], size);
                } else {
                    int getOffset = TypeDecoder.decodeUintAsInt(input, currEleOffset) << 1;
                    t = decodeDynamicArray(input, offset + getOffset, types[0]);
                }
            } else {
                if (Utf8String.class.isAssignableFrom(paraType) || DynamicBytes.class.isAssignableFrom(paraType)) {
                    // dynamicType
                    int getOffset = TypeDecoder.decodeUintAsInt(input, currEleOffset) << 1;
                    t = decode(input, offset + getOffset, paraType);
                } else {
                    t = decode(input, currEleOffset, paraType);
                }
            }
            elements.add(t);
        }
        String typeName = Utils.getSimpleTypeName(paraType);
        return consumer.apply(elements, typeName);
    } catch (ClassNotFoundException e) {
        throw new UnsupportedOperationException("Unable to access parameterized type " + type.getTypeName(), e);
    }
}
Also used : ArrayList(java.util.ArrayList) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) Uint(org.fisco.bcos.web3j.abi.datatypes.Uint) ParameterizedType(java.lang.reflect.ParameterizedType) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) FixedPointType(org.fisco.bcos.web3j.abi.datatypes.FixedPointType) NumericType(org.fisco.bcos.web3j.abi.datatypes.NumericType) IntType(org.fisco.bcos.web3j.abi.datatypes.IntType) Type(org.fisco.bcos.web3j.abi.datatypes.Type) ParameterizedType(java.lang.reflect.ParameterizedType) DynamicBytes(org.fisco.bcos.web3j.abi.datatypes.DynamicBytes)

Example 4 with Type

use of org.fisco.bcos.web3j.abi.datatypes.Type in project web3sdk by FISCO-BCOS.

the class ChainGovernance method getFreezeAccountInput.

public Tuple1<String> getFreezeAccountInput(TransactionReceipt transactionReceipt) {
    String data = transactionReceipt.getInput().substring(10);
    final Function function = new Function(FUNC_FREEZEACCOUNT, Arrays.<Type>asList(), Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {
    }));
    List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
    ;
    return new Tuple1<String>((String) results.get(0).getValue());
}
Also used : Function(org.fisco.bcos.web3j.abi.datatypes.Function) Type(org.fisco.bcos.web3j.abi.datatypes.Type) Tuple1(org.fisco.bcos.web3j.tuples.generated.Tuple1) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) TypeReference(org.fisco.bcos.web3j.abi.TypeReference)

Example 5 with Type

use of org.fisco.bcos.web3j.abi.datatypes.Type in project web3sdk by FISCO-BCOS.

the class ChainGovernance method getGrantCommitteeMemberInput.

public Tuple1<String> getGrantCommitteeMemberInput(TransactionReceipt transactionReceipt) {
    String data = transactionReceipt.getInput().substring(10);
    final Function function = new Function(FUNC_GRANTCOMMITTEEMEMBER, Arrays.<Type>asList(), Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {
    }));
    List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
    ;
    return new Tuple1<String>((String) results.get(0).getValue());
}
Also used : Function(org.fisco.bcos.web3j.abi.datatypes.Function) Type(org.fisco.bcos.web3j.abi.datatypes.Type) Tuple1(org.fisco.bcos.web3j.tuples.generated.Tuple1) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) TypeReference(org.fisco.bcos.web3j.abi.TypeReference)

Aggregations

Type (org.fisco.bcos.web3j.abi.datatypes.Type)59 Utf8String (org.fisco.bcos.web3j.abi.datatypes.Utf8String)52 TypeReference (org.fisco.bcos.web3j.abi.TypeReference)46 Function (org.fisco.bcos.web3j.abi.datatypes.Function)42 Tuple1 (org.fisco.bcos.web3j.tuples.generated.Tuple1)26 DynamicBytes (org.fisco.bcos.web3j.abi.datatypes.DynamicBytes)16 NamedType (org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType)16 Bool (org.fisco.bcos.web3j.abi.datatypes.Bool)15 ArrayList (java.util.ArrayList)14 Address (org.fisco.bcos.web3j.abi.datatypes.Address)14 EncryptType (org.fisco.bcos.web3j.crypto.EncryptType)14 Int256 (org.fisco.bcos.web3j.abi.datatypes.generated.Int256)13 Bytes32 (org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32)11 Uint256 (org.fisco.bcos.web3j.abi.datatypes.generated.Uint256)11 Test (org.junit.Test)10 AbiDefinition (org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition)9 List (java.util.List)8 Tuple2 (org.fisco.bcos.web3j.tuples.generated.Tuple2)7 DynamicArray (org.fisco.bcos.web3j.abi.datatypes.DynamicArray)6 Event (org.fisco.bcos.web3j.abi.datatypes.Event)6