From 194f0f5c1bb1d1dd511fb14d17a2639ed3c873e5 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Fri, 16 Oct 2020 12:37:19 +0200 Subject: [PATCH] add file flag fallback to set testnet on startup --- README.md | 2 ++ src/main/java/com/sparrowwallet/sparrow/MainApp.java | 6 ++++++ src/main/java/com/sparrowwallet/sparrow/io/Storage.java | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 758c3149..197b90f7 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/src/main/java/com/sparrowwallet/sparrow/MainApp.java b/src/main/java/com/sparrowwallet/sparrow/MainApp.java index 274c6a0e..abc506f7 100644 --- a/src/main/java/com/sparrowwallet/sparrow/MainApp.java +++ b/src/main/java/com/sparrowwallet/sparrow/MainApp.java @@ -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"); } diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Storage.java b/src/main/java/com/sparrowwallet/sparrow/io/Storage.java index 182c91b0..d48010c0 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Storage.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Storage.java @@ -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)); }