hyperledger-web3j / web3j

Lightweight Java and Android library for integration with Ethereum clients
https://www.web3labs.com/web3j-sdk
Other
5.1k stars 1.68k forks source link

Expose SolidityFunctionWrapperGenerator Methode for other libaries #86

Closed h2mch closed 7 years ago

h2mch commented 7 years ago

To make the workflow integrated from solidity code to the java classes, it would be nice, if we could use the methods inside the SolidityFunctionWrapperGenerator within other java library/application.

For that we should:

I did a first shoot in a separated fork. Now the question: Should I invest more time to make it ready for a merge request or if this feature nothing what you wan't in the web3j project.

conor10 commented 7 years ago

Hi @h2mch, I'd certainly like to see more integration between solidity and web3j. I don't think it would be appropriate to distributed the Solidity binaries with web3j. However, I'd certainly be interested in exploring this further.

Where is the fork you've started work on? Happy to take a look to understand your thinking more.

h2mch commented 7 years ago

First, I have extracted the generating logic out of the console application. with this step an other library can use the java code generator. see https://github.com/web3j/web3j/pull/88

h2mch commented 7 years ago

With this change a maven plugin or another library can make use of the create java code generating function inside web3j. Example:

String contractName = "HelloWorld";
byte[] contract = Files.readAllBytes(Paths.get("../contracts/HelloWorld.sol"));
SolidityCompiler.Result result = solidityCompiler.compileSrc(
    contract,
    true,
    true,
    SolidityCompiler.Options.ABI,
    SolidityCompiler.Options.BIN,
    SolidityCompiler.Options.METADATA);

CompilationResult parse = CompilationResult.parse(result.output);

String bin = parse.contracts.get(contractName).bin;
String abi = parse.contracts.get(contractName).abi;
String destinationDirLocation = "src/main/java";
String basePackageName = "ch.h2m.blockchain.model";

new SolidityFunctionWrapper().generateJavaFiles(contractName, bin, abi, destinationDirLocation, basePackageName);
conor10 commented 7 years ago

Fixed with https://github.com/web3j/web3j/pull/88.