Search in sources :

Example 1 with NumericType

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

the class ABIObject method newObject.

// clone itself
public ABIObject newObject() {
    ABIObject abiObject = new ABIObject(this.type);
    // value
    abiObject.setValueType(this.getValueType());
    abiObject.setName(this.getName());
    if (this.getNumericValue() != null) {
        abiObject.setNumericValue(new NumericType(this.getNumericValue().getTypeAsString(), this.getNumericValue().getValue()) {

            @Override
            public boolean dynamicType() {
                return false;
            }

            @Override
            public int offset() {
                return 1;
            }
        });
    }
    if (this.getBoolValue() != null) {
        abiObject.setBoolValue(new Bool(this.getBoolValue().getValue()));
    }
    if (this.getStringValue() != null) {
        abiObject.setStringValue(new Utf8String(this.getStringValue().getValue()));
    }
    if (this.getDynamicBytesValue() != null) {
        abiObject.setDynamicBytesValue(new DynamicBytes(this.getDynamicBytesValue().getValue()));
    }
    if (this.getAddressValue() != null) {
        abiObject.setAddressValue(new Address(this.getAddressValue().toUint160()));
    }
    if (this.getBytesValue() != null) {
        abiObject.setBytesValue(new Bytes(this.getBytesValue().getValue().length, this.getBytesValue().getValue()));
    }
    // list
    abiObject.setListType(this.getListType());
    abiObject.setListLength(this.getListLength());
    if (this.getListValueType() != null) {
        abiObject.setListValueType(this.getListValueType().newObject());
    }
    if (this.listValues != null) {
        for (ABIObject obj : this.listValues) {
            abiObject.listValues.add(obj.newObject());
        }
    }
    // tuple
    if (this.structFields != null) {
        for (ABIObject obj : this.structFields) {
            abiObject.structFields.add(obj.newObject());
        }
    }
    return abiObject;
}
Also used : NumericType(org.fisco.bcos.web3j.abi.datatypes.NumericType) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) DynamicBytes(org.fisco.bcos.web3j.abi.datatypes.DynamicBytes) Bytes(org.fisco.bcos.web3j.abi.datatypes.Bytes) DynamicBytes(org.fisco.bcos.web3j.abi.datatypes.DynamicBytes) Address(org.fisco.bcos.web3j.abi.datatypes.Address) Bool(org.fisco.bcos.web3j.abi.datatypes.Bool)

Example 2 with NumericType

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

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