Allow configurability of bitcoin network with --bitcoin.network

This commit changes the previous option value of 'networkType' to
'bitcoin.network' and exposes it through the ArgumentParser.
This commit is contained in:
Chris Beams 2014-11-10 14:19:06 +01:00
parent adfd8b2ac4
commit 8c9557c891
No known key found for this signature in database
GPG key ID: 3D214F8F5BC5ED73
5 changed files with 18 additions and 14 deletions

View file

@ -17,6 +17,6 @@
# Supported properties:
# networkType=regtest | testnet | mainnet
# bitcoin.network=regtest | testnet | mainnet
networkType=regtest
bitcoin.network=regtest

View file

@ -17,6 +17,7 @@
package io.bitsquare.app;
import io.bitsquare.btc.BitcoinModule;
import io.bitsquare.network.Node;
import net.sourceforge.argparse4j.ArgumentParsers;
@ -53,6 +54,10 @@ public class ArgumentParser {
parser.addArgument("--" + NETWORK_INTERFACE_KEY)
.help("Network interface");
parser.addArgument("--" + BitcoinModule.BITCOIN_NETWORK_KEY)
.setDefault(BitcoinModule.DEFAULT_BITCOIN_NETWORK.toString())
.help("Bitcoin network to use");
// Args for app config
parser.addArgument("-n", "--" + APP_NAME_KEY)
.help("Name to append to default application name");

View file

@ -50,6 +50,7 @@ import lighthouse.files.AppDirectory;
import net.sourceforge.argparse4j.inf.Namespace;
import static io.bitsquare.app.AppModule.APP_NAME_KEY;
import static io.bitsquare.btc.BitcoinModule.BITCOIN_NETWORK_KEY;
import static io.bitsquare.msg.tomp2p.TomP2PMessageModule.*;
import static io.bitsquare.network.Node.*;
@ -89,6 +90,9 @@ public class Main extends Application {
if (argumentsNamespace.getString(NETWORK_INTERFACE_KEY) != null)
properties.setProperty(NETWORK_INTERFACE_KEY, argumentsNamespace.getString(NETWORK_INTERFACE_KEY));
if (argumentsNamespace.getString(BITCOIN_NETWORK_KEY) != null)
properties.setProperty(BITCOIN_NETWORK_KEY, argumentsNamespace.getString(BITCOIN_NETWORK_KEY));
Application.launch(Main.class, args);
}

View file

@ -30,17 +30,11 @@ import java.util.Properties;
public class BitcoinModule extends BitsquareModule {
private static final BitcoinNetwork DEFAULT_NETWORK = BitcoinNetwork.TESTNET;
private final BitcoinNetwork network;
public static final String BITCOIN_NETWORK_KEY = "bitcoin.network";
public static final String DEFAULT_BITCOIN_NETWORK = BitcoinNetwork.TESTNET.toString();
public BitcoinModule(Properties properties) {
this(properties, DEFAULT_NETWORK);
}
public BitcoinModule(Properties properties, BitcoinNetwork network) {
super(properties);
this.network = network;
}
@Override
@ -57,9 +51,10 @@ public class BitcoinModule extends BitsquareModule {
}
private NetworkParameters network() {
String networkName = properties.getProperty("networkType", network.name());
BitcoinNetwork network = BitcoinNetwork.valueOf(
properties.getProperty(BITCOIN_NETWORK_KEY, DEFAULT_BITCOIN_NETWORK).toUpperCase());
switch (BitcoinNetwork.valueOf(networkName.toUpperCase())) {
switch (network) {
case MAINNET:
return MainNetParams.get();
case TESTNET:
@ -67,7 +62,7 @@ public class BitcoinModule extends BitsquareModule {
case REGTEST:
return RegTestParams.get();
default:
throw new IllegalArgumentException("Unknown bitcoin network name: " + networkName);
throw new IllegalArgumentException("Unknown bitcoin network: " + network);
}
}
}

View file

@ -18,5 +18,5 @@
package io.bitsquare.btc;
public enum BitcoinNetwork {
MAINNET, TESTNET, REGTEST
MAINNET, TESTNET, REGTEST;
}