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