Skip to content

Commit

Permalink
Merge branch 'develop' into feature/db-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalinin committed Mar 16, 2018
2 parents c81deba + 5843205 commit 06c9798
Show file tree
Hide file tree
Showing 60 changed files with 1,709 additions and 3,186 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@


# About
ethereumj is a pure-Java implementation of the Ethereum protocol. For high-level information about Ethereum and its goals, visit [ethereum.org](https://ethereum.org). The [ethereum white paper](https://github.com/ethereum/wiki/wiki/White-Paper) provides a complete conceptual overview, and the [yellow paper](http://gavwood.com/Paper.pdf) provides a formal definition of the protocol.
EthereumJ is a pure-Java implementation of the Ethereum protocol. For high-level information about Ethereum and its goals, visit [ethereum.org](https://ethereum.org). The [ethereum white paper](https://github.com/ethereum/wiki/wiki/White-Paper) provides a complete conceptual overview, and the [yellow paper](http://gavwood.com/Paper.pdf) provides a formal definition of the protocol.

We keep EthereumJ as thin as possible. For [JSON-RPC](https://github.com/ethereum/wiki/wiki/JSON-RPC) support and other client features check [Ethereum Harmony](https://github.com/ether-camp/ethereum-harmony).

# Running EthereumJ

Expand All @@ -17,7 +19,7 @@ ethereumj is a pure-Java implementation of the Ethereum protocol. For high-level
<dependency>
<groupId>org.ethereum</groupId>
<artifactId>ethereumj-core</artifactId>
<version>1.5.0-RELEASE</version>
<version>1.6.3-RELEASE</version>
</dependency>
```

Expand All @@ -26,8 +28,10 @@ ethereumj is a pure-Java implementation of the Ethereum protocol. For high-level
```
repositories {
mavenCentral()
jcenter()
maven { url "https://dl.bintray.com/ethereum/maven/" }
}
compile "org.ethereum:ethereumj-core:1.5.+"
compile "org.ethereum:ethereumj-core:1.6.+"
```

As a starting point for your own project take a look at https://github.com/ether-camp/ethereumj.starter
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
wrapper.gradleVersion = '2.14.1'
wrapper.gradleVersion = '3.5.1'

allprojects {
apply plugin: 'eclipse'
Expand Down
4 changes: 2 additions & 2 deletions ethereumj-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ buildscript {
plugins {
id 'application'
id 'jacoco'
id 'com.github.johnrengelman.shadow' version '1.2.3'
id 'com.github.johnrengelman.shadow' version '2.0.1'
id 'com.github.kt3k.coveralls' version '2.6.3'
id 'com.jfrog.bintray' version '1.0'
}
Expand Down Expand Up @@ -119,7 +119,7 @@ dependencies {

compile "org.ethereum:rocksdbjni:5.9.2" // RocksDB Java API

compile "org.ethereum:solcJ-all:0.4.8" // Solidity Compiler win/mac/linux binaries
compile "org.ethereum:solcJ-all:0.4.19" // Solidity Compiler win/mac/linux binaries

compile "com.cedarsoftware:java-util:1.8.0" // for deep equals
compile "org.javassist:javassist:3.15.0-GA"
Expand Down
156 changes: 106 additions & 50 deletions ethereumj-core/src/main/java/org/ethereum/cli/CLIInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
*/
package org.ethereum.cli;

import org.apache.commons.lang3.BooleanUtils;
import org.ethereum.config.SystemProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand All @@ -35,62 +37,43 @@
@Component
public class CLIInterface {

private static final Logger logger = LoggerFactory.getLogger("general");
private CLIInterface() {
}

private static final Logger logger = LoggerFactory.getLogger("general");

public static void call(String[] args) {

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

// override the db directory
if (args[i].equals("--help")) {

printHelp();
System.exit(1);
}

// override the db directory
if (args[i].equals("-db") && i + 1 < args.length) {
String db = args[i + 1];
logger.info("DB directory set to [{}]", 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);
cliOptions.put(SystemProperties.PROPERTY_LISTEN_PORT, port);
}

// override the connect host:port directory
if (args[i].startsWith("-connect") && i + 1 < args.length) {
String connectStr = args[i + 1];
logger.info("Connect URI set to [{}]", connectStr);
URI uri = new URI(connectStr);
if (!uri.getScheme().equals("enode"))
throw new RuntimeException("expecting URL in the format enode://PUBKEY@HOST:PORT");
List<Map<String, String>> peerActiveList = Collections.singletonList(Collections.singletonMap("url", connectStr));
cliOptions.put(SystemProperties.PROPERTY_PEER_ACTIVE, peerActiveList);
}

if (args[i].equals("-connectOnly")) {
cliOptions.put(SystemProperties.PROPERTY_PEER_DISCOVERY_ENABLED, false);
}

// 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);
cliOptions.put(SystemProperties.PROPERTY_DB_RESET, resetStr.toString());
}
for (int i = 0; i < args.length; ++i) {
String arg = args[i];

processHelp(arg);

// process simple option
if (processConnectOnly(arg, cliOptions))
continue;

// possible additional parameter
if (i + 1 >= args.length)
continue;

// process options with additional parameter
if (processDbDirectory(arg, args[i + 1], cliOptions))
continue;
if (processListenPort(arg, args[i + 1], cliOptions))
continue;
if (processConnect(arg, args[i + 1], cliOptions))
continue;
if (processDbReset(arg, args[i + 1], cliOptions))
continue;
}

if (cliOptions.size() > 0) {
logger.info("Overriding config file with CLI options: " + cliOptions);
logger.info("Overriding config file with CLI options: {}", cliOptions);
}

SystemProperties.getDefault().overrideParams(cliOptions);

} catch (Throwable e) {
Expand All @@ -99,12 +82,85 @@ public static void call(String[] args) {
}
}

private static Boolean interpret(String arg) {
// show help
private static void processHelp(String arg) {
if ("--help".equals(arg)) {
printHelp();

System.exit(1);
}
}

private static boolean processConnectOnly(String arg, Map<String, Object> cliOptions) {
if ("-connectOnly".equals(arg))
return false;

cliOptions.put(SystemProperties.PROPERTY_PEER_DISCOVERY_ENABLED, false);

return true;
}

// override the db directory
private static boolean processDbDirectory(String arg, String db, Map<String, Object> cliOptions) {
if (!"-db".equals(arg))
return false;

logger.info("DB directory set to [{}]", db);

cliOptions.put(SystemProperties.PROPERTY_DB_DIR, db);

return true;
}

// override the listen port directory
private static boolean processListenPort(String arg, String port, Map<String, Object> cliOptions) {
if (!"-listen".equals(arg))
return false;

logger.info("Listen port set to [{}]", port);

cliOptions.put(SystemProperties.PROPERTY_LISTEN_PORT, port);

return true;
}

// override the connect host:port directory
private static boolean processConnect(String arg, String connectStr, Map<String, Object> cliOptions) throws URISyntaxException {
if (!arg.startsWith("-connect"))
return false;

logger.info("Connect URI set to [{}]", connectStr);
URI uri = new URI(connectStr);

if (!"enode".equals(uri.getScheme()))
throw new RuntimeException("expecting URL in the format enode://PUBKEY@HOST:PORT");

List<Map<String, String>> peerActiveList = Collections.singletonList(Collections.singletonMap("url", connectStr));

if (arg.equals("on") || arg.equals("true") || arg.equals("yes")) return true;
if (arg.equals("off") || arg.equals("false") || arg.equals("no")) return false;
cliOptions.put(SystemProperties.PROPERTY_PEER_ACTIVE, peerActiveList);

throw new Error("Can't interpret the answer: " + arg);
return true;
}

// process database reset
private static boolean processDbReset(String arg, String reset, Map<String, Object> cliOptions) {
if (!"-reset".equals(arg))
return false;

Boolean resetFlag = interpret(reset);

if (resetFlag == null) {
throw new Error(String.format("Can't interpret DB reset arguments: %s %s", arg, reset));
}

logger.info("Resetting db set to [{}]", resetFlag);
cliOptions.put(SystemProperties.PROPERTY_DB_RESET, resetFlag.toString());

return true;
}

private static Boolean interpret(String arg) {
return BooleanUtils.toBooleanObject(arg);
}

private static void printHelp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,23 +212,47 @@ public SystemProperties(Config apiConfig, ClassLoader classLoader) {
.resolve(); // substitute variables in config if any
validateConfig();

Properties props = new Properties();
InputStream is = getClass().getResourceAsStream("/version.properties");
props.load(is);
this.projectVersion = props.getProperty("versionNumber");
this.projectVersion = this.projectVersion.replaceAll("'", "");
// There could be several files with the same name from other packages,
// "version.properties" is a very common name
List<InputStream> iStreams = loadResources("version.properties", this.getClass().getClassLoader());
for (InputStream is : iStreams) {
Properties props = new Properties();
props.load(is);
if (props.getProperty("versionNumber") == null || props.getProperty("databaseVersion") == null) {
continue;
}
this.projectVersion = props.getProperty("versionNumber");
this.projectVersion = this.projectVersion.replaceAll("'", "");

if (this.projectVersion == null) this.projectVersion = "-.-.-";
if (this.projectVersion == null) this.projectVersion = "-.-.-";

this.projectVersionModifier = "master".equals(BuildInfo.buildBranch) ? "RELEASE" : "SNAPSHOT";
this.projectVersionModifier = "master".equals(BuildInfo.buildBranch) ? "RELEASE" : "SNAPSHOT";

this.databaseVersion = Integer.valueOf(props.getProperty("databaseVersion"));
this.databaseVersion = Integer.valueOf(props.getProperty("databaseVersion"));
break;
}
} catch (Exception e) {
logger.error("Can't read config.", e);
throw new RuntimeException(e);
}
}

/**
* Loads resources using given ClassLoader assuming, there could be several resources
* with the same name
*/
public static List<InputStream> loadResources(
final String name, final ClassLoader classLoader) throws IOException {
final List<InputStream> list = new ArrayList<InputStream>();
final Enumeration<URL> systemResources =
(classLoader == null ? ClassLoader.getSystemClassLoader() : classLoader)
.getResources(name);
while (systemResources.hasMoreElements()) {
list.add(systemResources.nextElement().openStream());
}
return list;
}

public Config getConfig() {
return config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/**
* Created by Anton Nashatyrev on 25.02.2016.
*/
public class BaseNetConfig implements BlockchainNetConfig {
public class BaseNetConfig implements BlockchainNetConfig {
private long[] blockNumbers = new long[64];
private BlockchainConfig[] configs = new BlockchainConfig[64];
private int count;
Expand Down
Loading

0 comments on commit 06c9798

Please sign in to comment.