Skip to content

Commit

Permalink
Use typesafe:config for configuration. Moved system.properties -> eth…
Browse files Browse the repository at this point in the history
…ereumj.conf
  • Loading branch information
Nashatyrev committed Jul 14, 2015
1 parent 980672f commit 1bc5d6c
Show file tree
Hide file tree
Showing 12 changed files with 590 additions and 425 deletions.
1 change: 1 addition & 0 deletions ethereumj-core/build.gradle
Expand Up @@ -111,6 +111,7 @@ dependencies {
compile "commons-dbcp:commons-dbcp:1.4"
compile "redis.clients:jedis:2.6.0"
compile "com.h2database:h2:1.4.187"
compile "com.typesafe:config:1.2.1"

// compile "org.mapdb:mapdb:1.0.7"
compile "org.mapdb:mapdb:2.0-beta1"
Expand Down
15 changes: 9 additions & 6 deletions ethereumj-core/src/main/java/org/ethereum/Start.java
@@ -1,9 +1,10 @@
package org.ethereum;

import org.ethereum.cli.CLIInterface;
import org.ethereum.config.SystemProperties;
import org.ethereum.facade.Ethereum;
import org.ethereum.facade.EthereumFactory;
import org.ethereum.net.rlpx.Node;
import org.spongycastle.util.encoders.Hex;

import java.io.IOException;
import java.net.URISyntaxException;
Expand All @@ -20,13 +21,15 @@ public static void main(String args[]) throws IOException, URISyntaxException {
CLIInterface.call(args);
Ethereum ethereum = EthereumFactory.createEthereum();

if (CONFIG.blocksLoader().equals(""))
if (CONFIG.blocksLoader().equals("")) {
Node node = CONFIG.peerActive().get(0);
ethereum.connect(
CONFIG.activePeerIP(),
CONFIG.activePeerPort(),
CONFIG.activePeerNodeid());
else
node.getHost(),
node.getPort(),
Hex.toHexString(node.getId()));
} else {
ethereum.getBlockLoader().loadBlocks();
}
}

}
22 changes: 12 additions & 10 deletions ethereumj-core/src/main/java/org/ethereum/cli/CLIInterface.java
@@ -1,12 +1,13 @@
package org.ethereum.cli;

import org.ethereum.config.SystemProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.net.URI;

import static org.ethereum.config.SystemProperties.CONFIG;
import java.util.HashMap;
import java.util.Map;

/**
* @author Roman Mandeleil
Expand All @@ -21,6 +22,7 @@ public class CLIInterface {
public static void call(String[] args) {

try {
Map<String, String> cliOptions = new HashMap<>();
for (int i = 0; i < args.length; ++i) {

// override the db directory
Expand All @@ -34,14 +36,14 @@ public static void call(String[] args) {
if (args[i].equals("-db") && i + 1 < args.length) {
String db = args[i + 1];
logger.info("DB directory set to [{}]", db);
CONFIG.setDataBaseDir(db);
cliOptions.put(SystemProperties.PROPERTY_DB_DIR, db);
}

// override the listen port directory
if (args[i].equals("-listen") && i + 1 < args.length) {
String port = args[i + 1];
logger.info("Listen port set to [{}]", port);
CONFIG.setListenPort(Integer.valueOf(port));
cliOptions.put(SystemProperties.PROPERTY_LISTEN_PORT, port);
}

// override the connect host:port directory
Expand All @@ -51,20 +53,20 @@ public static void call(String[] args) {
URI uri = new URI(connectStr);
if (!uri.getScheme().equals("enode"))
throw new RuntimeException("expecting URL in the format enode://PUBKEY@HOST:PORT");

CONFIG.setActivePeerIP(uri.getHost());
CONFIG.setActivePeerPort(uri.getPort());
CONFIG.setActivePeerNodeid(uri.getUserInfo());
cliOptions.put(SystemProperties.PROPERTY_PEER_ACTIVE, "[{url='" + connectStr + "'}]");
}

// override the listen port directory
if (args[i].equals("-reset") && i + 1 < args.length) {
Boolean resetStr = interpret(args[i + 1]);
logger.info("Resetting db set to [{}]", resetStr);
CONFIG.setDatabaseReset(resetStr);
cliOptions.put(SystemProperties.PROPERTY_DB_RESET, resetStr.toString());
}
}
logger.info("");

logger.info("Overriding config file with CLI options: " + cliOptions);
SystemProperties.CONFIG.overrideParams(cliOptions);

} catch (Throwable e) {
logger.error("Error parsing command line: [{}]", e.getMessage());
System.exit(1);
Expand Down

0 comments on commit 1bc5d6c

Please sign in to comment.