From 63205d78f6932a0f4096250413aad9b76e852aed Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Fri, 10 Jan 2020 20:18:03 +0100 Subject: [PATCH] Make Config option fields public and inline accessors See updated Config Javadoc for rationale. --- .../main/java/bisq/common/config/Config.java | 416 ++++-------------- .../java/bisq/common/config/ConfigTests.java | 76 ++-- core/src/main/java/bisq/core/CoreModule.java | 14 +- .../java/bisq/core/alert/AlertModule.java | 2 +- .../core/app/AvoidStandbyModeService.java | 2 +- .../java/bisq/core/app/BisqExecutable.java | 6 +- .../main/java/bisq/core/app/BisqSetup.java | 4 +- .../main/java/bisq/core/app/SetupUtils.java | 2 +- .../java/bisq/core/app/WalletAppSetup.java | 4 +- .../java/bisq/core/app/misc/AppSetup.java | 2 +- .../core/app/misc/AppSetupWithP2PAndDAO.java | 2 +- .../app/misc/ExecutableForAppWithP2p.java | 4 +- .../core/app/misc/ModuleForAppWithP2p.java | 12 +- .../java/bisq/core/btc/BitcoinModule.java | 22 +- .../bisq/core/btc/nodes/LocalBitcoinNode.java | 2 +- .../bisq/core/btc/setup/WalletConfig.java | 2 +- .../bisq/core/btc/setup/WalletsSetup.java | 2 +- .../main/java/bisq/core/dao/DaoModule.java | 24 +- .../blindvote/BlindVoteListService.java | 2 +- .../java/bisq/core/filter/FilterManager.java | 2 +- .../java/bisq/core/filter/FilterModule.java | 2 +- .../p2p/seed/DefaultSeedNodeRepository.java | 8 +- .../core/provider/ProvidersRepository.java | 4 +- .../core/setup/CoreNetworkCapabilities.java | 4 +- .../core/setup/CorePersistedDataHost.java | 2 +- .../main/java/bisq/core/setup/CoreSetup.java | 6 +- .../java/bisq/core/trade/TradeModule.java | 2 +- .../main/java/bisq/core/user/Preferences.java | 10 +- .../java/bisq/core/user/PreferencesTest.java | 2 +- .../main/java/bisq/desktop/DesktopModule.java | 2 +- .../java/bisq/desktop/main/MainViewModel.java | 2 +- .../account/content/backup/BackupView.java | 2 +- .../DisplayUpdateDownloadWindow.java | 2 +- .../settings/preferences/PreferencesView.java | 2 +- .../main/java/bisq/network/p2p/P2PModule.java | 28 +- .../bisq/network/p2p/network/Connection.java | 14 +- 36 files changed, 218 insertions(+), 476 deletions(-) diff --git a/common/src/main/java/bisq/common/config/Config.java b/common/src/main/java/bisq/common/config/Config.java index 4b0aa527130..c9167c4273e 100644 --- a/common/src/main/java/bisq/common/config/Config.java +++ b/common/src/main/java/bisq/common/config/Config.java @@ -40,6 +40,15 @@ * modification of the actual system user data directory and/or the production Bisq * application data directory. Calling code must explicitly specify these values; they are * never assumed. + *

