Search in sources :

Example 1 with Array

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

the class ResultEntity method typeToObject.

public static Object typeToObject(Type type) {
    Object obj = null;
    if (type instanceof NumericType) {
        // uint int
        obj = ((NumericType) type).getValue();
    } else if (type instanceof Bool) {
        // bool
        obj = ((Bool) type).getValue();
    } else if (type instanceof Address) {
        // address
        obj = type.toString();
    } else if (type instanceof Bytes) {
        // bytes32
        obj = new String(((Bytes) type).getValue()).trim();
    } else if (type instanceof DynamicBytes) {
        // bytes
        obj = new String(((DynamicBytes) type).getValue()).trim();
    } else if (type instanceof Utf8String) {
        // string
        obj = ((Utf8String) type).getValue();
    } else if (type instanceof Array) {
        // T[] T[k]
        List<Object> r = new ArrayList<Object>();
        List l = ((Array) type).getValue();
        for (int i = 0; i < l.size(); ++i) {
            r.add(typeToObject((Type) l.get(i)));
        }
        obj = (Object) r;
    } else {
        obj = (Object) obj;
    }
    return obj;
}
Also used : NumericType(org.fisco.bcos.web3j.abi.datatypes.NumericType) Address(org.fisco.bcos.web3j.abi.datatypes.Address) ArrayList(java.util.ArrayList) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) Array(org.fisco.bcos.web3j.abi.datatypes.Array) DynamicBytes(org.fisco.bcos.web3j.abi.datatypes.DynamicBytes) Bytes(org.fisco.bcos.web3j.abi.datatypes.Bytes) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) DynamicBytes(org.fisco.bcos.web3j.abi.datatypes.DynamicBytes) NumericType(org.fisco.bcos.web3j.abi.datatypes.NumericType) Type(org.fisco.bcos.web3j.abi.datatypes.Type) Bool(org.fisco.bcos.web3j.abi.datatypes.Bool) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Address (org.fisco.bcos.web3j.abi.datatypes.Address)1 Array (org.fisco.bcos.web3j.abi.datatypes.Array)1 Bool (org.fisco.bcos.web3j.abi.datatypes.Bool)1 Bytes (org.fisco.bcos.web3j.abi.datatypes.Bytes)1 DynamicBytes (org.fisco.bcos.web3j.abi.datatypes.DynamicBytes)1 NumericType (org.fisco.bcos.web3j.abi.datatypes.NumericType)1 Type (org.fisco.bcos.web3j.abi.datatypes.Type)1 Utf8String (org.fisco.bcos.web3j.abi.datatypes.Utf8String)1