add file flag fallback to set testnet on startup

This commit is contained in:
Craig Raw 2020-10-16 12:37:19 +02:00
parent bda5c1a709
commit 194f0f5c1b
3 changed files with 9 additions and 1 deletions

View file

@ -52,6 +52,8 @@ As a fallback, the network (mainnet, testnet or regtest) can also be set using a
`export SPARROW_NETWORK=testnet`
A final fallback which can be useful when running the Sparrow binary is to create a file called ``network-testnet`` in the Sparrow home folder (see below) to configure the testnet network.
Note that if you are connecting to an Electrum server when using testnet, that server will need to running on testnet configuration as well.
When not explicitly configured using the command line argument above, Sparrow stores it's mainnet config file, log file and wallets in a home folder location appropriate to the operating system:

View file

@ -8,6 +8,7 @@ import com.sparrowwallet.sparrow.glyphfont.FontAwesome5Brands;
import com.sparrowwallet.sparrow.io.Config;
import com.sparrowwallet.sparrow.io.FileType;
import com.sparrowwallet.sparrow.io.IOUtils;
import com.sparrowwallet.sparrow.io.Storage;
import com.sparrowwallet.sparrow.preferences.PreferenceGroup;
import com.sparrowwallet.sparrow.preferences.PreferencesDialog;
import javafx.application.Application;
@ -138,6 +139,11 @@ public class MainApp extends Application {
}
}
File testnetFlag = new File(Storage.getSparrowHome(), "network-" + Network.TESTNET.getName());
if(testnetFlag.exists()) {
Network.set(Network.TESTNET);
}
if(Network.get() != Network.MAINNET) {
log.info("Using " + Network.get() + " configuration");
}

View file

@ -285,7 +285,7 @@ public class Storage {
return getSparrowHome();
}
static File getSparrowHome() {
public static File getSparrowHome() {
if(System.getProperty(MainApp.APP_HOME_PROPERTY) != null) {
return new File(System.getProperty(MainApp.APP_HOME_PROPERTY));
}