diff --git a/doc/bitsquare.config b/doc/bitsquare.config new file mode 100644 index 0000000000..1efd45eb5c --- /dev/null +++ b/doc/bitsquare.config @@ -0,0 +1,24 @@ +# If that file is available in the data directory the defined properties will be used. + +# Here are the typical locations for the data directory: + +# Windows: +# %APPDATA%\Bitcoin\ +# (XP) C:\Documents and Settings\username\Application Data\Bitcoin\bitcoin.conf +# (Vista, 7) C:\Users\username\AppData\Roaming\Bitcoin\bitcoin.conf + +# Linux: +# $HOME/.bitcoin/ +# /home/username/.bitcoin/bitcoin.conf + +# Mac OSX: +# $HOME/Library/Application Support/Bitcoin/ +# /Users/username/Library/Application Support/Bitcoin/bitcoin.conf + + +# Supported properties: +# networkType=regtest +# networkType=testnet +# networkType=mainnet + +networkType=regtest \ No newline at end of file diff --git a/src/main/java/io/bitsquare/BitSquare.java b/src/main/java/io/bitsquare/BitSquare.java index 84276e9a64..d3188af218 100644 --- a/src/main/java/io/bitsquare/BitSquare.java +++ b/src/main/java/io/bitsquare/BitSquare.java @@ -63,7 +63,9 @@ public class BitSquare extends Application { public static void main(String[] args) { Profiler.init(); Profiler.printMsgWithTime("BitSquare.main called with args " + Arrays.asList(args).toString()); - if (args.length > 0) APP_NAME = APP_NAME + "_" + args[0]; + + if (args.length > 0) + APP_NAME = APP_NAME + "_" + args[0]; launch(args); } @@ -107,7 +109,6 @@ public class BitSquare extends Application { User persistedUser = (User) persistence.read(user); user.applyPersistedUser(persistedUser); - //persistence.write(user); settings.applyPersistedSettings((Settings) persistence.read(settings.getClass().getName())); diff --git a/src/main/java/io/bitsquare/btc/WalletFacade.java b/src/main/java/io/bitsquare/btc/WalletFacade.java index 04b3d2aa0d..f648a586b5 100644 --- a/src/main/java/io/bitsquare/btc/WalletFacade.java +++ b/src/main/java/io/bitsquare/btc/WalletFacade.java @@ -91,9 +91,9 @@ import static com.google.bitcoin.script.ScriptOpCodes.OP_RETURN; public class WalletFacade { private static final Logger log = LoggerFactory.getLogger(WalletFacade.class); - public static final String MAIN_NET = "MAIN_NET"; - public static final String TEST_NET = "TEST_NET"; - public static final String REG_TEST_NET = "REG_TEST_NET"; + public static final String MAIN_NET = "mainnet"; + public static final String TEST_NET = "testnet"; + public static final String REG_TEST_NET = "regtest"; public static final String WALLET_PREFIX = BitSquare.getAppName(); private final ReentrantLock lock = Threading.lock("lock"); diff --git a/src/main/java/io/bitsquare/di/BitSquareModule.java b/src/main/java/io/bitsquare/di/BitSquareModule.java index dd46df3d02..e1fc27461c 100644 --- a/src/main/java/io/bitsquare/di/BitSquareModule.java +++ b/src/main/java/io/bitsquare/di/BitSquareModule.java @@ -39,6 +39,7 @@ import io.bitsquare.persistence.Persistence; import io.bitsquare.settings.Settings; import io.bitsquare.trade.TradeManager; import io.bitsquare.user.User; +import io.bitsquare.util.ConfigLoader; import com.google.bitcoin.core.NetworkParameters; import com.google.bitcoin.params.MainNetParams; @@ -50,9 +51,15 @@ import com.google.inject.Provider; import com.google.inject.name.Named; import com.google.inject.name.Names; +import java.util.Properties; + import javax.inject.Inject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class BitSquareModule extends AbstractModule { + private static final Logger log = LoggerFactory.getLogger(BitSquareModule.class); @Override protected void configure() { @@ -100,17 +107,25 @@ public class BitSquareModule extends AbstractModule { } class NetworkParametersProvider implements Provider { - private final String networkType; + private static final Logger log = LoggerFactory.getLogger(NetworkParametersProvider.class); + private String networkType; @Inject public NetworkParametersProvider(@Named("networkType") String networkType) { this.networkType = networkType; } - public NetworkParameters get() { NetworkParameters result = null; + //If config is available we override the networkType defined in Guice with the one from the config file + Properties properties = ConfigLoader.loadConfig(); + log.info("networkType = " + properties.getProperty("networkType")); + String networkTypeFromConfig = properties.getProperty("networkType"); + + if (networkTypeFromConfig != null) + networkType = networkTypeFromConfig; + switch (networkType) { case WalletFacade.MAIN_NET: result = MainNetParams.get(); diff --git a/src/main/java/io/bitsquare/util/ConfigLoader.java b/src/main/java/io/bitsquare/util/ConfigLoader.java new file mode 100644 index 0000000000..de5eb1cb75 --- /dev/null +++ b/src/main/java/io/bitsquare/util/ConfigLoader.java @@ -0,0 +1,57 @@ +/* + * This file is part of Bitsquare. + * + * Bitsquare is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bitsquare is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bitsquare. If not, see . + */ + +package io.bitsquare.util; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +import java.util.Properties; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import lighthouse.files.AppDirectory; + +public class ConfigLoader { + private static final Logger log = LoggerFactory.getLogger(ConfigLoader.class); + private static final String configFilePath = AppDirectory.dir() + "/bitsquare.config"; + + public static Properties loadConfig() { + Properties properties = new Properties(); + InputStream inputStream = null; + if (new File(configFilePath).exists()) { + try { + inputStream = new FileInputStream(configFilePath); + properties.load(inputStream); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e2) { + e2.printStackTrace(); + } + } + } + } + return properties; + } +} diff --git a/src/main/resources/bitsquare.properties b/src/main/resources/bitsquare.properties index 962fe3e828..e69de29bb2 100644 --- a/src/main/resources/bitsquare.properties +++ b/src/main/resources/bitsquare.properties @@ -1,3 +0,0 @@ -com.google.bitcoin = FATAL - -