+ * Note that this class deviates from typical JavaBean conventions in that fields + * representing configuration options are public and have no corresponding accessor + * ("getter") method. This is because all such fields are final and therefore not subject + * to modification by calling code and because eliminating the accessor methods means + * eliminating hundreds of lines of boilerplate code and one less touchpoint to deal with + * when adding or modifying options. Furthermore, while accessor methods are often useful + * when mocking an object in a testing context, this class is designed for testability + * without needing to be mocked. See {@code ConfigTests} for examples. * @see #Config(String...) * @see #Config(String, File, String...) */ @@ -120,78 +129,78 @@ public class Config { // Default "data dir properties", i.e. properties that can determine the location of // Bisq's application data directory (appDataDir) - private final String defaultAppName; - private final File defaultUserDataDir; - private final File defaultAppDataDir; - private final File defaultConfigFile; + public final String defaultAppName; + public final File defaultUserDataDir; + public final File defaultAppDataDir; + public final File defaultConfigFile; // Options supported only at the command-line interface (cli) - private final boolean helpRequested; - private final File configFile; + public final boolean helpRequested; + public final File configFile; // Options supported both at the cli and in the config file - private final String appName; - private final File userDataDir; - private final File appDataDir; - private final int nodePort; - private final int maxMemory; - private final String logLevel; - private final List bannedBtcNodes; - private final List bannedPriceRelayNodes; - private final List bannedSeedNodes; - private final BaseCurrencyNetwork baseCurrencyNetwork; - private final NetworkParameters baseCurrencyNetworkParameters; - private final boolean ignoreLocalBtcNode; - private final String bitcoinRegtestHost; - private final boolean daoActivated; - private final String referralId; - private final boolean useDevMode; - private final boolean useDevPrivilegeKeys; - private final boolean dumpStatistics; - private final boolean ignoreDevMsg; - private final List providers; - private final List seedNodes; - private final List banList; - private final boolean useLocalhostForP2P; - private final int maxConnections; - private final String socks5ProxyBtcAddress; - private final String socks5ProxyHttpAddress; - private final File torrcFile; - private final String torrcOptions; - private final int torControlPort; - private final String torControlPassword; - private final File torControlCookieFile; - private final boolean useTorControlSafeCookieAuth; - private final boolean torStreamIsolation; - private final int msgThrottlePerSec; - private final int msgThrottlePer10Sec; - private final int sendMsgThrottleTrigger; - private final int sendMsgThrottleSleep; - private final String btcNodes; - private final boolean useTorForBtc; - private final boolean useTorForBtcOptionSetExplicitly; - private final String socks5DiscoverMode; - private final boolean useAllProvidedNodes; - private final String userAgent; - private final int numConnectionsForBtc; - private final String rpcUser; - private final String rpcPassword; - private final String rpcHost; - private final int rpcPort; - private final int rpcBlockNotificationPort; - private final String rpcBlockNotificationHost; - private final boolean dumpBlockchainData; - private final boolean fullDaoNode; - private final boolean fullDaoNodeOptionSetExplicitly; - private final String genesisTxId; - private final int genesisBlockHeight; - private final long genesisTotalSupply; + public final String appName; + public final File userDataDir; + public final File appDataDir; + public final int nodePort; + public final int maxMemory; + public final String logLevel; + public final List bannedBtcNodes; + public final List bannedPriceRelayNodes; + public final List bannedSeedNodes; + public final BaseCurrencyNetwork baseCurrencyNetwork; + public final NetworkParameters baseCurrencyNetworkParameters; + public final boolean ignoreLocalBtcNode; + public final String bitcoinRegtestHost; + public final boolean daoActivated; + public final String referralId; + public final boolean useDevMode; + public final boolean useDevPrivilegeKeys; + public final boolean dumpStatistics; + public final boolean ignoreDevMsg; + public final List providers; + public final List seedNodes; + public final List banList; + public final boolean useLocalhostForP2P; + public final int maxConnections; + public final String socks5ProxyBtcAddress; + public final String socks5ProxyHttpAddress; + public final File torrcFile; + public final String torrcOptions; + public final int torControlPort; + public final String torControlPassword; + public final File torControlCookieFile; + public final boolean useTorControlSafeCookieAuth; + public final boolean torStreamIsolation; + public final int msgThrottlePerSec; + public final int msgThrottlePer10Sec; + public final int sendMsgThrottleTrigger; + public final int sendMsgThrottleSleep; + public final String btcNodes; + public final boolean useTorForBtc; + public final boolean useTorForBtcOptionSetExplicitly; + public final String socks5DiscoverMode; + public final boolean useAllProvidedNodes; + public final String userAgent; + public final int numConnectionsForBtc; + public final String rpcUser; + public final String rpcPassword; + public final String rpcHost; + public final int rpcPort; + public final int rpcBlockNotificationPort; + public final String rpcBlockNotificationHost; + public final boolean dumpBlockchainData; + public final boolean fullDaoNode; + public final boolean fullDaoNodeOptionSetExplicitly; + public final String genesisTxId; + public final int genesisBlockHeight; + public final long genesisTotalSupply; // Properties derived from options but not exposed as options themselves - private final File torDir; - private final File walletDir; - private final File storageDir; - private final File keyStorageDir; + public final File torDir; + public final File walletDir; + public final File storageDir; + public final File keyStorageDir; // The parser that will be used to parse both cli and config file options private final OptionParser parser = new OptionParser(); @@ -806,9 +815,9 @@ private static File mkdir(File parent, String child) { /** * Static accessor that returns the same value as the non-static - * {@link #getAppDataDir()} method. For use only in the {@code Overlay} class, where + * {@link #appDataDir} property. For use only in the {@code Overlay} class, where * because of its large number of subclasses, injecting the Guice-managed - * {@link Config} class is not worth the effort. {@link #getAppDataDir()} should be + * {@link Config} class is not worth the effort. {@link #appDataDir} should be * favored in all other cases. * @throws NullPointerException if the static value has not yet been assigned, i.e. if * the Guice-managed {@link Config} class has not yet been instantiated elsewhere. @@ -825,7 +834,7 @@ public static File appDataDir() { * Static accessor that returns either the default base currency network value of * {@link BaseCurrencyNetwork#BTC_MAINNET} or the value assigned via the * {@value BASE_CURRENCY_NETWORK} option. The non-static - * {@link #getBaseCurrencyNetwork()} accessor should be favored whenever possible and + * {@link #baseCurrencyNetwork} property should be favored whenever possible and * this static accessor should be used only in code locations where it is infeasible * or too cumbersome to inject the normal Guice-managed singleton {@link Config} * instance. @@ -838,278 +847,11 @@ public static BaseCurrencyNetwork baseCurrencyNetwork() { * Static accessor that returns the value of * {@code baseCurrencyNetwork().getParameters()} for convenience and to avoid violating * the Law of Demeter. The - * non-static {@link #getBaseCurrencyNetwork()} method should be favored whenever + * non-static {@link #baseCurrencyNetwork} property should be favored whenever * possible. * @see #baseCurrencyNetwork() */ public static NetworkParameters baseCurrencyNetworkParameters() { return BASE_CURRENCY_NETWORK_VALUE.getParameters(); } - - - // == ACCESSORS ====================================================================== - - public String getDefaultAppName() { - return defaultAppName; - } - - public File getDefaultUserDataDir() { - return defaultUserDataDir; - } - - public File getDefaultAppDataDir() { - return defaultAppDataDir; - } - - public File getDefaultConfigFile() { - return defaultConfigFile; - } - - public boolean isHelpRequested() { - return helpRequested; - } - - public File getConfigFile() { - return configFile; - } - - public String getAppName() { - return appName; - } - - public File getUserDataDir() { - return userDataDir; - } - - public File getAppDataDir() { - return appDataDir; - } - - public int getNodePort() { - return nodePort; - } - - public List getBannedBtcNodes() { - return bannedBtcNodes; - } - - public List getBannedPriceRelayNodes() { - return bannedPriceRelayNodes; - } - - public List getBannedSeedNodes() { - return bannedSeedNodes; - } - - public BaseCurrencyNetwork getBaseCurrencyNetwork() { - return baseCurrencyNetwork; - } - - public NetworkParameters getBaseCurrencyNetworkParameters() { - return baseCurrencyNetworkParameters; - } - - public boolean isIgnoreLocalBtcNode() { - return ignoreLocalBtcNode; - } - - public String getBitcoinRegtestHost() { - return bitcoinRegtestHost; - } - - public String getLogLevel() { - return logLevel; - } - - public String getReferralId() { - return referralId; - } - - public boolean isUseDevMode() { - return useDevMode; - } - - public File getTorDir() { - return torDir; - } - - public File getWalletDir() { - return walletDir; - } - - public File getStorageDir() { - return storageDir; - } - - public File getKeyStorageDir() { - return keyStorageDir; - } - - public boolean isUseDevPrivilegeKeys() { - return useDevPrivilegeKeys; - } - - public boolean isDumpStatistics() { - return dumpStatistics; - } - - public int getMaxMemory() { - return maxMemory; - } - - public boolean isIgnoreDevMsg() { - return ignoreDevMsg; - } - - public List getProviders() { - return providers; - } - - public List getSeedNodes() { - return seedNodes; - } - - public List getBanList() { - return banList; - } - - public boolean isUseLocalhostForP2P() { - return useLocalhostForP2P; - } - - public int getMaxConnections() { - return maxConnections; - } - - public String getSocks5ProxyBtcAddress() { - return socks5ProxyBtcAddress; - } - - public String getSocks5ProxyHttpAddress() { - return socks5ProxyHttpAddress; - } - - public File getTorrcFile() { - return torrcFile; - } - - public String getTorrcOptions() { - return torrcOptions; - } - - public int getTorControlPort() { - return torControlPort; - } - - public String getTorControlPassword() { - return torControlPassword; - } - - public File getTorControlCookieFile() { - return torControlCookieFile; - } - - public boolean isUseTorControlSafeCookieAuth() { - return useTorControlSafeCookieAuth; - } - - public boolean isTorStreamIsolation() { - return torStreamIsolation; - } - - public int getMsgThrottlePerSec() { - return msgThrottlePerSec; - } - - public int getMsgThrottlePer10Sec() { - return msgThrottlePer10Sec; - } - - public int getSendMsgThrottleTrigger() { - return sendMsgThrottleTrigger; - } - - public int getSendMsgThrottleSleep() { - return sendMsgThrottleSleep; - } - - public String getBtcNodes() { - return btcNodes; - } - - public boolean isUseTorForBtc() { - return useTorForBtc; - } - - public boolean isUseTorForBtcOptionSetExplicitly() { - return useTorForBtcOptionSetExplicitly; - } - - public String getSocks5DiscoverMode() { - return socks5DiscoverMode; - } - - public boolean isUseAllProvidedNodes() { - return useAllProvidedNodes; - } - - public String getUserAgent() { - return userAgent; - } - - public int getNumConnectionsForBtc() { - return numConnectionsForBtc; - } - - public String getRpcUser() { - return rpcUser; - } - - public String getRpcPassword() { - return rpcPassword; - } - - public String getRpcHost() { - return rpcHost; - } - - public int getRpcPort() { - return rpcPort; - } - - public int getRpcBlockNotificationPort() { - return rpcBlockNotificationPort; - } - - public String getRpcBlockNotificationHost() { - return rpcBlockNotificationHost; - } - - public boolean isDumpBlockchainData() { - return dumpBlockchainData; - } - - public boolean isFullDaoNode() { - return fullDaoNode; - } - - public boolean isFullDaoNodeOptionSetExplicitly() { - return fullDaoNodeOptionSetExplicitly; - } - - public String getGenesisTxId() { - return genesisTxId; - } - - public int getGenesisBlockHeight() { - return genesisBlockHeight; - } - - public long getGenesisTotalSupply() { - return genesisTotalSupply; - } - - public boolean isDaoActivated() { - return daoActivated; - } } diff --git a/common/src/test/java/bisq/common/config/ConfigTests.java b/common/src/test/java/bisq/common/config/ConfigTests.java index 0fbf6dda474..91554893881 100644 --- a/common/src/test/java/bisq/common/config/ConfigTests.java +++ b/common/src/test/java/bisq/common/config/ConfigTests.java @@ -35,7 +35,7 @@ public class ConfigTests { @Test public void whenNoArgCtorIsCalled_thenDefaultAppNameIsSetToTempValue() { Config config = new Config(); - String defaultAppName = config.getDefaultAppName(); + String defaultAppName = config.defaultAppName; String regex = "Bisq\\d{2,}Temp"; assertTrue(format("Temp app name '%s' failed to match '%s'", defaultAppName, regex), defaultAppName.matches(regex)); @@ -44,56 +44,56 @@ public void whenNoArgCtorIsCalled_thenDefaultAppNameIsSetToTempValue() { @Test public void whenAppNameOptionIsSet_thenAppNamePropertyDiffersFromDefaultAppNameProperty() { Config config = configWithOpts(opt(APP_NAME, "My-Bisq")); - assertThat(config.getAppName(), equalTo("My-Bisq")); - assertThat(config.getAppName(), not(equalTo(config.getDefaultAppName()))); + assertThat(config.appName, equalTo("My-Bisq")); + assertThat(config.appName, not(equalTo(config.defaultAppName))); } @Test public void whenNoOptionsAreSet_thenDataDirPropertiesEqualDefaultValues() { Config config = new Config(); - assertThat(config.getAppName(), equalTo(config.getDefaultAppName())); - assertThat(config.getUserDataDir(), equalTo(config.getDefaultUserDataDir())); - assertThat(config.getAppDataDir(), equalTo(config.getDefaultAppDataDir())); - assertThat(config.getConfigFile(), equalTo(config.getDefaultConfigFile())); + assertThat(config.appName, equalTo(config.defaultAppName)); + assertThat(config.userDataDir, equalTo(config.defaultUserDataDir)); + assertThat(config.appDataDir, equalTo(config.defaultAppDataDir)); + assertThat(config.configFile, equalTo(config.defaultConfigFile)); } @Test public void whenAppNameOptionIsSet_thenDataDirPropertiesReflectItsValue() { Config config = configWithOpts(opt(APP_NAME, "My-Bisq")); - assertThat(config.getAppName(), equalTo("My-Bisq")); - assertThat(config.getUserDataDir(), equalTo(config.getDefaultUserDataDir())); - assertThat(config.getAppDataDir(), equalTo(new File(config.getUserDataDir(), "My-Bisq"))); - assertThat(config.getConfigFile(), equalTo(new File(config.getAppDataDir(), DEFAULT_CONFIG_FILE_NAME))); + assertThat(config.appName, equalTo("My-Bisq")); + assertThat(config.userDataDir, equalTo(config.defaultUserDataDir)); + assertThat(config.appDataDir, equalTo(new File(config.userDataDir, "My-Bisq"))); + assertThat(config.configFile, equalTo(new File(config.appDataDir, DEFAULT_CONFIG_FILE_NAME))); } @Test public void whenAppDataDirOptionIsSet_thenDataDirPropertiesReflectItsValue() throws IOException { File appDataDir = Files.createTempDirectory("myapp").toFile(); Config config = configWithOpts(opt(APP_DATA_DIR, appDataDir)); - assertThat(config.getAppName(), equalTo(config.getDefaultAppName())); - assertThat(config.getUserDataDir(), equalTo(config.getDefaultUserDataDir())); - assertThat(config.getAppDataDir(), equalTo(appDataDir)); - assertThat(config.getConfigFile(), equalTo(new File(config.getAppDataDir(), DEFAULT_CONFIG_FILE_NAME))); + assertThat(config.appName, equalTo(config.defaultAppName)); + assertThat(config.userDataDir, equalTo(config.defaultUserDataDir)); + assertThat(config.appDataDir, equalTo(appDataDir)); + assertThat(config.configFile, equalTo(new File(config.appDataDir, DEFAULT_CONFIG_FILE_NAME))); } @Test public void whenUserDataDirOptionIsSet_thenDataDirPropertiesReflectItsValue() throws IOException { File userDataDir = Files.createTempDirectory("myuserdata").toFile(); Config config = configWithOpts(opt(USER_DATA_DIR, userDataDir)); - assertThat(config.getAppName(), equalTo(config.getDefaultAppName())); - assertThat(config.getUserDataDir(), equalTo(userDataDir)); - assertThat(config.getAppDataDir(), equalTo(new File(userDataDir, config.getDefaultAppName()))); - assertThat(config.getConfigFile(), equalTo(new File(config.getAppDataDir(), DEFAULT_CONFIG_FILE_NAME))); + assertThat(config.appName, equalTo(config.defaultAppName)); + assertThat(config.userDataDir, equalTo(userDataDir)); + assertThat(config.appDataDir, equalTo(new File(userDataDir, config.defaultAppName))); + assertThat(config.configFile, equalTo(new File(config.appDataDir, DEFAULT_CONFIG_FILE_NAME))); } @Test public void whenAppNameAndAppDataDirOptionsAreSet_thenDataDirPropertiesReflectTheirValues() throws IOException { File appDataDir = Files.createTempDirectory("myapp").toFile(); Config config = configWithOpts(opt(APP_NAME, "My-Bisq"), opt(APP_DATA_DIR, appDataDir)); - assertThat(config.getAppName(), equalTo("My-Bisq")); - assertThat(config.getUserDataDir(), equalTo(config.getDefaultUserDataDir())); - assertThat(config.getAppDataDir(), equalTo(appDataDir)); - assertThat(config.getConfigFile(), equalTo(new File(config.getAppDataDir(), DEFAULT_CONFIG_FILE_NAME))); + assertThat(config.appName, equalTo("My-Bisq")); + assertThat(config.userDataDir, equalTo(config.defaultUserDataDir)); + assertThat(config.appDataDir, equalTo(appDataDir)); + assertThat(config.configFile, equalTo(new File(config.appDataDir, DEFAULT_CONFIG_FILE_NAME))); } @Test @@ -103,7 +103,7 @@ public void whenOptionIsSetAtCommandLineAndInConfigFile_thenCommandLineValueTake writer.println(new ConfigFileOption(APP_NAME, "Bisq-configFileValue")); } Config config = configWithOpts(opt(APP_NAME, "Bisq-commandLineValue")); - assertThat(config.getAppName(), equalTo("Bisq-commandLineValue")); + assertThat(config.appName, equalTo("Bisq-commandLineValue")); } @Test @@ -142,7 +142,7 @@ public void whenConfigFileOptionIsSetInConfigFile_thenConfigExceptionIsThrown() public void whenConfigFileOptionIsSetToExistingFile_thenConfigFilePropertyReflectsItsValue() throws IOException { File configFile = File.createTempFile("bisq", "properties"); Config config = configWithOpts(opt(CONFIG_FILE, configFile.getAbsolutePath())); - assertThat(config.getConfigFile(), equalTo(configFile)); + assertThat(config.configFile, equalTo(configFile)); } @Test @@ -151,7 +151,7 @@ public void whenConfigFileOptionIsSetToRelativePath_thenThePathIsPrefixedByAppDa File appDataDir = configFile.getParentFile(); String relativeConfigFilePath = configFile.getName(); Config config = configWithOpts(opt(APP_DATA_DIR, appDataDir), opt(CONFIG_FILE, relativeConfigFilePath)); - assertThat(config.getConfigFile(), equalTo(configFile)); + assertThat(config.configFile, equalTo(configFile)); } @Test @@ -161,22 +161,22 @@ public void whenAppNameIsSetInConfigFile_thenDataDirPropertiesReflectItsValue() writer.println(new ConfigFileOption(APP_NAME, "My-Bisq")); } Config config = configWithOpts(opt(CONFIG_FILE, configFile.getAbsolutePath())); - assertThat(config.getAppName(), equalTo("My-Bisq")); - assertThat(config.getUserDataDir(), equalTo(config.getDefaultUserDataDir())); - assertThat(config.getAppDataDir(), equalTo(new File(config.getUserDataDir(), config.getAppName()))); - assertThat(config.getConfigFile(), equalTo(configFile)); + assertThat(config.appName, equalTo("My-Bisq")); + assertThat(config.userDataDir, equalTo(config.defaultUserDataDir)); + assertThat(config.appDataDir, equalTo(new File(config.userDataDir, config.appName))); + assertThat(config.configFile, equalTo(configFile)); } @Test public void whenBannedBtcNodesOptionIsSet_thenBannedBtcNodesPropertyReturnsItsValue() { Config config = configWithOpts(opt(BANNED_BTC_NODES, "foo.onion:8333,bar.onion:8333")); - assertThat(config.getBannedBtcNodes(), contains("foo.onion:8333", "bar.onion:8333")); + assertThat(config.bannedBtcNodes, contains("foo.onion:8333", "bar.onion:8333")); } @Test public void whenHelpOptionIsSet_thenIsHelpRequestedIsTrue() { - assertFalse(new Config().isHelpRequested()); - assertTrue(configWithOpts(opt(HELP)).isHelpRequested()); + assertFalse(new Config().helpRequested); + assertTrue(configWithOpts(opt(HELP)).helpRequested); } @Test @@ -201,11 +201,11 @@ public void whenConfigIsConstructed_thenNoConsoleOutputSideEffectsShouldOccur() @Test public void whenConfigIsConstructed_thenAppDataDirAndSubdirsAreCreated() { Config config = new Config(); - assertTrue(config.getAppDataDir().exists()); - assertTrue(config.getKeyStorageDir().exists()); - assertTrue(config.getStorageDir().exists()); - assertTrue(config.getTorDir().exists()); - assertTrue(config.getWalletDir().exists()); + assertTrue(config.appDataDir.exists()); + assertTrue(config.keyStorageDir.exists()); + assertTrue(config.storageDir.exists()); + assertTrue(config.torDir.exists()); + assertTrue(config.walletDir.exists()); } @Test diff --git a/core/src/main/java/bisq/core/CoreModule.java b/core/src/main/java/bisq/core/CoreModule.java index 322666e3236..2af3cae3d31 100644 --- a/core/src/main/java/bisq/core/CoreModule.java +++ b/core/src/main/java/bisq/core/CoreModule.java @@ -64,22 +64,22 @@ protected void configure() { bind(SeedNodeRepository.class).to(DefaultSeedNodeRepository.class); - bind(File.class).annotatedWith(named(STORAGE_DIR)).toInstance(config.getStorageDir()); + bind(File.class).annotatedWith(named(STORAGE_DIR)).toInstance(config.storageDir); - CoinFormatter btcFormatter = new ImmutableCoinFormatter(config.getBaseCurrencyNetworkParameters().getMonetaryFormat()); + CoinFormatter btcFormatter = new ImmutableCoinFormatter(config.baseCurrencyNetworkParameters.getMonetaryFormat()); bind(CoinFormatter.class).annotatedWith(named(FormattingUtils.BTC_FORMATTER_KEY)).toInstance(btcFormatter); - bind(File.class).annotatedWith(named(KEY_STORAGE_DIR)).toInstance(config.getKeyStorageDir()); + bind(File.class).annotatedWith(named(KEY_STORAGE_DIR)).toInstance(config.keyStorageDir); bind(NetworkProtoResolver.class).to(CoreNetworkProtoResolver.class); bind(PersistenceProtoResolver.class).to(CorePersistenceProtoResolver.class); - bindConstant().annotatedWith(named(USE_DEV_PRIVILEGE_KEYS)).to(config.isUseDevPrivilegeKeys()); - bindConstant().annotatedWith(named(USE_DEV_MODE)).to(config.isUseDevMode()); - bindConstant().annotatedWith(named(REFERRAL_ID)).to(config.getReferralId()); + bindConstant().annotatedWith(named(USE_DEV_PRIVILEGE_KEYS)).to(config.useDevPrivilegeKeys); + bindConstant().annotatedWith(named(USE_DEV_MODE)).to(config.useDevMode); + bindConstant().annotatedWith(named(REFERRAL_ID)).to(config.referralId); bindConstant().annotatedWith(named(LOCAL_BITCOIN_NODE_PORT)) - .to(config.getBaseCurrencyNetworkParameters().getPort()); + .to(config.baseCurrencyNetworkParameters.getPort()); // ordering is used for shut down sequence diff --git a/core/src/main/java/bisq/core/alert/AlertModule.java b/core/src/main/java/bisq/core/alert/AlertModule.java index 44ae125b357..3f2e11b7eb9 100644 --- a/core/src/main/java/bisq/core/alert/AlertModule.java +++ b/core/src/main/java/bisq/core/alert/AlertModule.java @@ -35,6 +35,6 @@ public AlertModule(Config config) { protected final void configure() { bind(AlertManager.class).in(Singleton.class); bind(PrivateNotificationManager.class).in(Singleton.class); - bindConstant().annotatedWith(named(IGNORE_DEV_MSG)).to(config.isIgnoreDevMsg()); + bindConstant().annotatedWith(named(IGNORE_DEV_MSG)).to(config.ignoreDevMsg); } } diff --git a/core/src/main/java/bisq/core/app/AvoidStandbyModeService.java b/core/src/main/java/bisq/core/app/AvoidStandbyModeService.java index 69f89ba54d6..17d47ebb85c 100644 --- a/core/src/main/java/bisq/core/app/AvoidStandbyModeService.java +++ b/core/src/main/java/bisq/core/app/AvoidStandbyModeService.java @@ -86,7 +86,7 @@ private void play() { InputStream inputStream = null; try { inputStream = getClass().getClassLoader().getResourceAsStream("prevent-app-nap-silent-sound.aiff"); - File soundFile = new File(config.getAppDataDir(), "prevent-app-nap-silent-sound.aiff"); + File soundFile = new File(config.appDataDir, "prevent-app-nap-silent-sound.aiff"); if (!soundFile.exists()) { outputStream = new FileOutputStream(soundFile); IOUtils.copy(inputStream, outputStream); diff --git a/core/src/main/java/bisq/core/app/BisqExecutable.java b/core/src/main/java/bisq/core/app/BisqExecutable.java index cce9c2b23c4..39a9461b510 100644 --- a/core/src/main/java/bisq/core/app/BisqExecutable.java +++ b/core/src/main/java/bisq/core/app/BisqExecutable.java @@ -74,7 +74,7 @@ public BisqExecutable(String fullName, String scriptName, String appName, String public void execute(String[] args) { try { config = new Config(appName, osUserDataDir(), args); - if (config.isHelpRequested()) { + if (config.helpRequested) { config.printHelp(System.out, new BisqHelpFormatter(fullName, scriptName, version)); System.exit(EXIT_SUCCESS); } @@ -148,8 +148,8 @@ protected void applyInjector() { } protected void setupDevEnv() { - DevEnv.setDevMode(config.isUseDevMode()); - DevEnv.setDaoActivated(config.isDaoActivated()); + DevEnv.setDevMode(config.useDevMode); + DevEnv.setDaoActivated(config.daoActivated); } protected void setupPersistedDataHosts(Injector injector) { diff --git a/core/src/main/java/bisq/core/app/BisqSetup.java b/core/src/main/java/bisq/core/app/BisqSetup.java index 4f8547932ac..bd9ef8efe2a 100644 --- a/core/src/main/java/bisq/core/app/BisqSetup.java +++ b/core/src/main/java/bisq/core/app/BisqSetup.java @@ -480,8 +480,8 @@ private void maybeShowTac() { } private void detectLocalBitcoinNode(Runnable nextStep) { - BaseCurrencyNetwork baseCurrencyNetwork = config.getBaseCurrencyNetwork(); - if (config.isIgnoreLocalBtcNode() || baseCurrencyNetwork.isDaoRegTest() || baseCurrencyNetwork.isDaoTestNet()) { + BaseCurrencyNetwork baseCurrencyNetwork = config.baseCurrencyNetwork; + if (config.ignoreLocalBtcNode || baseCurrencyNetwork.isDaoRegTest() || baseCurrencyNetwork.isDaoTestNet()) { nextStep.run(); return; } diff --git a/core/src/main/java/bisq/core/app/SetupUtils.java b/core/src/main/java/bisq/core/app/SetupUtils.java index 69ac7af5c71..c0b3338dcd5 100644 --- a/core/src/main/java/bisq/core/app/SetupUtils.java +++ b/core/src/main/java/bisq/core/app/SetupUtils.java @@ -80,7 +80,7 @@ public static BooleanProperty readFromResources(P2PDataStorage p2PDataStorage, C BooleanProperty result = new SimpleBooleanProperty(); new Thread(() -> { // Used to load different files per base currency (EntryMap_BTC_MAINNET, EntryMap_LTC,...) - final BaseCurrencyNetwork baseCurrencyNetwork = config.getBaseCurrencyNetwork(); + final BaseCurrencyNetwork baseCurrencyNetwork = config.baseCurrencyNetwork; final String postFix = "_" + baseCurrencyNetwork.name(); long ts = new Date().getTime(); p2PDataStorage.readFromResources(postFix); diff --git a/core/src/main/java/bisq/core/app/WalletAppSetup.java b/core/src/main/java/bisq/core/app/WalletAppSetup.java index fd09372d3e0..b567e5c1902 100644 --- a/core/src/main/java/bisq/core/app/WalletAppSetup.java +++ b/core/src/main/java/bisq/core/app/WalletAppSetup.java @@ -177,12 +177,12 @@ void init(@Nullable Consumer chainFileLockedExceptionHandler, private String getBtcNetworkAsString() { String postFix; - if (config.isIgnoreLocalBtcNode()) + if (config.ignoreLocalBtcNode) postFix = " " + Res.get("mainView.footer.localhostBitcoinNode"); else if (preferences.getUseTorForBitcoinJ()) postFix = " " + Res.get("mainView.footer.usingTor"); else postFix = ""; - return Res.get(config.getBaseCurrencyNetwork().name()) + postFix; + return Res.get(config.baseCurrencyNetwork.name()) + postFix; } } diff --git a/core/src/main/java/bisq/core/app/misc/AppSetup.java b/core/src/main/java/bisq/core/app/misc/AppSetup.java index 3607c270c16..213c2b0a270 100644 --- a/core/src/main/java/bisq/core/app/misc/AppSetup.java +++ b/core/src/main/java/bisq/core/app/misc/AppSetup.java @@ -44,7 +44,7 @@ public AppSetup(EncryptionService encryptionService, this.keyRing = keyRing; this.config = config; - Version.setBaseCryptoNetworkId(this.config.getBaseCurrencyNetwork().ordinal()); + Version.setBaseCryptoNetworkId(this.config.baseCurrencyNetwork.ordinal()); Version.printVersion(); } diff --git a/core/src/main/java/bisq/core/app/misc/AppSetupWithP2PAndDAO.java b/core/src/main/java/bisq/core/app/misc/AppSetupWithP2PAndDAO.java index 8d9272ec0b2..8257e47e5ce 100644 --- a/core/src/main/java/bisq/core/app/misc/AppSetupWithP2PAndDAO.java +++ b/core/src/main/java/bisq/core/app/misc/AppSetupWithP2PAndDAO.java @@ -74,7 +74,7 @@ public AppSetupWithP2PAndDAO(EncryptionService encryptionService, this.daoSetup = daoSetup; // TODO Should be refactored/removed. In the meantime keep in sync with CorePersistedDataHost - if (config.isDaoActivated()) { + if (config.daoActivated) { persistedDataHosts.add(myVoteListService); persistedDataHosts.add(ballotListService); persistedDataHosts.add(myBlindVoteListService); diff --git a/core/src/main/java/bisq/core/app/misc/ExecutableForAppWithP2p.java b/core/src/main/java/bisq/core/app/misc/ExecutableForAppWithP2p.java index cde24886317..4f81a94d0d7 100644 --- a/core/src/main/java/bisq/core/app/misc/ExecutableForAppWithP2p.java +++ b/core/src/main/java/bisq/core/app/misc/ExecutableForAppWithP2p.java @@ -136,7 +136,7 @@ protected void startShutDownInterval(GracefulShutDownHandler gracefulShutDownHan } protected void checkMemory(Config config, GracefulShutDownHandler gracefulShutDownHandler) { - int maxMemory = config.getMaxMemory(); + int maxMemory = config.maxMemory; UserThread.runPeriodically(() -> { Profiler.printSystemLoad(log); if (!stopped) { @@ -183,7 +183,7 @@ protected void restart(Config config, GracefulShutDownHandler gracefulShutDownHa gracefulShutDownHandler.gracefulShutDown(() -> { //noinspection finally try { - final String[] tokens = config.getAppDataDir().getPath().split("_"); + final String[] tokens = config.appDataDir.getPath().split("_"); String logPath = "error_" + (tokens.length > 1 ? tokens[tokens.length - 2] : "") + ".log"; RestartUtil.restartApplication(logPath); } catch (IOException e) { diff --git a/core/src/main/java/bisq/core/app/misc/ModuleForAppWithP2p.java b/core/src/main/java/bisq/core/app/misc/ModuleForAppWithP2p.java index 94f04ddbaea..f95d8548e52 100644 --- a/core/src/main/java/bisq/core/app/misc/ModuleForAppWithP2p.java +++ b/core/src/main/java/bisq/core/app/misc/ModuleForAppWithP2p.java @@ -75,15 +75,15 @@ protected void configure() { bind(SeedNodeRepository.class).to(DefaultSeedNodeRepository.class).in(Singleton.class); - bind(File.class).annotatedWith(named(STORAGE_DIR)).toInstance(config.getStorageDir()); - bind(File.class).annotatedWith(named(KEY_STORAGE_DIR)).toInstance(config.getKeyStorageDir()); + bind(File.class).annotatedWith(named(STORAGE_DIR)).toInstance(config.storageDir); + bind(File.class).annotatedWith(named(KEY_STORAGE_DIR)).toInstance(config.keyStorageDir); - bindConstant().annotatedWith(named(USE_DEV_PRIVILEGE_KEYS)).to(config.isUseDevPrivilegeKeys()); - bindConstant().annotatedWith(named(USE_DEV_MODE)).to(config.isUseDevMode()); - bindConstant().annotatedWith(named(REFERRAL_ID)).to(config.getReferralId()); + bindConstant().annotatedWith(named(USE_DEV_PRIVILEGE_KEYS)).to(config.useDevPrivilegeKeys); + bindConstant().annotatedWith(named(USE_DEV_MODE)).to(config.useDevMode); + bindConstant().annotatedWith(named(REFERRAL_ID)).to(config.referralId); bindConstant().annotatedWith(named(LOCAL_BITCOIN_NODE_PORT)) - .to(config.getBaseCurrencyNetworkParameters().getPort()); + .to(config.baseCurrencyNetworkParameters.getPort()); // ordering is used for shut down sequence install(new TradeModule(config)); diff --git a/core/src/main/java/bisq/core/btc/BitcoinModule.java b/core/src/main/java/bisq/core/btc/BitcoinModule.java index ec8f87bf706..c99d24250ab 100644 --- a/core/src/main/java/bisq/core/btc/BitcoinModule.java +++ b/core/src/main/java/bisq/core/btc/BitcoinModule.java @@ -58,11 +58,11 @@ public BitcoinModule(Config config) { protected void configure() { // If we have selected BTC_DAO_REGTEST or BTC_DAO_TESTNET we use our master regtest node, // otherwise the specified host or default (localhost) - String regTestHost = config.getBitcoinRegtestHost(); + String regTestHost = config.bitcoinRegtestHost; if (regTestHost.isEmpty()) { - regTestHost = config.getBaseCurrencyNetwork().isDaoTestNet() ? + regTestHost = config.baseCurrencyNetwork.isDaoTestNet() ? "104.248.31.39" : - config.getBaseCurrencyNetwork().isDaoRegTest() ? + config.baseCurrencyNetwork.isDaoRegTest() ? "134.209.242.206" : Config.DEFAULT_REGTEST_HOST; } @@ -76,15 +76,15 @@ protected void configure() { bind(RegTestHost.class).toInstance(RegTestHost.REMOTE_HOST); } - bind(File.class).annotatedWith(named(WALLET_DIR)).toInstance(config.getWalletDir()); + bind(File.class).annotatedWith(named(WALLET_DIR)).toInstance(config.walletDir); - bindConstant().annotatedWith(named(Config.BTC_NODES)).to(config.getBtcNodes()); - bindConstant().annotatedWith(named(Config.USER_AGENT)).to(config.getUserAgent()); - bindConstant().annotatedWith(named(Config.NUM_CONNECTIONS_FOR_BTC)).to(config.getNumConnectionsForBtc()); - bindConstant().annotatedWith(named(Config.USE_ALL_PROVIDED_NODES)).to(config.isUseAllProvidedNodes()); - bindConstant().annotatedWith(named(Config.IGNORE_LOCAL_BTC_NODE)).to(config.isIgnoreLocalBtcNode()); - bindConstant().annotatedWith(Names.named(Config.SOCKS5_DISCOVER_MODE)).to(config.getSocks5DiscoverMode()); - bind(new TypeLiteral>(){}).annotatedWith(named(PROVIDERS)).toInstance(config.getProviders()); + bindConstant().annotatedWith(named(Config.BTC_NODES)).to(config.btcNodes); + bindConstant().annotatedWith(named(Config.USER_AGENT)).to(config.userAgent); + bindConstant().annotatedWith(named(Config.NUM_CONNECTIONS_FOR_BTC)).to(config.numConnectionsForBtc); + bindConstant().annotatedWith(named(Config.USE_ALL_PROVIDED_NODES)).to(config.useAllProvidedNodes); + bindConstant().annotatedWith(named(Config.IGNORE_LOCAL_BTC_NODE)).to(config.ignoreLocalBtcNode); + bindConstant().annotatedWith(Names.named(Config.SOCKS5_DISCOVER_MODE)).to(config.socks5DiscoverMode); + bind(new TypeLiteral>(){}).annotatedWith(named(PROVIDERS)).toInstance(config.providers); bind(AddressEntryList.class).in(Singleton.class); bind(WalletsSetup.class).in(Singleton.class); diff --git a/core/src/main/java/bisq/core/btc/nodes/LocalBitcoinNode.java b/core/src/main/java/bisq/core/btc/nodes/LocalBitcoinNode.java index 58ac4396be3..d98023ddedf 100644 --- a/core/src/main/java/bisq/core/btc/nodes/LocalBitcoinNode.java +++ b/core/src/main/java/bisq/core/btc/nodes/LocalBitcoinNode.java @@ -13,7 +13,7 @@ /** * Detects whether a Bitcoin node is running on localhost. - * @see bisq.common.config.Config#isIgnoreLocalBtcNode() + * @see bisq.common.config.Config#ignoreLocalBtcNode */ public class LocalBitcoinNode { diff --git a/core/src/main/java/bisq/core/btc/setup/WalletConfig.java b/core/src/main/java/bisq/core/btc/setup/WalletConfig.java index a129a731fe4..237d8709b97 100644 --- a/core/src/main/java/bisq/core/btc/setup/WalletConfig.java +++ b/core/src/main/java/bisq/core/btc/setup/WalletConfig.java @@ -229,7 +229,7 @@ private PeerGroup createPeerGroup() { ProxySocketFactory proxySocketFactory = new ProxySocketFactory(proxy); // We don't use tor mode if we have a local node running - BlockingClientManager blockingClientManager = config.isIgnoreLocalBtcNode() ? + BlockingClientManager blockingClientManager = config.ignoreLocalBtcNode ? new BlockingClientManager() : new BlockingClientManager(proxySocketFactory); diff --git a/core/src/main/java/bisq/core/btc/setup/WalletsSetup.java b/core/src/main/java/bisq/core/btc/setup/WalletsSetup.java index 2e60b5f2d4c..f9af354b3b8 100644 --- a/core/src/main/java/bisq/core/btc/setup/WalletsSetup.java +++ b/core/src/main/java/bisq/core/btc/setup/WalletsSetup.java @@ -162,7 +162,7 @@ public WalletsSetup(RegTestHost regTestHost, this.socks5DiscoverMode = evaluateMode(socks5DiscoverModeString); this.walletDir = walletDir; - btcWalletFileName = "bisq_" + config.getBaseCurrencyNetwork().getCurrencyCode() + ".wallet"; + btcWalletFileName = "bisq_" + config.baseCurrencyNetwork.getCurrencyCode() + ".wallet"; params = Config.baseCurrencyNetworkParameters(); PeerGroup.setIgnoreHttpSeeds(true); } diff --git a/core/src/main/java/bisq/core/dao/DaoModule.java b/core/src/main/java/bisq/core/dao/DaoModule.java index eceb61c1447..ad8f2c30efc 100644 --- a/core/src/main/java/bisq/core/dao/DaoModule.java +++ b/core/src/main/java/bisq/core/dao/DaoModule.java @@ -195,9 +195,9 @@ protected void configure() { bind(RepublishGovernanceDataHandler.class).in(Singleton.class); // Genesis - bindConstant().annotatedWith(named(Config.GENESIS_TX_ID)).to(config.getGenesisTxId()); - bindConstant().annotatedWith(named(Config.GENESIS_BLOCK_HEIGHT)).to(config.getGenesisBlockHeight()); - bindConstant().annotatedWith(named(Config.GENESIS_TOTAL_SUPPLY)).to(config.getGenesisTotalSupply()); + bindConstant().annotatedWith(named(Config.GENESIS_TX_ID)).to(config.genesisTxId); + bindConstant().annotatedWith(named(Config.GENESIS_BLOCK_HEIGHT)).to(config.genesisBlockHeight); + bindConstant().annotatedWith(named(Config.GENESIS_TOTAL_SUPPLY)).to(config.genesisTotalSupply); // Bonds bind(LockupTxService.class).in(Singleton.class); @@ -215,15 +215,15 @@ protected void configure() { bind(MyProofOfBurnListService.class).in(Singleton.class); // Options - bindConstant().annotatedWith(named(Config.RPC_USER)).to(config.getRpcUser()); - bindConstant().annotatedWith(named(Config.RPC_PASSWORD)).to(config.getRpcPassword()); - bindConstant().annotatedWith(named(Config.RPC_HOST)).to(config.getRpcHost()); - bindConstant().annotatedWith(named(Config.RPC_PORT)).to(config.getRpcPort()); - bindConstant().annotatedWith(named(Config.RPC_BLOCK_NOTIFICATION_PORT)).to(config.getRpcBlockNotificationPort()); - bindConstant().annotatedWith(named(Config.RPC_BLOCK_NOTIFICATION_HOST)).to(config.getRpcBlockNotificationHost()); - bindConstant().annotatedWith(named(Config.DUMP_BLOCKCHAIN_DATA)).to(config.isDumpBlockchainData()); - bindConstant().annotatedWith(named(Config.FULL_DAO_NODE)).to(config.isFullDaoNode()); - bindConstant().annotatedWith(named(Config.DAO_ACTIVATED)).to(config.isDaoActivated()); + bindConstant().annotatedWith(named(Config.RPC_USER)).to(config.rpcUser); + bindConstant().annotatedWith(named(Config.RPC_PASSWORD)).to(config.rpcPassword); + bindConstant().annotatedWith(named(Config.RPC_HOST)).to(config.rpcHost); + bindConstant().annotatedWith(named(Config.RPC_PORT)).to(config.rpcPort); + bindConstant().annotatedWith(named(Config.RPC_BLOCK_NOTIFICATION_PORT)).to(config.rpcBlockNotificationPort); + bindConstant().annotatedWith(named(Config.RPC_BLOCK_NOTIFICATION_HOST)).to(config.rpcBlockNotificationHost); + bindConstant().annotatedWith(named(Config.DUMP_BLOCKCHAIN_DATA)).to(config.dumpBlockchainData); + bindConstant().annotatedWith(named(Config.FULL_DAO_NODE)).to(config.fullDaoNode); + bindConstant().annotatedWith(named(Config.DAO_ACTIVATED)).to(config.daoActivated); } } diff --git a/core/src/main/java/bisq/core/dao/governance/blindvote/BlindVoteListService.java b/core/src/main/java/bisq/core/dao/governance/blindvote/BlindVoteListService.java index fd46243d70c..4ed289d8813 100644 --- a/core/src/main/java/bisq/core/dao/governance/blindvote/BlindVoteListService.java +++ b/core/src/main/java/bisq/core/dao/governance/blindvote/BlindVoteListService.java @@ -75,7 +75,7 @@ public BlindVoteListService(DaoStateService daoStateService, this.blindVoteStorageService = blindVoteStorageService; this.blindVoteValidator = blindVoteValidator; - if (config.isDaoActivated()) + if (config.daoActivated) appendOnlyDataStoreService.addService(blindVoteStorageService); } diff --git a/core/src/main/java/bisq/core/filter/FilterManager.java b/core/src/main/java/bisq/core/filter/FilterManager.java index ecdcea44d01..65711143d99 100644 --- a/core/src/main/java/bisq/core/filter/FilterManager.java +++ b/core/src/main/java/bisq/core/filter/FilterManager.java @@ -115,7 +115,7 @@ public FilterManager(P2PService p2PService, this.keyRing = keyRing; this.user = user; this.preferences = preferences; - this.configFileEditor = new ConfigFileEditor(config.getConfigFile()); + this.configFileEditor = new ConfigFileEditor(config.configFile); this.providersRepository = providersRepository; this.ignoreDevMsg = ignoreDevMsg; pubKeyAsHex = useDevPrivilegeKeys ? diff --git a/core/src/main/java/bisq/core/filter/FilterModule.java b/core/src/main/java/bisq/core/filter/FilterModule.java index caf318f46be..d676ef65a88 100644 --- a/core/src/main/java/bisq/core/filter/FilterModule.java +++ b/core/src/main/java/bisq/core/filter/FilterModule.java @@ -34,6 +34,6 @@ public FilterModule(Config config) { @Override protected final void configure() { bind(FilterManager.class).in(Singleton.class); - bindConstant().annotatedWith(named(IGNORE_DEV_MSG)).to(config.isIgnoreDevMsg()); + bindConstant().annotatedWith(named(IGNORE_DEV_MSG)).to(config.ignoreDevMsg); } } diff --git a/core/src/main/java/bisq/core/network/p2p/seed/DefaultSeedNodeRepository.java b/core/src/main/java/bisq/core/network/p2p/seed/DefaultSeedNodeRepository.java index c7f27ce026e..f526cd0d5e8 100644 --- a/core/src/main/java/bisq/core/network/p2p/seed/DefaultSeedNodeRepository.java +++ b/core/src/main/java/bisq/core/network/p2p/seed/DefaultSeedNodeRepository.java @@ -55,15 +55,15 @@ public DefaultSeedNodeRepository(Config config) { private void reload() { try { // see if there are any seed nodes configured manually - if (!config.getSeedNodes().isEmpty()) { + if (!config.seedNodes.isEmpty()) { cache.clear(); - config.getSeedNodes().forEach(s -> cache.add(new NodeAddress(s))); + config.seedNodes.forEach(s -> cache.add(new NodeAddress(s))); return; } // else, we fetch the seed nodes from our resources - InputStream fileInputStream = DefaultSeedNodeRepository.class.getClassLoader().getResourceAsStream(config.getBaseCurrencyNetwork().name().toLowerCase() + ENDING); + InputStream fileInputStream = DefaultSeedNodeRepository.class.getClassLoader().getResourceAsStream(config.baseCurrencyNetwork.name().toLowerCase() + ENDING); BufferedReader seedNodeFile = new BufferedReader(new InputStreamReader(fileInputStream)); // only clear if we have a fresh data source (otherwise, an exception would prevent us from getting here) @@ -81,7 +81,7 @@ private void reload() { }); // filter - cache.removeAll(config.getBannedSeedNodes().stream().map(NodeAddress::new).collect(Collectors.toSet())); + cache.removeAll(config.bannedSeedNodes.stream().map(NodeAddress::new).collect(Collectors.toSet())); log.info("Seed nodes: {}", cache); } catch (Throwable t) { diff --git a/core/src/main/java/bisq/core/provider/ProvidersRepository.java b/core/src/main/java/bisq/core/provider/ProvidersRepository.java index c2c7467b39f..421f740b8fb 100644 --- a/core/src/main/java/bisq/core/provider/ProvidersRepository.java +++ b/core/src/main/java/bisq/core/provider/ProvidersRepository.java @@ -71,7 +71,7 @@ public ProvidersRepository(Config config, Collections.shuffle(DEFAULT_NODES); - applyBannedNodes(config.getBannedPriceRelayNodes()); + applyBannedNodes(config.bannedPriceRelayNodes); } public void applyBannedNodes(@Nullable List bannedNodes) { @@ -94,7 +94,7 @@ public void selectNextProviderBaseUrl() { baseUrl = providerList.get(index); index++; - if (providerList.size() == 1 && config.getBaseCurrencyNetwork().isMainnet()) + if (providerList.size() == 1 && config.baseCurrencyNetwork.isMainnet()) log.warn("We only have one provider"); } else { baseUrl = ""; diff --git a/core/src/main/java/bisq/core/setup/CoreNetworkCapabilities.java b/core/src/main/java/bisq/core/setup/CoreNetworkCapabilities.java index 9a75f04eb8a..fcd03280337 100644 --- a/core/src/main/java/bisq/core/setup/CoreNetworkCapabilities.java +++ b/core/src/main/java/bisq/core/setup/CoreNetworkCapabilities.java @@ -42,7 +42,7 @@ static void setSupportedCapabilities(Config config) { Capability.TRADE_STATISTICS_HASH_UPDATE ); - if (config.isDaoActivated()) { + if (config.daoActivated) { maybeApplyDaoFullMode(config); } } @@ -51,7 +51,7 @@ public static void maybeApplyDaoFullMode(Config config) { // If we set dao full mode at the preferences view we add the capability there. We read the preferences a // bit later than we call that method so we have to add DAO_FULL_NODE Capability at preferences as well to // be sure it is set in both cases. - if (config.isFullDaoNode()) { + if (config.fullDaoNode) { log.info("Set Capability.DAO_FULL_NODE"); Capabilities.app.addAll(Capability.DAO_FULL_NODE); } else { diff --git a/core/src/main/java/bisq/core/setup/CorePersistedDataHost.java b/core/src/main/java/bisq/core/setup/CorePersistedDataHost.java index 9b65b03b7a0..426504a4073 100644 --- a/core/src/main/java/bisq/core/setup/CorePersistedDataHost.java +++ b/core/src/main/java/bisq/core/setup/CorePersistedDataHost.java @@ -65,7 +65,7 @@ public static List getPersistedDataHosts(Injector injector) { persistedDataHosts.add(injector.getInstance(RefundDisputeListService.class)); persistedDataHosts.add(injector.getInstance(P2PService.class)); - if (injector.getInstance(Config.class).isDaoActivated()) { + if (injector.getInstance(Config.class).daoActivated) { persistedDataHosts.add(injector.getInstance(BallotListService.class)); persistedDataHosts.add(injector.getInstance(MyBlindVoteListService.class)); persistedDataHosts.add(injector.getInstance(MyVoteListService.class)); diff --git a/core/src/main/java/bisq/core/setup/CoreSetup.java b/core/src/main/java/bisq/core/setup/CoreSetup.java index 0e580e7af6d..68a77a66709 100644 --- a/core/src/main/java/bisq/core/setup/CoreSetup.java +++ b/core/src/main/java/bisq/core/setup/CoreSetup.java @@ -42,7 +42,7 @@ public static void setup(Config config) { Res.setup(); CurrencyUtil.setup(); - Version.setBaseCryptoNetworkId(config.getBaseCurrencyNetwork().ordinal()); + Version.setBaseCryptoNetworkId(config.baseCurrencyNetwork.ordinal()); Version.printVersion(); try { @@ -56,10 +56,10 @@ public static void setup(Config config) { } private static void setupLog(Config config) { - String logPath = Paths.get(config.getAppDataDir().getPath(), "bisq").toString(); + String logPath = Paths.get(config.appDataDir.getPath(), "bisq").toString(); Log.setup(logPath); log.info("\n\n\nLog files under: " + logPath); Utilities.printSysInfo(); - Log.setLevel(Level.toLevel(config.getLogLevel())); + Log.setLevel(Level.toLevel(config.logLevel)); } } diff --git a/core/src/main/java/bisq/core/trade/TradeModule.java b/core/src/main/java/bisq/core/trade/TradeModule.java index 52d2a0e11b8..604424debec 100644 --- a/core/src/main/java/bisq/core/trade/TradeModule.java +++ b/core/src/main/java/bisq/core/trade/TradeModule.java @@ -55,6 +55,6 @@ protected void configure() { bind(SignedWitnessStorageService.class).in(Singleton.class); bind(ReferralIdService.class).in(Singleton.class); bind(AssetTradeActivityCheck.class).in(Singleton.class); - bindConstant().annotatedWith(named(DUMP_STATISTICS)).to(config.isDumpStatistics()); + bindConstant().annotatedWith(named(DUMP_STATISTICS)).to(config.dumpStatistics); } } diff --git a/core/src/main/java/bisq/core/user/Preferences.java b/core/src/main/java/bisq/core/user/Preferences.java index aefe4ea3d21..08d9e0edbaa 100644 --- a/core/src/main/java/bisq/core/user/Preferences.java +++ b/core/src/main/java/bisq/core/user/Preferences.java @@ -271,8 +271,8 @@ public void readPersisted() { dontShowAgainMapAsObservable.putAll(getDontShowAgainMap()); // Override settings with options if set - if (config.isUseTorForBtcOptionSetExplicitly()) - setUseTorForBitcoinJ(config.isUseTorForBtc()); + if (config.useTorForBtcOptionSetExplicitly) + setUseTorForBitcoinJ(config.useTorForBtc); if (btcNodesFromOptions != null && !btcNodesFromOptions.isEmpty()) { if (getBitcoinNodes() != null && !getBitcoinNodes().equals(btcNodesFromOptions)) { @@ -629,7 +629,7 @@ public void setTakeOfferSelectedPaymentAccountId(String value) { public void setDaoFullNode(boolean value) { // We only persist if we have not set the program argument - if (config.isFullDaoNodeOptionSetExplicitly()) { + if (config.fullDaoNodeOptionSetExplicitly) { prefPayload.setDaoFullNode(value); persist(); } @@ -741,7 +741,7 @@ public boolean getUseTorForBitcoinJ() { // On testnet there are very few Bitcoin tor nodes and we don't provide tor nodes. if ((!Config.baseCurrencyNetwork().isMainnet() || localBitcoinNode.isDetected()) - && !config.isUseTorForBtcOptionSetExplicitly()) + && !config.useTorForBtcOptionSetExplicitly) return false; else return prefPayload.isUseTorForBitcoinJ(); @@ -775,7 +775,7 @@ public long getWithdrawalTxFeeInBytes() { } public boolean isDaoFullNode() { - if (config.isFullDaoNodeOptionSetExplicitly()) { + if (config.fullDaoNodeOptionSetExplicitly) { return fullDaoNodeFromOptions; } else { return prefPayload.isDaoFullNode(); diff --git a/core/src/test/java/bisq/core/user/PreferencesTest.java b/core/src/test/java/bisq/core/user/PreferencesTest.java index ef4f2cb0350..4c8f89b95de 100644 --- a/core/src/test/java/bisq/core/user/PreferencesTest.java +++ b/core/src/test/java/bisq/core/user/PreferencesTest.java @@ -60,7 +60,7 @@ public void setUp() { storage = mock(Storage.class); Config config = new Config(); - LocalBitcoinNode localBitcoinNode = new LocalBitcoinNode(config.getBaseCurrencyNetworkParameters().getPort()); + LocalBitcoinNode localBitcoinNode = new LocalBitcoinNode(config.baseCurrencyNetworkParameters.getPort()); preferences = new Preferences( storage, config, localBitcoinNode, null, null, Config.DEFAULT_FULL_DAO_NODE, null, null, Config.UNSPECIFIED_PORT); diff --git a/desktop/src/main/java/bisq/desktop/DesktopModule.java b/desktop/src/main/java/bisq/desktop/DesktopModule.java index 0829d1a0fa8..c688c866bf1 100644 --- a/desktop/src/main/java/bisq/desktop/DesktopModule.java +++ b/desktop/src/main/java/bisq/desktop/DesktopModule.java @@ -47,6 +47,6 @@ protected void configure() { bind(ResourceBundle.class).toInstance(Res.getResourceBundle()); bind(ViewLoader.class).to(FxmlViewLoader.class).in(Singleton.class); - bindConstant().annotatedWith(Names.named(APP_NAME)).to(config.getAppName()); + bindConstant().annotatedWith(Names.named(APP_NAME)).to(config.appName); } } diff --git a/desktop/src/main/java/bisq/desktop/main/MainViewModel.java b/desktop/src/main/java/bisq/desktop/main/MainViewModel.java index 4b066ba4b2e..6e1b167a45a 100644 --- a/desktop/src/main/java/bisq/desktop/main/MainViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/MainViewModel.java @@ -372,7 +372,7 @@ private void setupHandlers() { bisqSetup.setRejectedTxErrorMessageHandler(msg -> new Popup().width(850).warning(msg).show()); corruptedDatabaseFilesHandler.getCorruptedDatabaseFiles().ifPresent(files -> new Popup() - .warning(Res.get("popup.warning.incompatibleDB", files.toString(), config.getAppDataDir())) + .warning(Res.get("popup.warning.incompatibleDB", files.toString(), config.appDataDir)) .useShutDownButton() .show()); diff --git a/desktop/src/main/java/bisq/desktop/main/account/content/backup/BackupView.java b/desktop/src/main/java/bisq/desktop/main/account/content/backup/BackupView.java index a83f842b415..2e72c73a968 100644 --- a/desktop/src/main/java/bisq/desktop/main/account/content/backup/BackupView.java +++ b/desktop/src/main/java/bisq/desktop/main/account/content/backup/BackupView.java @@ -75,7 +75,7 @@ public class BackupView extends ActivatableView { private BackupView(Preferences preferences, Config config) { super(); this.preferences = preferences; - dataDir = new File(config.getAppDataDir().getPath()); + dataDir = new File(config.appDataDir.getPath()); logFile = new File(Paths.get(dataDir.getPath(), "bisq.log").toString()); } diff --git a/desktop/src/main/java/bisq/desktop/main/overlays/windows/downloadupdate/DisplayUpdateDownloadWindow.java b/desktop/src/main/java/bisq/desktop/main/overlays/windows/downloadupdate/DisplayUpdateDownloadWindow.java index 95566347e3d..1a2015fe95e 100644 --- a/desktop/src/main/java/bisq/desktop/main/overlays/windows/downloadupdate/DisplayUpdateDownloadWindow.java +++ b/desktop/src/main/java/bisq/desktop/main/overlays/windows/downloadupdate/DisplayUpdateDownloadWindow.java @@ -292,7 +292,7 @@ private void copyJarHashToDataDir(BisqInstaller.FileDescriptor fileDescriptor) { scanner.close(); final String hashOfJar = sb.toString(); - Path path = Paths.get(config.getAppDataDir().getPath(), fileDescriptor.getFileName()); + Path path = Paths.get(config.appDataDir.getPath(), fileDescriptor.getFileName()); final String target = path.toString(); try (PrintWriter writer = new PrintWriter(target, "UTF-8")) { writer.println(hashOfJar); diff --git a/desktop/src/main/java/bisq/desktop/main/settings/preferences/PreferencesView.java b/desktop/src/main/java/bisq/desktop/main/settings/preferences/PreferencesView.java index dc273cf9dbe..cfdb8080ce6 100644 --- a/desktop/src/main/java/bisq/desktop/main/settings/preferences/PreferencesView.java +++ b/desktop/src/main/java/bisq/desktop/main/settings/preferences/PreferencesView.java @@ -168,7 +168,7 @@ public PreferencesView(PreferencesViewModel model, this.assetService = assetService; this.filterManager = filterManager; this.daoFacade = daoFacade; - daoOptionsSet = config.isFullDaoNodeOptionSetExplicitly() && + daoOptionsSet = config.fullDaoNodeOptionSetExplicitly && !rpcUser.isEmpty() && !rpcPassword.isEmpty() && rpcBlockNotificationPort != Config.UNSPECIFIED_PORT; diff --git a/p2p/src/main/java/bisq/network/p2p/P2PModule.java b/p2p/src/main/java/bisq/network/p2p/P2PModule.java index 3908d52a28d..7f00ba60673 100644 --- a/p2p/src/main/java/bisq/network/p2p/P2PModule.java +++ b/p2p/src/main/java/bisq/network/p2p/P2PModule.java @@ -75,24 +75,24 @@ protected void configure() { requestStaticInjection(Connection.class); - bindConstant().annotatedWith(Names.named(USE_LOCALHOST_FOR_P2P)).to(config.isUseLocalhostForP2P()); + bindConstant().annotatedWith(Names.named(USE_LOCALHOST_FOR_P2P)).to(config.useLocalhostForP2P); - bind(File.class).annotatedWith(named(TOR_DIR)).toInstance(config.getTorDir()); + bind(File.class).annotatedWith(named(TOR_DIR)).toInstance(config.torDir); - bind(int.class).annotatedWith(Names.named(NODE_PORT)).toInstance(config.getNodePort()); + bind(int.class).annotatedWith(Names.named(NODE_PORT)).toInstance(config.nodePort); - bindConstant().annotatedWith(named(MAX_CONNECTIONS)).to(config.getMaxConnections()); + bindConstant().annotatedWith(named(MAX_CONNECTIONS)).to(config.maxConnections); - bind(new TypeLiteral>(){}).annotatedWith(named(BAN_LIST)).toInstance(config.getBanList()); - bindConstant().annotatedWith(named(SOCKS_5_PROXY_BTC_ADDRESS)).to(config.getSocks5ProxyBtcAddress()); - bindConstant().annotatedWith(named(SOCKS_5_PROXY_HTTP_ADDRESS)).to(config.getSocks5ProxyHttpAddress()); - bind(File.class).annotatedWith(named(TORRC_FILE)).toProvider(of(config.getTorrcFile())); // allow null value - bindConstant().annotatedWith(named(TORRC_OPTIONS)).to(config.getTorrcOptions()); - bindConstant().annotatedWith(named(TOR_CONTROL_PORT)).to(config.getTorControlPort()); - bindConstant().annotatedWith(named(TOR_CONTROL_PASSWORD)).to(config.getTorControlPassword()); - bind(File.class).annotatedWith(named(TOR_CONTROL_COOKIE_FILE)).toProvider(of(config.getTorControlCookieFile())); - bindConstant().annotatedWith(named(TOR_CONTROL_USE_SAFE_COOKIE_AUTH)).to(config.isUseTorControlSafeCookieAuth()); - bindConstant().annotatedWith(named(TOR_STREAM_ISOLATION)).to(config.isTorStreamIsolation()); + bind(new TypeLiteral>(){}).annotatedWith(named(BAN_LIST)).toInstance(config.banList); + bindConstant().annotatedWith(named(SOCKS_5_PROXY_BTC_ADDRESS)).to(config.socks5ProxyBtcAddress); + bindConstant().annotatedWith(named(SOCKS_5_PROXY_HTTP_ADDRESS)).to(config.socks5ProxyHttpAddress); + bind(File.class).annotatedWith(named(TORRC_FILE)).toProvider(of(config.torrcFile)); // allow null value + bindConstant().annotatedWith(named(TORRC_OPTIONS)).to(config.torrcOptions); + bindConstant().annotatedWith(named(TOR_CONTROL_PORT)).to(config.torControlPort); + bindConstant().annotatedWith(named(TOR_CONTROL_PASSWORD)).to(config.torControlPassword); + bind(File.class).annotatedWith(named(TOR_CONTROL_COOKIE_FILE)).toProvider(of(config.torControlCookieFile)); + bindConstant().annotatedWith(named(TOR_CONTROL_USE_SAFE_COOKIE_AUTH)).to(config.useTorControlSafeCookieAuth); + bindConstant().annotatedWith(named(TOR_STREAM_ISOLATION)).to(config.torStreamIsolation); bindConstant().annotatedWith(named("MAX_SEQUENCE_NUMBER_MAP_SIZE_BEFORE_PURGE")).to(1000); } } diff --git a/p2p/src/main/java/bisq/network/p2p/network/Connection.java b/p2p/src/main/java/bisq/network/p2p/network/Connection.java index 772a4b032d6..fc515a87967 100644 --- a/p2p/src/main/java/bisq/network/p2p/network/Connection.java +++ b/p2p/src/main/java/bisq/network/p2p/network/Connection.java @@ -262,10 +262,10 @@ public void sendMessage(NetworkEnvelope networkEnvelope) { // Throttle outbound network_messages long now = System.currentTimeMillis(); long elapsed = now - lastSendTimeStamp; - if (elapsed < config.getSendMsgThrottleTrigger()) { + if (elapsed < config.sendMsgThrottleTrigger) { log.debug("We got 2 sendMessage requests in less than {} ms. We set the thread to sleep " + "for {} ms to avoid flooding our peer. lastSendTimeStamp={}, now={}, elapsed={}, networkEnvelope={}", - config.getSendMsgThrottleTrigger(), config.getSendMsgThrottleSleep(), lastSendTimeStamp, now, elapsed, + config.sendMsgThrottleTrigger, config.sendMsgThrottleSleep, lastSendTimeStamp, now, elapsed, networkEnvelope.getClass().getSimpleName()); // check if BundleOfEnvelopes is supported @@ -278,7 +278,7 @@ public void sendMessage(NetworkEnvelope networkEnvelope) { queueOfBundles.add(new BundleOfEnvelopes()); // - and schedule it for sending - lastSendTimeStamp += config.getSendMsgThrottleSleep(); + lastSendTimeStamp += config.sendMsgThrottleSleep; bundleSender.schedule(() -> { if (!stopped) { @@ -302,7 +302,7 @@ public void sendMessage(NetworkEnvelope networkEnvelope) { return; } - Thread.sleep(config.getSendMsgThrottleSleep()); + Thread.sleep(config.sendMsgThrottleSleep); } lastSendTimeStamp = now; @@ -375,11 +375,11 @@ private boolean violatesThrottleLimit() { messageTimeStamps.add(now); // clean list - while (messageTimeStamps.size() > config.getMsgThrottlePer10Sec()) + while (messageTimeStamps.size() > config.msgThrottlePer10Sec) messageTimeStamps.remove(0); - return violatesThrottleLimit(now, 1, config.getMsgThrottlePerSec()) || - violatesThrottleLimit(now, 10, config.getMsgThrottlePer10Sec()); + return violatesThrottleLimit(now, 1, config.msgThrottlePerSec) || + violatesThrottleLimit(now, 10, config.msgThrottlePer10Sec); } private boolean violatesThrottleLimit(long now, int seconds, int messageCountLimit) {