use of org.bcos.web3j.protocol.core.methods.response.AbiDefinition in project web3sdk by FISCO-BCOS.
the class SolidityFunctionWrapper method buildFunctionDefinitions.
private static List<MethodSpec> buildFunctionDefinitions(String className, TypeSpec.Builder classBuilder, List<AbiDefinition> functionDefinitions) throws ClassNotFoundException {
List<MethodSpec> methodSpecs = new ArrayList<>();
boolean constructor = false;
for (AbiDefinition functionDefinition : functionDefinitions) {
if (functionDefinition.getType().equals("function")) {
methodSpecs.add(buildFunction(functionDefinition));
// 添加带有callback的方法
if (!functionDefinition.isConstant()) {
methodSpecs.add(buildFunctionWithCallback(functionDefinition));
}
} else if (functionDefinition.getType().equals("event")) {
buildEventFunctions(functionDefinition, classBuilder);
} else if (functionDefinition.getType().equals("constructor")) {
constructor = true;
methodSpecs.add(buildDeploy(className, functionDefinition, Credentials.class, CREDENTIALS));
methodSpecs.add(buildDeploy(className, functionDefinition, TransactionManager.class, TRANSACTION_MANAGER));
}
}
// constructor will not be specified in ABI file if its empty
if (!constructor) {
MethodSpec.Builder credentialsMethodBuilder = getDeployMethodSpec(className, Credentials.class, CREDENTIALS);
methodSpecs.add(buildDeployAsyncNoParams(credentialsMethodBuilder, className, CREDENTIALS));
MethodSpec.Builder transactionManagerMethodBuilder = getDeployMethodSpec(className, TransactionManager.class, TRANSACTION_MANAGER);
methodSpecs.add(buildDeployAsyncNoParams(transactionManagerMethodBuilder, className, TRANSACTION_MANAGER));
}
return methodSpecs;
}
use of org.bcos.web3j.protocol.core.methods.response.AbiDefinition in project web3sdk by FISCO-BCOS.
the class SolidityFunctionWrapper method loadContractDefinition.
private List<AbiDefinition> loadContractDefinition(String abi) throws IOException {
ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
AbiDefinition[] abiDefinition = objectMapper.readValue(abi, AbiDefinition[].class);
return Arrays.asList(abiDefinition);
}
use of org.bcos.web3j.protocol.core.methods.response.AbiDefinition in project web3sdk by FISCO-BCOS.
the class SolidityFunctionWrapperGenerator method generate.
private void generate() throws IOException, ClassNotFoundException {
File binaryFile = new File(binaryFileLocation);
if (!binaryFile.exists()) {
exitError("Invalid input binary file specified: " + binaryFileLocation);
}
byte[] bytes = Files.readBytes(new File(binaryFile.toURI()));
String binary = new String(bytes);
File absFile = new File(absFileLocation);
if (!absFile.exists() || !absFile.canRead()) {
exitError("Invalid input ABI file specified: " + absFileLocation);
}
String fileName = absFile.getName();
String contractName = getFileNameNoExtension(fileName);
bytes = Files.readBytes(new File(absFile.toURI()));
String abi = new String(bytes);
List<AbiDefinition> functionDefinitions = loadContractDefinition(absFile);
if (functionDefinitions.isEmpty()) {
exitError("Unable to parse input ABI file");
} else {
String className = Strings.capitaliseFirstLetter(contractName);
System.out.printf("Generating " + basePackageName + "." + className + " ... ");
new SolidityFunctionWrapper().generateJavaFiles(contractName, binary, abi, destinationDirLocation.toString(), basePackageName);
System.out.println("File written to " + destinationDirLocation.toString() + "\n");
}
}
use of org.bcos.web3j.protocol.core.methods.response.AbiDefinition in project web3sdk by FISCO-BCOS.
the class SolidityFunctionWrapperGenerator method loadContractDefinition.
private static List<AbiDefinition> loadContractDefinition(File absFile) throws IOException {
ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
AbiDefinition[] abiDefinition = objectMapper.readValue(absFile, AbiDefinition[].class);
return Arrays.asList(abiDefinition);
}
Aggregations