Skip to content

Commit

Permalink
Change NODE_URL to variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandrouR committed Dec 18, 2019
1 parent d9601ea commit f9c3013
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/main/resources/Template.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class <project_name> {

private static final Logger log=LoggerFactory.getLogger(<project_name>.class);

private static final String NODE_URL = "NODE_URL";

public static void main(String[]args) throws Exception{
try {
Expand All @@ -45,20 +45,22 @@ private static Credentials loadCredentials(String walletName) throws IOException
}

private static Web3j createWeb3jService(String url){
final String nodeURLProperty = System.getProperty(NODE_URL);
final String nodeURLEnv = System.getenv(NODE_URL);
if (url == null || url.isEmpty()) {
if (System.getProperty("NODE_URL") == null || System.getProperty("NODE_URL").isEmpty()) {
if (System.getenv("NODE_URL") == null || System.getenv("NODE_URL").isEmpty()) {
if (nodeURLProperty == null || nodeURLProperty.isEmpty()) {
if (nodeURLEnv == null || nodeURLEnv.isEmpty()) {
log.info("Please make sure the node url is valid.");
log.info("You can edit the node url programmatically, use java -DNODE_URL=\"\" or as an environmental variable e.g export NODE_URL=\"\"");
log.info("You can edit the node url programmatically, use java -D"+NODE_URL+"=\"\" or as an environmental variable e.g export "+NODE_URL+"=\"\"");
System.exit(1);
} else {
log.info("Connecting to " + System.getenv("NODE_URL"));
return Web3j.build(new HttpService(System.getenv("NODE_URL")));
log.info("Connecting to " + nodeURLEnv);
return Web3j.build(new HttpService(nodeURLEnv));
}
}
else {
log.info("Connecting to " + System.getProperty("NODE_URL"));
return Web3j.build(new HttpService(System.getProperty("NODE_URL")));
log.info("Connecting to " + nodeURLProperty);
return Web3j.build(new HttpService(nodeURLProperty));
}
}
log.info("Connecting to " + url);
Expand Down

0 comments on commit f9c3013

Please sign in to comment.