mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-03-15 10:26:37 -04:00
Add config file support for network type selection
This commit is contained in:
parent
d2b1c5f37c
commit
a5a04fe72c
24
doc/bitsquare.config
Normal file
24
doc/bitsquare.config
Normal file
@ -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
|
@ -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()));
|
||||
|
||||
|
@ -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");
|
||||
|
@ -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<NetworkParameters> {
|
||||
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();
|
||||
|
57
src/main/java/io/bitsquare/util/ConfigLoader.java
Normal file
57
src/main/java/io/bitsquare/util/ConfigLoader.java
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
com.google.bitcoin = FATAL
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user