public static List<Type> readTx(String inputData, String abi, String methodName){
ABIUtils abiUtils = new ABIUtils();
try {
String abi4Json = abiUtils.getABI4Json(abi);
ArrayList<TypeReference<Type>> transfer = abiUtils.getInputTypeReferences(methodName, abi4Json);
return FunctionReturnDecoder.decode(inputData, transfer);
} catch (FileNotFoundException | JsonProcessingException | ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
public ArrayList<TypeReference<Type>> getInputTypeReferences(String methodName, String abi) throws ClassNotFoundException, JsonProcessingException {
ObjectMapper om = new ObjectMapper();
AbiDefinition[] abiDefinitions = om.readValue(abi, AbiDefinition[].class);
AbiDefinition function = Arrays.stream(abiDefinitions).filter(abiDefinition -> {
if (abiDefinition.getType().equals("function")) {
return abiDefinition.getName().equalsIgnoreCase(methodName);
}
return false;
}).findFirst().orElse(null);
ArrayList<TypeReference<Type>> functionsRef = new ArrayList<>();
for (AbiDefinition.NamedType namedType : function.getInputs()) {
String type = namedType.getType();
TypeReference typeReference = TypeReference.makeTypeReference(type);
functionsRef.add(typeReference);
}
return functionsRef;
}
how to use web3j geting inputparams ,this code ?Here I want to use abi to directly obtain the execution parameters of the contract, is there anything that needs to be changed
Here I want to use abi to directly obtain the execution parameters of the contract, is there anything that needs to be changed