Skip to content

Commit

Permalink
added new template based on version.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandrouR committed Dec 9, 2019
1 parent 12687bc commit b0b4b6a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ apply {
download {
src "https://raw.githubusercontent.com/web3j/build-tools/master/gradle/$buildScript/build.gradle"
dest "$rootDir/gradle/$buildScript/build.gradle"
overwrite true
overwrite false
quiet true
onlyIfModified true
}
Expand Down
1 change: 1 addition & 0 deletions gradle/repositories/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
repositories {
mavenLocal()
mavenCentral()
jcenter()
maven { url 'https://oss.sonatype.org/content/repositories/releases/' }
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/org/web3j/console/project/ProjectCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
import java.util.List;
import java.util.Optional;

<<<<<<< HEAD
=======
import picocli.CommandLine;

import org.web3j.commons.JavaVersion;
import org.web3j.console.project.utills.InputVerifier;
>>>>>>> added new template based on version.
import org.web3j.console.project.utills.ProjectUtils;
import org.web3j.crypto.CipherException;
import org.web3j.crypto.WalletUtils;
Expand Down Expand Up @@ -48,12 +55,14 @@ public class ProjectCreator {
final String walletName =
WalletUtils.generateNewWalletFile(
walletPassword, new File(projectStructure.getWalletPath()));

this.templateProvider =
new TemplateProvider.Builder()
.loadGradlewBatScript("gradlew.bat.template")
.loadGradlewScript("gradlew.template")
.loadMainJavaClass("Template.java")
.loadMainJavaClass(
JavaVersion.getJavaVersionAsDouble() < 11
? "Template.java"
: "TemplateJava11.java")
.loadGradleBuild("build.gradle.template")
.loadGradleSettings("settings.gradle.template")
.loadGradlewWrapperSettings("gradlew-wrapper.properties.template")
Expand Down
18 changes: 7 additions & 11 deletions src/main/resources/Template.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
import org.web3j.crypto.CipherException;
import org.web3j.crypto.Credentials;
import org.web3j.crypto.WalletUtils;
import org.web3j.evm.Configuration;
import org.web3j.evm.EmbeddedWeb3jService;
import org.web3j.evm.PassthroughTracer;
import org.web3j.protocol.Web3j;
import org.web3j.tx.gas.ContractGasProvider;
import org.web3j.tx.gas.DefaultGasProvider;
import org.web3j.protocol.http.HttpService;


import java.io.File;
import java.io.IOException;
Expand All @@ -25,8 +24,7 @@ public class <project_name> {

public static void main(String[]args) throws Exception {
Credentials credentials=loadCredentials("<wallet_name>","<wallet_password_placeholder>");
Configuration configuration=fundAccount(credentials);
Web3j web3j=createWeb3jService(configuration);
Web3j web3j=createWeb3jService("URL_TO_INFURA");
HelloWorld helloWorld = deployHelloWorld(web3j,credentials,new DefaultGasProvider());
callGreetMethod(helloWorld);
}
Expand All @@ -41,18 +39,16 @@ private static Credentials loadCredentials(String walletName,String walletPasswo
return WalletUtils.loadCredentials(walletPassword,file);
}

private static Configuration fundAccount(Credentials credentials){
private static void fundAccount(Credentials credentials){
// Use the Web3j CLI fund command to obtain testnet Ether
// See <Link to docs here>
log.info("Funding address "+credentials.getAddress()+" with "+10+" ether.");
return new Configuration(new Address(credentials.getAddress()),10);

}

private static Web3j createWeb3jService(Configuration configuration){
// To run against a real Ethereum node use HttpService instead of EmbeddedWeb3jService and pass in the URL of your node.
log.info("Creating a web3j service locally with EmbeddedWeb3jService.");
return Web3j.build(new EmbeddedWeb3jService(configuration,new PassthroughTracer()));
private static Web3j createWeb3jService(String url){
log.info("Connecting to " + url);
return Web3j.build(new HttpService(url));
}

private static HelloWorld deployHelloWorld(Web3j web3j,Credentials credentials,ContractGasProvider contractGasProvider)throws Exception{
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/web3j/console/project/ProjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public void fileCreationTest() {
.exists();
final boolean gradleWrapperSettings =
new File(
projectStructure.getWrapperPath()
+ File.separator
+ "gradle-wrapper.properties")
projectStructure.getWrapperPath()
+ File.separator
+ "gradle-wrapper.properties")
.exists();
final boolean gradleWrapperJar =
new File(projectStructure.getWrapperPath() + File.separator + "gradle-wrapper.jar")
Expand Down

0 comments on commit b0b4b6a

Please sign in to comment.