diff --git a/core/src/main/java/io/bitsquare/app/gui/BitsquareAppMain.java b/core/src/main/java/io/bitsquare/app/gui/BitsquareAppMain.java index e3d1849500..545be06a60 100644 --- a/core/src/main/java/io/bitsquare/app/gui/BitsquareAppMain.java +++ b/core/src/main/java/io/bitsquare/app/gui/BitsquareAppMain.java @@ -23,6 +23,7 @@ import io.bitsquare.app.BitsquareEnvironment; import io.bitsquare.app.BitsquareExecutable; import io.bitsquare.app.UpdateProcess; import io.bitsquare.btc.BitcoinNetwork; +import io.bitsquare.btc.RegTestHost; import io.bitsquare.p2p.BootstrapNodes; import io.bitsquare.p2p.Node; import io.bitsquare.util.joptsimple.EnumValueConverter; @@ -134,6 +135,13 @@ public class BitsquareAppMain extends BitsquareExecutable { .withRequiredArg() .ofType(BitcoinNetwork.class) .withValuesConvertedBy(new EnumValueConverter(BitcoinNetwork.class)); + + parser.accepts(RegTestHost.KEY, description("", RegTestHost.DEFAULT)) + .withRequiredArg() + .ofType(RegTestHost.class) + .withValuesConvertedBy(new EnumValueConverter(RegTestHost.class)); + + parser.accepts(BOOTSTRAP_NODE_NAME_KEY, description("", BootstrapNodes.DEFAULT.getName())) .withRequiredArg(); parser.accepts(BOOTSTRAP_NODE_IP_KEY, description("", BootstrapNodes.DEFAULT.getIp())) diff --git a/core/src/main/java/io/bitsquare/btc/BitcoinModule.java b/core/src/main/java/io/bitsquare/btc/BitcoinModule.java index f587df499b..4fbe23863b 100644 --- a/core/src/main/java/io/bitsquare/btc/BitcoinModule.java +++ b/core/src/main/java/io/bitsquare/btc/BitcoinModule.java @@ -41,6 +41,7 @@ public class BitcoinModule extends BitsquareModule { @Override protected void configure() { bind(BitcoinNetwork.class).toInstance(env.getProperty(BitcoinNetwork.KEY, BitcoinNetwork.class, BitcoinNetwork.DEFAULT)); + bind(RegTestHost.class).toInstance(env.getProperty(RegTestHost.KEY, RegTestHost.class, RegTestHost.DEFAULT)); bind(FeePolicy.class).in(Singleton.class); bindConstant().annotatedWith(named(UserAgent.NAME_KEY)).to(env.getRequiredProperty(UserAgent.NAME_KEY)); diff --git a/core/src/main/java/io/bitsquare/btc/RegTestHost.java b/core/src/main/java/io/bitsquare/btc/RegTestHost.java new file mode 100644 index 0000000000..df21959319 --- /dev/null +++ b/core/src/main/java/io/bitsquare/btc/RegTestHost.java @@ -0,0 +1,27 @@ +/* + * 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 . + */ + +package io.bitsquare.btc; + +public enum RegTestHost { + + LOCALHOST(), + BITSQUARE(); // 188.226.179.109 + + public static final String KEY = "bitcoin.regtest.host"; + public static final RegTestHost DEFAULT = BITSQUARE; +} diff --git a/core/src/main/java/io/bitsquare/btc/WalletService.java b/core/src/main/java/io/bitsquare/btc/WalletService.java index 41e3c943b2..2b9eb3188d 100644 --- a/core/src/main/java/io/bitsquare/btc/WalletService.java +++ b/core/src/main/java/io/bitsquare/btc/WalletService.java @@ -29,6 +29,7 @@ import org.bitcoinj.core.Coin; import org.bitcoinj.core.DownloadProgressTracker; import org.bitcoinj.core.InsufficientMoneyException; import org.bitcoinj.core.NetworkParameters; +import org.bitcoinj.core.PeerAddress; import org.bitcoinj.core.Transaction; import org.bitcoinj.core.TransactionConfidence; import org.bitcoinj.core.TransactionInput; @@ -49,6 +50,9 @@ import com.google.common.util.concurrent.Service; import java.io.File; +import java.net.InetAddress; +import java.net.UnknownHostException; + import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -87,6 +91,7 @@ public class WalletService { private final Observable downloadProgress = downloadListener.getObservable(); private final WalletEventListener walletEventListener = new BitsquareWalletEventListener(); + private RegTestHost regTestHost; private final TradeWalletService tradeWalletService; private final AddressEntryList addressEntryList; private final NetworkParameters params; @@ -106,9 +111,10 @@ public class WalletService { /////////////////////////////////////////////////////////////////////////////////////////// @Inject - public WalletService(BitcoinNetwork bitcoinNetwork, SignatureService signatureService, + public WalletService(BitcoinNetwork bitcoinNetwork, RegTestHost regTestHost, SignatureService signatureService, TradeWalletService tradeWalletService, AddressEntryList addressEntryList, UserAgent userAgent, @Named(DIR_KEY) File walletDir, @Named(PREFIX_KEY) String walletPrefix) { + this.regTestHost = regTestHost; this.tradeWalletService = tradeWalletService; this.addressEntryList = addressEntryList; this.params = bitcoinNetwork.getParameters(); @@ -153,7 +159,16 @@ public class WalletService { // Now configure and start the appkit. This will take a second or two - we could show a temporary splash screen // or progress widget to keep the user engaged whilst we initialise, but we don't. if (params == RegTestParams.get()) { - walletAppKit.connectToLocalHost(); // You should run a regtest mode bitcoind locally. + if (regTestHost == RegTestHost.BITSQUARE) { + try { + walletAppKit.setPeerNodes(new PeerAddress(InetAddress.getByName("188.226.179.109"), params.getPort())); + } catch (UnknownHostException e) { + throw new RuntimeException(e); + } + } + else if (regTestHost == RegTestHost.LOCALHOST) { + walletAppKit.connectToLocalHost(); // You should run a regtest mode bitcoind locally.} + } } else if (params == MainNetParams.get()) { // Checkpoints are block headers that ship inside our app: for a new user, we pick the last header diff --git a/core/src/main/java/io/bitsquare/gui/main/settings/SettingsView.fxml b/core/src/main/java/io/bitsquare/gui/main/settings/SettingsView.fxml index 59ade893e4..3bfd559a12 100644 --- a/core/src/main/java/io/bitsquare/gui/main/settings/SettingsView.fxml +++ b/core/src/main/java/io/bitsquare/gui/main/settings/SettingsView.fxml @@ -24,7 +24,7 @@ AnchorPane.rightAnchor="0" AnchorPane.topAnchor="0" xmlns:fx="http://javafx.com/fxml"> - +