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;
}
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;
}
Aggregations