Skip to content

Commit

Permalink
Add 'blockchain.config.*' config options
Browse files Browse the repository at this point in the history
  • Loading branch information
Nashatyrev committed Feb 26, 2016
1 parent 7af6710 commit 0c28444
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Expand Up @@ -4,7 +4,10 @@
import com.typesafe.config.ConfigFactory;
import com.typesafe.config.ConfigObject;
import com.typesafe.config.ConfigRenderOptions;
import org.ethereum.config.blockchain.OlympicConfig;
import org.ethereum.config.fork.MainForkConfig;
import org.ethereum.config.fork.MordenForkConfig;
import org.ethereum.config.fork.TestNetForkConfig;
import org.ethereum.core.Genesis;
import org.ethereum.core.genesis.GenesisLoader;
import org.ethereum.crypto.ECKey;
Expand Down Expand Up @@ -83,7 +86,7 @@ public class SystemProperties {
private Boolean syncEnabled = null;
private Boolean discoveryEnabled = null;

private BlockchainForkConfig blockchainConfig = MainForkConfig.INSTANCE;
private BlockchainForkConfig blockchainConfig;
private Genesis genesis;

public SystemProperties() {
Expand Down Expand Up @@ -210,7 +213,43 @@ public <T> T getProperty(String propName, T defaultValue) {
return (T) config.getAnyRef(propName);
}

@ValidateMe
public BlockchainForkConfig getBlockchainConfig() {
if (blockchainConfig == null) {
if (config.hasPath("blockchain.config.name") && config.hasPath("blockchain.config.class")) {
throw new RuntimeException("Only one of two options should be defined: 'blockchain.config.name' and 'blockchain.config.class'");
}
if (config.hasPath("blockchain.config.name")) {
switch(config.getString("blockchain.config.name")) {
case "main":
blockchainConfig = new MainForkConfig();
break;
case "olympic":
blockchainConfig = new OlympicConfig();
break;
case "morden":
blockchainConfig = new MordenForkConfig();
break;
case "testnet":
blockchainConfig = new TestNetForkConfig();
break;
default:
throw new RuntimeException("Unknown value for 'blockchain.config.name': '" + config.getString("blockchain.config.name") + "'");
}
} else {
String className = config.getString("blockchain.config.class");
try {
Class<? extends BlockchainForkConfig> aClass = (Class<? extends BlockchainForkConfig>) Class.forName(className);
blockchainConfig = aClass.newInstance();
} catch (ClassNotFoundException e) {
throw new RuntimeException("The class specified via blockchain.config.class '" + className + "' not found" , e);
} catch (ClassCastException e) {
throw new RuntimeException("The class specified via blockchain.config.class '" + className + "' is not instance of org.ethereum.config.BlockchainForkConfig" , e);
} catch (InstantiationException|IllegalAccessException e) {
throw new RuntimeException("The class specified via blockchain.config.class '" + className + "' couldn't be instantiated (check for default constructor and its accessibility)" , e);
}
}
}
return blockchainConfig;
}

Expand Down
16 changes: 16 additions & 0 deletions ethereumj-core/src/main/resources/ethereumj.conf
Expand Up @@ -126,6 +126,22 @@ peer {
# to the network the peer will run on
genesis = frontier.json

# Blockchain settings (constants and algorithms) which are
# not described in the genesis file (like MINIMUM_DIFFICULTY or Mining algorithm)
# The possible named presets are:
# - main : the main network (Frontier-Homestead-...)
# - morden: Morden test network
# - testnet: Ethercamp test network
# - olympic: pre-Frontier Olympic network
# For custom network settings please refer to 'blockchain.config.class'
blockchain.config.name = "main"

# This is a more advanced replacement for 'blockchain.config.name'
# Here the exact org.ethereum.config.BlockchainForkConfig implementation
# class name can be specified.
# Only one of two options (this and above) can be defined.
#blockchain.config.class = "org.ethereum.config.fork.MainForkConfig"

# the time we wait to the network
# to approve the transaction, the
# transaction got approved when
Expand Down

0 comments on commit 0c28444

Please sign in to comment.