org.web3j.utils.Files Java Examples

The following examples show how to use org.web3j.utils.Files. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KeyImporter.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
private void run(String input) {
    File keyFile = new File(input);

    if (keyFile.isFile()) {
        String privateKey = null;
        try {
            privateKey = Files.readString(keyFile);
        } catch (IOException e) {
            exitError("Unable to read file " + input);
        }

        createWalletFile(privateKey.trim());
    } else {
        createWalletFile(input.trim());
    }
}
 
Example #2
Source File: KeyImporter.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
private void run(String input) {
    File keyFile = new File(input);

    if (keyFile.isFile()) {
        String privateKey = null;
        try {
            privateKey = Files.readString(keyFile);
        } catch (IOException e) {
            exitError("Unable to read file " + input);
        }

        createWalletFile(privateKey.trim());
    } else {
        createWalletFile(input.trim());
    }
}
 
Example #3
Source File: SolidityFunctionWrapperGenerator.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
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(useJavaNativeTypes).generateJavaFiles(contractName, binary, abi, destinationDirLocation.toString(),
					basePackageName);
			System.out.println("File written to " + destinationDirLocation.toString() + "\n");
		}
	}
 
Example #4
Source File: WasmFunctionWrapperGenerator.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
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);
		String binary = Numeric.toHexString(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(getFileNameNoExtension(fileName));
		bytes = Files.readBytes(new File(absFile.toURI()));
		String abi = new String(bytes);

		List<WasmAbiDefinition> functionDefinitions = loadContractDefinition(absFile);

		if (functionDefinitions.isEmpty()) {
			exitError("Unable to parse input ABI file");
		} else {
			String className = Strings.capitaliseFirstLetter(contractName);

			System.out.println("Generating " + basePackageName + "." + className + " ... ");

			new WasmFunctionWrapper().generateJavaFiles(contractName, binary, abi, destinationDirLocation.toString(), basePackageName);

			System.out.println("File written to " + destinationDirLocation.toString() + "\n");
		}
	}
 
Example #5
Source File: SolidityFunctionWrapperGenerator.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
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(useJavaNativeTypes).generateJavaFiles(
                    contractName, binary, abi, destinationDirLocation.toString(), basePackageName);
            System.out.println("File written to " + destinationDirLocation.toString() + "\n");
        }
    }
 
Example #6
Source File: SolidityFunctionWrapperGenerator.java    From web3j with Apache License 2.0 5 votes vote down vote up
public final void generate() throws IOException, ClassNotFoundException {
    String binary = Contract.BIN_NOT_PROVIDED;
    if (binFile != null) {
        byte[] bytes = Files.readBytes(binFile);
        binary = new String(bytes);
    }
    List<AbiDefinition> functionDefinitions = loadContractDefinition(abiFile);

    if (functionDefinitions.isEmpty()) {
        exitError("Unable to parse input ABI file");
    } else {
        String className = Strings.capitaliseFirstLetter(contractName);
        System.out.print("Generating " + basePackageName + "." + className + " ... ");

        new SolidityFunctionWrapper(
                        useJavaNativeTypes,
                        useJavaPrimitiveTypes,
                        generateSendTxForCalls,
                        addressLength)
                .generateJavaFiles(
                        contractClass,
                        contractName,
                        binary,
                        functionDefinitions,
                        destinationDirLocation.toString(),
                        basePackageName,
                        null);

        System.out.println("File written to " + destinationDirLocation.toString() + "\n");
    }
}