Search in sources :

Example 41 with Type

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

the class TypeDecoder method decodeDynamicArray.

@SuppressWarnings("unchecked")
public static <T extends Type> T decodeDynamicArray(String input, int offset, java.lang.reflect.Type type) {
    int length = decodeUintAsInt(input, offset);
    BiFunction<List<T>, String, T> function = (elements, typeName) -> {
        if (elements.isEmpty()) {
            return (T) DynamicArray.empty(typeName);
        } else {
            return (T) new DynamicArray<>(elements);
        }
    };
    int valueOffset = offset + MAX_BYTE_LENGTH_FOR_HEX_STRING;
    return decodeArrayElements(input, valueOffset, type, length, function);
}
Also used : Uint160(org.fisco.bcos.web3j.abi.datatypes.generated.Uint160) DynamicBytes(org.fisco.bcos.web3j.abi.datatypes.DynamicBytes) Fixed(org.fisco.bcos.web3j.abi.datatypes.Fixed) BiFunction(java.util.function.BiFunction) Bool(org.fisco.bcos.web3j.abi.datatypes.Bool) StaticArray(org.fisco.bcos.web3j.abi.datatypes.StaticArray) Ufixed(org.fisco.bcos.web3j.abi.datatypes.Ufixed) ArrayList(java.util.ArrayList) FixedPointType(org.fisco.bcos.web3j.abi.datatypes.FixedPointType) Array(org.fisco.bcos.web3j.abi.datatypes.Array) Uint(org.fisco.bcos.web3j.abi.datatypes.Uint) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) BigInteger(java.math.BigInteger) Address(org.fisco.bcos.web3j.abi.datatypes.Address) DynamicArray(org.fisco.bcos.web3j.abi.datatypes.DynamicArray) Numeric(org.fisco.bcos.web3j.utils.Numeric) NumericType(org.fisco.bcos.web3j.abi.datatypes.NumericType) IntType(org.fisco.bcos.web3j.abi.datatypes.IntType) StandardCharsets(java.nio.charset.StandardCharsets) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) Type(org.fisco.bcos.web3j.abi.datatypes.Type) ParameterizedType(java.lang.reflect.ParameterizedType) Int(org.fisco.bcos.web3j.abi.datatypes.Int) Bytes(org.fisco.bcos.web3j.abi.datatypes.Bytes) DynamicArray(org.fisco.bcos.web3j.abi.datatypes.DynamicArray) ArrayList(java.util.ArrayList) List(java.util.List) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) Uint(org.fisco.bcos.web3j.abi.datatypes.Uint)

Example 42 with Type

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

the class Utils method getOffset.

public static <T extends Type> int getOffset(java.lang.reflect.Type type) throws ClassNotFoundException {
    if (Utils.dynamicType(type)) {
        return 1;
    }
    Class<T> cls = Utils.getClassType(type);
    if (StaticArray.class.isAssignableFrom(cls)) {
        int length = Integer.parseInt(cls.getSimpleName().substring(StaticArray.class.getSimpleName().length()));
        java.lang.reflect.Type[] types = ((ParameterizedType) type).getActualTypeArguments();
        return getOffset(types[0]) * length;
    } else {
        return 1;
    }
}
Also used : StaticArray(org.fisco.bcos.web3j.abi.datatypes.StaticArray) ParameterizedType(java.lang.reflect.ParameterizedType) Type(org.fisco.bcos.web3j.abi.datatypes.Type) ParameterizedType(java.lang.reflect.ParameterizedType) Uint(org.fisco.bcos.web3j.abi.datatypes.Uint)

Example 43 with Type

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

the class ChainGovernance method getUpdateCommitteeMemberWeightOutput.

public Tuple1<BigInteger> getUpdateCommitteeMemberWeightOutput(TransactionReceipt transactionReceipt) {
    String data = transactionReceipt.getOutput();
    final Function function = new Function(FUNC_UPDATECOMMITTEEMEMBERWEIGHT, Arrays.<Type>asList(), Arrays.<TypeReference<?>>asList(new TypeReference<Int256>() {
    }));
    List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
    ;
    return new Tuple1<BigInteger>((BigInteger) 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 44 with Type

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

the class ChainGovernance method getRevokeOperatorInput.

public Tuple1<String> getRevokeOperatorInput(TransactionReceipt transactionReceipt) {
    String data = transactionReceipt.getInput().substring(10);
    final Function function = new Function(FUNC_REVOKEOPERATOR, 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 45 with Type

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

the class ChainGovernance method getGrantCommitteeMemberOutput.

public Tuple1<BigInteger> getGrantCommitteeMemberOutput(TransactionReceipt transactionReceipt) {
    String data = transactionReceipt.getOutput();
    final Function function = new Function(FUNC_GRANTCOMMITTEEMEMBER, Arrays.<Type>asList(), Arrays.<TypeReference<?>>asList(new TypeReference<Int256>() {
    }));
    List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
    ;
    return new Tuple1<BigInteger>((BigInteger) 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