mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 07:07:43 +01:00
read preferred crypto network from property file
This commit is contained in:
parent
d50ff6c6dc
commit
a61a350ec7
10 changed files with 188 additions and 80 deletions
|
@ -84,11 +84,11 @@ public class Version {
|
|||
return p2pMessageVersion;
|
||||
}
|
||||
|
||||
// The version for the bitcoin network (Mainnet = 0, TestNet = 1, Regtest = 2)
|
||||
// The version for the crypto network (BTC_Mainnet = 0, BTC_TestNet = 1, BTC_Regtest = 2, ...)
|
||||
private static int CRYPTO_NETWORK_ID;
|
||||
|
||||
public static void setBaseCryptoNetworkId(int btcNetworkId) {
|
||||
CRYPTO_NETWORK_ID = btcNetworkId;
|
||||
public static void setBaseCryptoNetworkId(int baseCryptoNetworkId) {
|
||||
CRYPTO_NETWORK_ID = baseCryptoNetworkId;
|
||||
|
||||
// CRYPTO_NETWORK_ID is 0, 1 or 2, we use for changes at NETWORK_PROTOCOL_VERSION a multiplication with 10
|
||||
// to avoid conflicts:
|
||||
|
|
|
@ -49,12 +49,20 @@ public class ProtoUtil {
|
|||
return "".equals(stringFromProto) ? null : stringFromProto;
|
||||
}
|
||||
|
||||
public static <E extends Enum<E>> E enumFromProto(Class<E> e, String id) {
|
||||
/**
|
||||
* Get a Java enum from a Protobuf enum in a safe way.
|
||||
*
|
||||
* @param enumType the class of the enum, e.g: BlaEnum.class
|
||||
* @param name the name of the enum entry, e.g: proto.getWinner().name()
|
||||
* @param <E> the enum Type
|
||||
* @return an enum
|
||||
*/
|
||||
public static <E extends Enum<E>> E enumFromProto(Class<E> enumType, String name) {
|
||||
E result = null;
|
||||
try {
|
||||
result = Enum.valueOf(e, id);
|
||||
result = Enum.valueOf(enumType, name);
|
||||
} catch (IllegalArgumentException err) {
|
||||
log.error("Invalid value for enum " + e.getSimpleName() + ": " + id, err);
|
||||
log.error("Invalid value for enum " + enumType.getSimpleName() + ": " + name, err);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -1335,11 +1335,17 @@ formatter.asTaker={0} {1} as taker
|
|||
# we use enum values here
|
||||
# dynamic values are not recognized by IntelliJ
|
||||
# suppress inspection "UnusedProperty"
|
||||
MAINNET=Mainnet
|
||||
BTC_MAINNET=Bitcoin Mainnet
|
||||
# suppress inspection "UnusedProperty"
|
||||
TESTNET=Testnet
|
||||
BTC_TESTNET=Bitcoin Testnet
|
||||
# suppress inspection "UnusedProperty"
|
||||
REGTEST=Regtest
|
||||
BTC_REGTEST=Bitcoin Regtest
|
||||
|
||||
LTC_MAINNET=Litecoin Mainnet
|
||||
# suppress inspection "UnusedProperty"
|
||||
LTC_TESTNET=Litecoin Testnet
|
||||
# suppress inspection "UnusedProperty"
|
||||
LTC_REGTEST=Litecoin Regtest
|
||||
|
||||
time.year=Year
|
||||
time.month=Month
|
||||
|
|
|
@ -91,7 +91,7 @@ public class BisqEnvironment extends StandardEnvironment {
|
|||
File file = resource.getFile();
|
||||
Properties properties = new Properties();
|
||||
if (file.exists()) {
|
||||
Object propertiesObject = appDirProperties().getSource();
|
||||
Object propertiesObject = getAppDirProperties().getSource();
|
||||
if (propertiesObject instanceof Properties) {
|
||||
properties = (Properties) propertiesObject;
|
||||
} else {
|
||||
|
@ -199,6 +199,7 @@ public class BisqEnvironment extends StandardEnvironment {
|
|||
MutablePropertySources propertySources = this.getPropertySources();
|
||||
propertySources.addFirst(commandLineProperties);
|
||||
try {
|
||||
propertySources.addLast(getAppDirProperties());
|
||||
baseCryptoNetwork = BaseCryptoNetwork.valueOf(getProperty(BtcOptionKeys.BASE_CRYPTO_NETWORK,
|
||||
BaseCryptoNetwork.DEFAULT.name()).toUpperCase());
|
||||
btcNetworkDir = Paths.get(appDataDir, baseCryptoNetwork.name().toLowerCase()).toString();
|
||||
|
@ -218,7 +219,7 @@ public class BisqEnvironment extends StandardEnvironment {
|
|||
return resourceLoader.getResource(location);
|
||||
}
|
||||
|
||||
PropertySource<?> appDirProperties() throws Exception {
|
||||
PropertySource<?> getAppDirProperties() throws Exception {
|
||||
Resource resource = getAppDirPropertiesResource();
|
||||
|
||||
if (!resource.exists())
|
||||
|
|
|
@ -26,22 +26,27 @@ import org.libdohj.params.LitecoinRegTestParams;
|
|||
import org.libdohj.params.LitecoinTestNet3Params;
|
||||
|
||||
public enum BaseCryptoNetwork {
|
||||
BTC_MAINNET(MainNetParams.get()),
|
||||
BTC_TESTNET(TestNet3Params.get()),
|
||||
BTC_REGTEST(RegTestParams.get()),
|
||||
LTC_MAINNET(LitecoinMainNetParams.get()),
|
||||
LTC_TESTNET(LitecoinTestNet3Params.get()),
|
||||
LTC_REGTEST(LitecoinRegTestParams.get());
|
||||
BTC_MAINNET(MainNetParams.get(), "BTC", "MAINNET"),
|
||||
BTC_TESTNET(TestNet3Params.get(), "BTC", "TESTNET"),
|
||||
BTC_REGTEST(RegTestParams.get(), "BTC", "REGTEST"),
|
||||
LTC_MAINNET(LitecoinMainNetParams.get(), "LTC", "MAINNET"),
|
||||
LTC_TESTNET(LitecoinTestNet3Params.get(), "LTC", "TESTNET"),
|
||||
LTC_REGTEST(LitecoinRegTestParams.get(), "LTC", "REGTEST");
|
||||
|
||||
public static final BaseCryptoNetwork DEFAULT = BTC_MAINNET;
|
||||
|
||||
private final NetworkParameters parameters;
|
||||
private String cryptoName;
|
||||
private String networkTranslation;
|
||||
|
||||
BaseCryptoNetwork(NetworkParameters parameters) {
|
||||
BaseCryptoNetwork(NetworkParameters parameters, String cryptoName, String networkTranslation) {
|
||||
this.parameters = parameters;
|
||||
this.cryptoName = cryptoName;
|
||||
this.networkTranslation = networkTranslation;
|
||||
}
|
||||
|
||||
public NetworkParameters getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ public class WalletsSetup {
|
|||
|
||||
WalletUtils.setBaseCryptoNetwork(bisqEnvironment.getBaseCryptoNetwork());
|
||||
params = WalletUtils.getParameters();
|
||||
walletDir = new File(appDir, "bitcoin");
|
||||
walletDir = new File(appDir, "wallet");
|
||||
PeerGroup.setIgnoreHttpSeeds(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import io.bisq.common.locale.*;
|
|||
import io.bisq.common.proto.persistable.PersistedDataHost;
|
||||
import io.bisq.common.storage.Storage;
|
||||
import io.bisq.common.util.Utilities;
|
||||
import io.bisq.core.app.BisqEnvironment;
|
||||
import io.bisq.core.btc.BaseCryptoNetwork;
|
||||
import io.bisq.core.btc.BtcOptionKeys;
|
||||
import io.bisq.core.btc.Restrictions;
|
||||
|
@ -20,6 +21,7 @@ import lombok.experimental.Delegate;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bitcoinj.core.Coin;
|
||||
import org.bitcoinj.utils.MonetaryFormat;
|
||||
import org.bouncycastle.jce.provider.symmetric.ARC4;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -66,6 +68,7 @@ public final class Preferences implements PersistedDataHost {
|
|||
@Delegate(excludes = ExcludesDelegateMethods.class)
|
||||
private PreferencesPayload prefPayload = new PreferencesPayload();
|
||||
private boolean initialReadDone = false;
|
||||
private BisqEnvironment bisqEnvironment;
|
||||
|
||||
// Observable wrappers
|
||||
@Getter
|
||||
|
@ -88,7 +91,6 @@ public final class Preferences implements PersistedDataHost {
|
|||
private boolean resyncSpvRequested;
|
||||
private boolean tacAccepted;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Constructor
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -97,10 +99,12 @@ public final class Preferences implements PersistedDataHost {
|
|||
@SuppressWarnings("WeakerAccess")
|
||||
@Inject
|
||||
public Preferences(Storage<PreferencesPayload> storage,
|
||||
BisqEnvironment bisqEnvironment,
|
||||
@Named(BtcOptionKeys.BTC_NODES) String btcNodesFromOptions,
|
||||
@Named(BtcOptionKeys.USE_TOR_FOR_BTC) String useTorFlagFromOptions) {
|
||||
|
||||
this.storage = storage;
|
||||
this.bisqEnvironment = bisqEnvironment;
|
||||
this.btcNodesFromOptions = btcNodesFromOptions;
|
||||
this.useTorFlagFromOptions = useTorFlagFromOptions;
|
||||
}
|
||||
|
@ -441,6 +445,14 @@ public final class Preferences implements PersistedDataHost {
|
|||
persist();
|
||||
}
|
||||
|
||||
public BaseCryptoNetwork getBaseCrypteNetwork(BaseCryptoNetwork baseCrypteNetwork) {
|
||||
return bisqEnvironment.getBaseCryptoNetwork();
|
||||
}
|
||||
|
||||
public void setBaseCrypteNetwork(BaseCryptoNetwork baseCrypteNetwork) {
|
||||
if (bisqEnvironment.getBaseCryptoNetwork() != baseCrypteNetwork)
|
||||
bisqEnvironment.saveBaseCryptoNetwork(baseCrypteNetwork);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Getter
|
||||
|
@ -530,38 +542,71 @@ public final class Preferences implements PersistedDataHost {
|
|||
|
||||
private interface ExcludesDelegateMethods {
|
||||
void setTacAccepted(boolean tacAccepted);
|
||||
|
||||
void setUseAnimations(boolean useAnimations);
|
||||
|
||||
void setUserLanguage(@NotNull String userLanguageCode);
|
||||
|
||||
void setUserCountry(@NotNull Country userCountry);
|
||||
|
||||
void setPreferredTradeCurrency(TradeCurrency preferredTradeCurrency);
|
||||
|
||||
void setUseTorForBitcoinJ(boolean useTorForBitcoinJ);
|
||||
|
||||
void setShowOwnOffersInOfferBook(boolean showOwnOffersInOfferBook);
|
||||
|
||||
void setMaxPriceDistanceInPercent(double maxPriceDistanceInPercent);
|
||||
|
||||
void setBackupDirectory(String backupDirectory);
|
||||
|
||||
void setAutoSelectArbitrators(boolean autoSelectArbitrators);
|
||||
|
||||
void setUsePercentageBasedPrice(boolean usePercentageBasedPrice);
|
||||
|
||||
void setTagForPeer(String hostName, String tag);
|
||||
|
||||
void setOfferBookChartScreenCurrencyCode(String offerBookChartScreenCurrencyCode);
|
||||
|
||||
void setBuyScreenCurrencyCode(String buyScreenCurrencyCode);
|
||||
|
||||
void setSellScreenCurrencyCode(String sellScreenCurrencyCode);
|
||||
|
||||
void setIgnoreTradersList(List<String> ignoreTradersList);
|
||||
|
||||
void setDirectoryChooserPath(String directoryChooserPath);
|
||||
|
||||
void setTradeChartsScreenCurrencyCode(String tradeChartsScreenCurrencyCode);
|
||||
|
||||
void setTradeStatisticsTickUnitIndex(int tradeStatisticsTickUnitIndex);
|
||||
|
||||
void setSortMarketCurrenciesNumerically(boolean sortMarketCurrenciesNumerically);
|
||||
|
||||
void setBitcoinNodes(String bitcoinNodes);
|
||||
|
||||
void setUseCustomWithdrawalTxFee(boolean useCustomWithdrawalTxFee);
|
||||
|
||||
void setWithdrawalTxFeeInBytes(long withdrawalTxFeeInBytes);
|
||||
|
||||
void setBuyerSecurityDepositAsLong(long buyerSecurityDepositAsLong);
|
||||
|
||||
void setSelectedPaymentAccountForCreateOffer(@Nullable PaymentAccount paymentAccount);
|
||||
|
||||
void setBsqBlockChainExplorer(BlockChainExplorer bsqBlockChainExplorer);
|
||||
|
||||
void setPayFeeInBtc(boolean payFeeInBtc);
|
||||
|
||||
void setFiatCurrencies(List<FiatCurrency> currencies);
|
||||
|
||||
void setCryptoCurrencies(List<CryptoCurrency> currencies);
|
||||
|
||||
void setBlockChainExplorerTestNet(BlockChainExplorer blockChainExplorerTestNet);
|
||||
|
||||
void setBlockChainExplorerMainNet(BlockChainExplorer blockChainExplorerMainNet);
|
||||
|
||||
void setResyncSpvRequested(boolean resyncSpvRequested);
|
||||
|
||||
void setDontShowAgainMap(Map<String, Boolean> dontShowAgainMap);
|
||||
|
||||
void setPeerTagMap(Map<String, String> peerTagMap);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public class BisqEnvironmentTests {
|
|||
|
||||
ConfigurableEnvironment env = new BisqEnvironment(commandlineProps) {
|
||||
@Override
|
||||
PropertySource<?> appDirProperties() {
|
||||
PropertySource<?> getAppDirProperties() {
|
||||
return filesystemProps;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -35,20 +35,23 @@
|
|||
|
||||
<TitledGroupBg fx:id="btcHeader" GridPane.rowSpan="4"/>
|
||||
|
||||
<Label fx:id="bitcoinPeersLabel" GridPane.rowIndex="0"/>
|
||||
<TextArea fx:id="bitcoinPeersTextArea" GridPane.rowIndex="0" GridPane.columnIndex="1" GridPane.hgrow="ALWAYS"
|
||||
<Label text="Select Network:" GridPane.rowIndex="0"/>
|
||||
<ComboBox fx:id="netWorkComboBox" GridPane.rowIndex="0" GridPane.columnIndex="1"/>
|
||||
|
||||
<Label fx:id="bitcoinPeersLabel" GridPane.rowIndex="1"/>
|
||||
<TextArea fx:id="bitcoinPeersTextArea" GridPane.rowIndex="1" GridPane.columnIndex="1" GridPane.hgrow="ALWAYS"
|
||||
GridPane.vgrow="SOMETIMES" editable="false" focusTraversable="false"/>
|
||||
|
||||
<Label fx:id="useTorForBtcJLabel" GridPane.rowIndex="1"/>
|
||||
<CheckBox fx:id="useTorForBtcJCheckBox" GridPane.rowIndex="1" GridPane.columnIndex="1"/>
|
||||
<Label fx:id="useTorForBtcJLabel" GridPane.rowIndex="2"/>
|
||||
<CheckBox fx:id="useTorForBtcJCheckBox" GridPane.rowIndex="2" GridPane.columnIndex="1"/>
|
||||
|
||||
<Label fx:id="btcNodesLabel" GridPane.rowIndex="2"/>
|
||||
<InputTextField fx:id="btcNodes" GridPane.rowIndex="2" GridPane.columnIndex="1"/>
|
||||
<Label fx:id="btcNodesLabel" GridPane.rowIndex="3"/>
|
||||
<InputTextField fx:id="btcNodes" GridPane.rowIndex="3" GridPane.columnIndex="1"/>
|
||||
|
||||
<Label fx:id="reSyncSPVChainLabel" GridPane.rowIndex="3"/>
|
||||
<Button fx:id="reSyncSPVChainButton" GridPane.rowIndex="3" GridPane.columnIndex="1"/>
|
||||
<Label fx:id="reSyncSPVChainLabel" GridPane.rowIndex="4"/>
|
||||
<Button fx:id="reSyncSPVChainButton" GridPane.rowIndex="4" GridPane.columnIndex="1"/>
|
||||
|
||||
<TitledGroupBg fx:id="p2pHeader" GridPane.rowIndex="4" GridPane.rowSpan="3">
|
||||
<TitledGroupBg fx:id="p2pHeader" GridPane.rowIndex="5" GridPane.rowSpan="3">
|
||||
<padding>
|
||||
<Insets top="50.0"/>
|
||||
</padding>
|
||||
|
@ -62,15 +65,15 @@
|
|||
<Insets top="50.0"/>
|
||||
</GridPane.margin>
|
||||
</Label>
|
||||
<TextField fx:id="onionAddress" GridPane.rowIndex="4" GridPane.columnIndex="1"
|
||||
<TextField fx:id="onionAddress" GridPane.rowIndex="5" GridPane.columnIndex="1"
|
||||
editable="false" focusTraversable="false">
|
||||
<GridPane.margin>
|
||||
<Insets top="50.0"/>
|
||||
</GridPane.margin>
|
||||
</TextField>
|
||||
|
||||
<Label fx:id="p2PPeersLabel" GridPane.rowIndex="5"/>
|
||||
<TableView fx:id="tableView" GridPane.rowIndex="5" GridPane.columnIndex="1" GridPane.hgrow="ALWAYS"
|
||||
<Label fx:id="p2PPeersLabel" GridPane.rowIndex="6"/>
|
||||
<TableView fx:id="tableView" GridPane.rowIndex="6" GridPane.columnIndex="1" GridPane.hgrow="ALWAYS"
|
||||
GridPane.vgrow="SOMETIMES">
|
||||
<columns>
|
||||
<TableColumn fx:id="onionAddressColumn" minWidth="220">
|
||||
|
@ -111,8 +114,8 @@
|
|||
</columns>
|
||||
</TableView>
|
||||
|
||||
<Label fx:id="totalTrafficLabel" GridPane.rowIndex="6"/>
|
||||
<TextField fx:id="totalTrafficTextField" GridPane.rowIndex="6" GridPane.columnIndex="1" editable="false"
|
||||
<Label fx:id="totalTrafficLabel" GridPane.rowIndex="7"/>
|
||||
<TextField fx:id="totalTrafficTextField" GridPane.rowIndex="7" GridPane.columnIndex="1" editable="false"
|
||||
focusTraversable="false"/>
|
||||
|
||||
<columnConstraints>
|
||||
|
|
|
@ -20,6 +20,8 @@ package io.bisq.gui.main.settings.network;
|
|||
import io.bisq.common.Clock;
|
||||
import io.bisq.common.UserThread;
|
||||
import io.bisq.common.locale.Res;
|
||||
import io.bisq.core.app.BisqEnvironment;
|
||||
import io.bisq.core.btc.BaseCryptoNetwork;
|
||||
import io.bisq.core.btc.wallet.WalletsSetup;
|
||||
import io.bisq.core.user.Preferences;
|
||||
import io.bisq.gui.app.BisqApp;
|
||||
|
@ -41,6 +43,7 @@ import javafx.geometry.Insets;
|
|||
import javafx.geometry.VPos;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.util.StringConverter;
|
||||
import org.bitcoinj.core.Peer;
|
||||
import org.fxmisc.easybind.EasyBind;
|
||||
import org.fxmisc.easybind.Subscription;
|
||||
|
@ -62,6 +65,8 @@ public class NetworkSettingsView extends ActivatableViewAndModel<GridPane, Activ
|
|||
@FXML
|
||||
TextField onionAddress, totalTrafficTextField;
|
||||
@FXML
|
||||
ComboBox<BaseCryptoNetwork> netWorkComboBox;
|
||||
@FXML
|
||||
TextArea bitcoinPeersTextArea;
|
||||
@FXML
|
||||
Label bitcoinPeersLabel, p2PPeersLabel;
|
||||
|
@ -89,14 +94,16 @@ public class NetworkSettingsView extends ActivatableViewAndModel<GridPane, Activ
|
|||
private final SortedList<P2pNetworkListItem> sortedList = new SortedList<>(networkListItems);
|
||||
private ChangeListener<Boolean> btcNodesFocusListener;
|
||||
private String btcNodesPreFocusText;
|
||||
private BisqEnvironment bisqEnvironment;
|
||||
|
||||
@Inject
|
||||
public NetworkSettingsView(WalletsSetup walletsSetup, P2PService p2PService, Preferences preferences, Clock clock,
|
||||
BSFormatter formatter) {
|
||||
public NetworkSettingsView(WalletsSetup walletsSetup, P2PService p2PService, Preferences preferences,
|
||||
BisqEnvironment bisqEnvironment, Clock clock, BSFormatter formatter) {
|
||||
super();
|
||||
this.walletsSetup = walletsSetup;
|
||||
this.p2PService = p2PService;
|
||||
this.preferences = preferences;
|
||||
this.bisqEnvironment = bisqEnvironment;
|
||||
this.clock = clock;
|
||||
this.formatter = formatter;
|
||||
}
|
||||
|
@ -126,6 +133,20 @@ public class NetworkSettingsView extends ActivatableViewAndModel<GridPane, Activ
|
|||
GridPane.setValignment(p2PPeersLabel, VPos.TOP);
|
||||
|
||||
bitcoinPeersTextArea.setPrefRowCount(6);
|
||||
netWorkComboBox.setItems(FXCollections.observableArrayList(BaseCryptoNetwork.values()));
|
||||
netWorkComboBox.getSelectionModel().select(bisqEnvironment.getBaseCryptoNetwork());
|
||||
netWorkComboBox.setOnAction(e -> onSelectNetwork());
|
||||
netWorkComboBox.setConverter(new StringConverter<BaseCryptoNetwork>() {
|
||||
@Override
|
||||
public String toString(BaseCryptoNetwork baseCryptoNetwork) {
|
||||
return Res.get(baseCryptoNetwork.name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseCryptoNetwork fromString(String string) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
tableView.setMinHeight(230);
|
||||
tableView.setPrefHeight(230);
|
||||
|
@ -259,5 +280,24 @@ public class NetworkSettingsView extends ActivatableViewAndModel<GridPane, Activ
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void onSelectNetwork() {
|
||||
if (netWorkComboBox.getSelectionModel().getSelectedItem() != bisqEnvironment.getBaseCryptoNetwork())
|
||||
selectNetwork();
|
||||
}
|
||||
|
||||
private void selectNetwork() {
|
||||
new Popup().warning("You need to shut down and restart the application to apply the change of the Bitcoin network.\n\n" +
|
||||
"Do you want to shut down now?")
|
||||
.onAction(() -> {
|
||||
bisqEnvironment.saveBaseCryptoNetwork(netWorkComboBox.getSelectionModel().getSelectedItem());
|
||||
UserThread.runAfter(BisqApp.shutDownHandler::run, 500, TimeUnit.MILLISECONDS);
|
||||
})
|
||||
.actionButtonText("Shut down")
|
||||
.closeButtonText("Cancel")
|
||||
.onClose(() -> netWorkComboBox.getSelectionModel().select(bisqEnvironment.getBaseCryptoNetwork()))
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue