mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-05-06 16:45:07 -04:00
integrate bitcoinj WalletAppKit
This commit is contained in:
parent
227985fdc7
commit
328ecf34fe
15 changed files with 408 additions and 112 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -4,3 +4,5 @@
|
||||||
/bin
|
/bin
|
||||||
.idea
|
.idea
|
||||||
bitsquare.iml
|
bitsquare.iml
|
||||||
|
.spvchain
|
||||||
|
.wallet
|
||||||
|
|
78
pom.xml
78
pom.xml
|
@ -4,14 +4,21 @@
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>bitsquare</groupId>
|
<groupId>io.bitsquare</groupId>
|
||||||
<artifactId>bitsquare</artifactId>
|
<artifactId>bitsquare</artifactId>
|
||||||
<version>0.1</version>
|
<version>0.01-SNAPSHOT</version>
|
||||||
|
|
||||||
<name>BitSquare</name>
|
<name>BitSquare</name>
|
||||||
<description>A P2P Fiat-Bitcoin Exchange</description>
|
<description>A P2P Fiat-Bitcoin Exchange</description>
|
||||||
<url>https://www.bitsquare.io</url>
|
<url>https://www.bitsquare.io</url>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.google</groupId>
|
||||||
|
<artifactId>bitcoinj-parent</artifactId>
|
||||||
|
<version>0.12-SNAPSHOT</version>
|
||||||
|
<relativePath>libs/bitcoinj/pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
<licenses>
|
<licenses>
|
||||||
<license>
|
<license>
|
||||||
<name>Apache 2</name>
|
<name>Apache 2</name>
|
||||||
|
@ -24,6 +31,31 @@
|
||||||
<url>https://github.com/bitsquare/bitsquare</url>
|
<url>https://github.com/bitsquare/bitsquare</url>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>sonatype-oss-snapshot</id>
|
||||||
|
<snapshots/>
|
||||||
|
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>sonatype-oss-snapshot2</id>
|
||||||
|
<snapshots/>
|
||||||
|
<url>https://oss.sonatype.org/content/groups/public</url>
|
||||||
|
</repository>
|
||||||
|
<!-- bitcoin-j repo -->
|
||||||
|
<repository>
|
||||||
|
<id>bitcoinj-release</id>
|
||||||
|
<releases />
|
||||||
|
<url>http://distribution.bitcoinj.googlecode.com/git/releases</url>
|
||||||
|
</repository>
|
||||||
|
<!-- zxing repo -->
|
||||||
|
<repository>
|
||||||
|
<id>mvn-adamgent</id>
|
||||||
|
<url>http://mvn-adamgent.googlecode.com/svn/maven/release</url>
|
||||||
|
<name>Adam Gent Maven Repository</name>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
|
@ -33,24 +65,27 @@
|
||||||
<directory>src/main/resources</directory>
|
<directory>src/main/resources</directory>
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>2.4</version>
|
<version>3.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<archive>
|
<source>1.8</source>
|
||||||
<manifest>
|
<target>1.8</target>
|
||||||
<mainClass>io.bitsquare.BitSquare</mainClass>
|
|
||||||
</manifest>
|
|
||||||
</archive>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google</groupId>
|
||||||
|
<artifactId>bitcoinj</artifactId>
|
||||||
|
<version>0.12-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
|
@ -60,7 +95,7 @@
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-jdk14</artifactId>
|
||||||
<version>1.7.6</version>
|
<version>1.7.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -80,8 +115,14 @@
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.guava</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
<artifactId>guava-base</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
<version>r03</version>
|
<version>16.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.aquafx-project</groupId>
|
||||||
|
<artifactId>aquafx</artifactId>
|
||||||
|
<version>0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -97,6 +138,17 @@
|
||||||
<version>8.0.5</version>
|
<version>8.0.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>de.jensd</groupId>
|
||||||
|
<artifactId>fontawesomefx</artifactId>
|
||||||
|
<version>8.0.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.glxn</groupId>
|
||||||
|
<artifactId>qrgen</artifactId>
|
||||||
|
<version>1.3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|
|
@ -1,12 +1,18 @@
|
||||||
package io.bitsquare;
|
package io.bitsquare;
|
||||||
|
|
||||||
|
import com.google.bitcoin.store.BlockStoreException;
|
||||||
|
import com.google.bitcoin.utils.BriefLogFormatter;
|
||||||
|
import com.google.bitcoin.utils.Threading;
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
|
import io.bitsquare.btc.IWalletFacade;
|
||||||
import io.bitsquare.di.BitSquareModule;
|
import io.bitsquare.di.BitSquareModule;
|
||||||
import io.bitsquare.di.GuiceFXMLLoader;
|
import io.bitsquare.di.GuiceFXMLLoader;
|
||||||
import io.bitsquare.setup.ISetup;
|
import io.bitsquare.setup.ISetup;
|
||||||
import io.bitsquare.setup.MockSetup;
|
import io.bitsquare.setup.MockSetup;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
|
import javafx.application.Platform;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
@ -18,6 +24,7 @@ import java.io.IOException;
|
||||||
public class BitSquare extends Application
|
public class BitSquare extends Application
|
||||||
{
|
{
|
||||||
private static final Logger log = LoggerFactory.getLogger(BitSquare.class);
|
private static final Logger log = LoggerFactory.getLogger(BitSquare.class);
|
||||||
|
private IWalletFacade walletFacade;
|
||||||
|
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
|
@ -25,27 +32,66 @@ public class BitSquare extends Application
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage stage)
|
public void start(Stage stage) throws Exception
|
||||||
{
|
{
|
||||||
Injector injector = Guice.createInjector(new BitSquareModule());
|
// Show the crash dialog for any exceptions that we don't handle and that hit the main loop.
|
||||||
ISetup setup = injector.getInstance(MockSetup.class);
|
//GuiUtils.handleCrashesOnThisThread();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
init(stage);
|
||||||
|
} catch (Throwable t)
|
||||||
|
{
|
||||||
|
// Nicer message for the case where the block store file is locked.
|
||||||
|
if (Throwables.getRootCause(t) instanceof BlockStoreException)
|
||||||
|
{
|
||||||
|
//GuiUtils.informationalAlert("Already running", "This application is already running and cannot be started twice.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stop() throws Exception
|
||||||
|
{
|
||||||
|
walletFacade.terminateWallet();
|
||||||
|
|
||||||
|
super.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init(Stage stage) throws IOException
|
||||||
|
{
|
||||||
|
// Make log output concise.
|
||||||
|
BriefLogFormatter.init();
|
||||||
|
|
||||||
|
// Tell bitcoinj to run event handlers on the JavaFX UI thread. This keeps things simple and means
|
||||||
|
// we cannot forget to switch threads when adding event handlers. Unfortunately, the DownloadListener
|
||||||
|
// we give to the app kit is currently an exception and runs on a library thread. It'll get fixed in
|
||||||
|
// a future version.
|
||||||
|
Threading.USER_THREAD = Platform::runLater;
|
||||||
|
|
||||||
|
final Injector injector = Guice.createInjector(new BitSquareModule());
|
||||||
|
walletFacade = injector.getInstance(IWalletFacade.class);
|
||||||
|
|
||||||
|
final ISetup setup = injector.getInstance(MockSetup.class);
|
||||||
setup.applyPersistedData();
|
setup.applyPersistedData();
|
||||||
|
|
||||||
stage.setTitle("BitSquare");
|
stage.setTitle("BitSquare");
|
||||||
|
|
||||||
GuiceFXMLLoader loader = new GuiceFXMLLoader(injector);
|
// main view
|
||||||
try
|
final GuiceFXMLLoader loader = new GuiceFXMLLoader(injector);
|
||||||
{
|
final Parent mainView = loader.load(BitSquare.class.getResourceAsStream("/io/bitsquare/gui/MainView.fxml"));
|
||||||
Parent mainView = loader.load(BitSquare.class.getResourceAsStream("/io/bitsquare/gui/MainView.fxml"));
|
final Scene scene = new Scene(mainView, 800, 600);
|
||||||
Scene scene = new Scene(mainView, 800, 600);
|
stage.setScene(scene);
|
||||||
scene.getStylesheets().setAll(getClass().getResource("/io/bitsquare/gui/global.css").toExternalForm());
|
|
||||||
stage.setScene(scene);
|
|
||||||
stage.show();
|
|
||||||
} catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// apply css
|
||||||
|
final String global = getClass().getResource("/io/bitsquare/gui/global.css").toExternalForm();
|
||||||
|
// final String textValidation = getClass().getResource("/wallettemplate/utils/text-validation.css").toExternalForm();
|
||||||
|
//scene.getStylesheets().setAll(global, textValidation);
|
||||||
|
scene.getStylesheets().setAll(global);
|
||||||
|
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,19 @@
|
||||||
package io.bitsquare.btc;
|
package io.bitsquare.btc;
|
||||||
|
|
||||||
|
import com.google.bitcoin.core.PeerEventListener;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
|
||||||
public interface IWalletFacade
|
public interface IWalletFacade
|
||||||
{
|
{
|
||||||
|
public static final String MAIN_NET = "MAIN_NET";
|
||||||
|
public static final String TEST_NET = "TEST_NET";
|
||||||
|
public static final String REG_TEST_NET = "REG_TEST_NET";
|
||||||
|
|
||||||
|
void initWallet(PeerEventListener peerEventListener);
|
||||||
|
|
||||||
|
void terminateWallet();
|
||||||
|
|
||||||
BigInteger getBalance();
|
BigInteger getBalance();
|
||||||
|
|
||||||
boolean pay(BigInteger satoshisToPay, String destinationAddress);
|
boolean pay(BigInteger satoshisToPay, String destinationAddress);
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
package io.bitsquare.btc;
|
|
||||||
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gateway to wallet
|
|
||||||
*/
|
|
||||||
public class MockWalletFacade implements IWalletFacade
|
|
||||||
{
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(MockWalletFacade.class);
|
|
||||||
|
|
||||||
private BigInteger balance;
|
|
||||||
|
|
||||||
public MockWalletFacade()
|
|
||||||
{
|
|
||||||
balance = new BigInteger("100000000");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BigInteger getBalance()
|
|
||||||
{
|
|
||||||
return balance;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean pay(BigInteger satoshisToPay, String destinationAddress)
|
|
||||||
{
|
|
||||||
if (getBalance().subtract(satoshisToPay).longValue() > 0)
|
|
||||||
{
|
|
||||||
log.info("Pay " + satoshisToPay.toString() + " Satoshis to " + destinationAddress);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log.warn("Not enough funds in wallet for paying " + satoshisToPay.toString() + " Satoshis.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public KeyPair createNewAddress()
|
|
||||||
{
|
|
||||||
//MOCK
|
|
||||||
return new KeyPair(UUID.randomUUID().toString(), UUID.randomUUID().toString());
|
|
||||||
}
|
|
||||||
}
|
|
97
src/main/java/io/bitsquare/btc/WalletFacade.java
Normal file
97
src/main/java/io/bitsquare/btc/WalletFacade.java
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
package io.bitsquare.btc;
|
||||||
|
|
||||||
|
import com.google.bitcoin.core.NetworkParameters;
|
||||||
|
import com.google.bitcoin.core.PeerEventListener;
|
||||||
|
import com.google.bitcoin.kits.WalletAppKit;
|
||||||
|
import com.google.bitcoin.params.MainNetParams;
|
||||||
|
import com.google.bitcoin.params.RegTestParams;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class WalletFacade implements IWalletFacade
|
||||||
|
{
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(WalletFacade.class);
|
||||||
|
private NetworkParameters networkParameters;
|
||||||
|
private WalletAppKit walletAppKit;
|
||||||
|
|
||||||
|
private BigInteger balance;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public WalletFacade(NetworkParameters networkParameters, WalletAppKit walletAppKit)
|
||||||
|
{
|
||||||
|
this.networkParameters = networkParameters;
|
||||||
|
this.walletAppKit = walletAppKit;
|
||||||
|
|
||||||
|
balance = new BigInteger("100000000");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initWallet(PeerEventListener peerEventListener)
|
||||||
|
{
|
||||||
|
if (networkParameters == RegTestParams.get())
|
||||||
|
{
|
||||||
|
walletAppKit.connectToLocalHost(); // You should run a regtest mode bitcoind locally.
|
||||||
|
}
|
||||||
|
else if (networkParameters == MainNetParams.get())
|
||||||
|
{
|
||||||
|
// Checkpoints are block headers that ship inside our app: for a new user, we pick the last header
|
||||||
|
// in the checkpoints file and then download the rest from the network. It makes things much faster.
|
||||||
|
// Checkpoint files are made using the BuildCheckpoints tool and usually we have to download the
|
||||||
|
// last months worth or more (takes a few seconds).
|
||||||
|
walletAppKit.setCheckpoints(getClass().getResourceAsStream("/wallet/checkpoints"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
walletAppKit.setDownloadListener(peerEventListener)
|
||||||
|
.setBlockingStartup(false)
|
||||||
|
.setUserAgent("BitSquare", "1.0");
|
||||||
|
walletAppKit.startAsync();
|
||||||
|
walletAppKit.awaitRunning();
|
||||||
|
// Don't make the user wait for confirmations for now, as the intention is they're sending it their own money!
|
||||||
|
walletAppKit.wallet().allowSpendingUnconfirmedTransactions();
|
||||||
|
walletAppKit.peerGroup().setMaxConnections(11);
|
||||||
|
|
||||||
|
log.info(walletAppKit.wallet().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void terminateWallet()
|
||||||
|
{
|
||||||
|
walletAppKit.stopAsync();
|
||||||
|
walletAppKit.awaitTerminated();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//MOCK...
|
||||||
|
@Override
|
||||||
|
public BigInteger getBalance()
|
||||||
|
{
|
||||||
|
return balance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean pay(BigInteger satoshisToPay, String destinationAddress)
|
||||||
|
{
|
||||||
|
if (getBalance().subtract(satoshisToPay).longValue() > 0)
|
||||||
|
{
|
||||||
|
log.info("Pay " + satoshisToPay.toString() + " Satoshis to " + destinationAddress);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log.warn("Not enough funds in wallet for paying " + satoshisToPay.toString() + " Satoshis.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyPair createNewAddress()
|
||||||
|
{
|
||||||
|
//MOCK
|
||||||
|
return new KeyPair(UUID.randomUUID().toString(), UUID.randomUUID().toString());
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,10 +1,19 @@
|
||||||
package io.bitsquare.di;
|
package io.bitsquare.di;
|
||||||
|
|
||||||
|
|
||||||
|
import com.google.bitcoin.core.NetworkParameters;
|
||||||
|
import com.google.bitcoin.kits.WalletAppKit;
|
||||||
|
import com.google.bitcoin.params.MainNetParams;
|
||||||
|
import com.google.bitcoin.params.RegTestParams;
|
||||||
|
import com.google.bitcoin.params.TestNet3Params;
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Provider;
|
||||||
|
import com.google.inject.name.Named;
|
||||||
|
import com.google.inject.name.Names;
|
||||||
import io.bitsquare.btc.BlockChainFacade;
|
import io.bitsquare.btc.BlockChainFacade;
|
||||||
import io.bitsquare.btc.IWalletFacade;
|
import io.bitsquare.btc.IWalletFacade;
|
||||||
import io.bitsquare.btc.MockWalletFacade;
|
import io.bitsquare.btc.WalletFacade;
|
||||||
import io.bitsquare.crypto.ICryptoFacade;
|
import io.bitsquare.crypto.ICryptoFacade;
|
||||||
import io.bitsquare.crypto.MockCryptoFacade;
|
import io.bitsquare.crypto.MockCryptoFacade;
|
||||||
import io.bitsquare.msg.IMessageFacade;
|
import io.bitsquare.msg.IMessageFacade;
|
||||||
|
@ -21,8 +30,12 @@ import io.bitsquare.trade.orderbook.MockOrderBook;
|
||||||
import io.bitsquare.trade.orderbook.OrderBookFilter;
|
import io.bitsquare.trade.orderbook.OrderBookFilter;
|
||||||
import io.bitsquare.user.User;
|
import io.bitsquare.user.User;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
public class BitSquareModule extends AbstractModule
|
public class BitSquareModule extends AbstractModule
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure()
|
protected void configure()
|
||||||
{
|
{
|
||||||
|
@ -35,10 +48,62 @@ public class BitSquareModule extends AbstractModule
|
||||||
bind(OrderBookFilterSettings.class).asEagerSingleton();
|
bind(OrderBookFilterSettings.class).asEagerSingleton();
|
||||||
|
|
||||||
bind(ICryptoFacade.class).to(MockCryptoFacade.class).asEagerSingleton();
|
bind(ICryptoFacade.class).to(MockCryptoFacade.class).asEagerSingleton();
|
||||||
bind(IWalletFacade.class).to(MockWalletFacade.class).asEagerSingleton();
|
bind(IWalletFacade.class).to(WalletFacade.class).asEagerSingleton();
|
||||||
bind(BlockChainFacade.class).asEagerSingleton();
|
bind(BlockChainFacade.class).asEagerSingleton();
|
||||||
bind(IMessageFacade.class).to(MessageFacade.class).asEagerSingleton();
|
bind(IMessageFacade.class).to(MessageFacade.class).asEagerSingleton();
|
||||||
|
|
||||||
bind(TradingFacade.class).asEagerSingleton();
|
bind(TradingFacade.class).asEagerSingleton();
|
||||||
|
|
||||||
|
bind(String.class).annotatedWith(Names.named("networkType")).toInstance(IWalletFacade.MAIN_NET);
|
||||||
|
bind(NetworkParameters.class).toProvider(NetworkParametersProvider.class).asEagerSingleton();
|
||||||
|
bind(WalletAppKit.class).toProvider(WalletAppKitProvider.class).asEagerSingleton();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class WalletAppKitProvider implements Provider<WalletAppKit>
|
||||||
|
{
|
||||||
|
private NetworkParameters networkParameters;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public WalletAppKitProvider(NetworkParameters networkParameters)
|
||||||
|
{
|
||||||
|
this.networkParameters = networkParameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WalletAppKit get()
|
||||||
|
{
|
||||||
|
return new WalletAppKit(networkParameters, new File("."), "bitsquare");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class NetworkParametersProvider implements Provider<NetworkParameters>
|
||||||
|
{
|
||||||
|
private String networkType;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public NetworkParametersProvider(@Named("networkType") String networkType)
|
||||||
|
{
|
||||||
|
this.networkType = networkType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NetworkParameters get()
|
||||||
|
{
|
||||||
|
NetworkParameters result = null;
|
||||||
|
|
||||||
|
switch (networkType)
|
||||||
|
{
|
||||||
|
case IWalletFacade.MAIN_NET:
|
||||||
|
result = MainNetParams.get();
|
||||||
|
break;
|
||||||
|
case IWalletFacade.TEST_NET:
|
||||||
|
result = TestNet3Params.get();
|
||||||
|
break;
|
||||||
|
case IWalletFacade.REG_TEST_NET:
|
||||||
|
result = RegTestParams.get();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,13 +1,18 @@
|
||||||
package io.bitsquare.gui;
|
package io.bitsquare.gui;
|
||||||
|
|
||||||
|
import com.google.bitcoin.core.DownloadListener;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import io.bitsquare.BitSquare;
|
import io.bitsquare.BitSquare;
|
||||||
|
import io.bitsquare.btc.IWalletFacade;
|
||||||
import io.bitsquare.di.GuiceFXMLLoader;
|
import io.bitsquare.di.GuiceFXMLLoader;
|
||||||
import io.bitsquare.gui.trade.TradeController;
|
import io.bitsquare.gui.trade.TradeController;
|
||||||
import io.bitsquare.gui.util.Icons;
|
import io.bitsquare.gui.util.Icons;
|
||||||
import io.bitsquare.settings.Settings;
|
import io.bitsquare.settings.Settings;
|
||||||
import io.bitsquare.trade.Direction;
|
import io.bitsquare.trade.Direction;
|
||||||
import io.bitsquare.trade.orderbook.OrderBookFilter;
|
import io.bitsquare.trade.orderbook.OrderBookFilter;
|
||||||
|
import javafx.animation.FadeTransition;
|
||||||
|
import javafx.animation.Interpolator;
|
||||||
|
import javafx.application.Platform;
|
||||||
import javafx.beans.value.ChangeListener;
|
import javafx.beans.value.ChangeListener;
|
||||||
import javafx.beans.value.ObservableValue;
|
import javafx.beans.value.ObservableValue;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
|
@ -15,61 +20,59 @@ import javafx.fxml.FXML;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import javafx.scene.control.ComboBox;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.control.Label;
|
|
||||||
import javafx.scene.control.ToggleButton;
|
|
||||||
import javafx.scene.control.ToggleGroup;
|
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.util.Duration;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Currency;
|
import java.util.Currency;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
public class MainController implements Initializable, INavigationController
|
public class MainController implements Initializable, INavigationController
|
||||||
{
|
{
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(MainController.class);
|
||||||
|
|
||||||
private Settings settings;
|
private Settings settings;
|
||||||
private OrderBookFilter orderBookFilter;
|
private OrderBookFilter orderBookFilter;
|
||||||
|
private IWalletFacade walletFacade;
|
||||||
private IChildController childController;
|
private IChildController childController;
|
||||||
private ToggleGroup toggleGroup;
|
private ToggleGroup toggleGroup;
|
||||||
private ToggleButton prevToggleButton;
|
private ToggleButton prevToggleButton;
|
||||||
private Image prevToggleButtonIcon;
|
private Image prevToggleButtonIcon;
|
||||||
|
public ProgressBar networkSyncProgressBar;
|
||||||
|
public Label networkSyncInfoLabel;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public Pane contentPane;
|
public Pane contentPane;
|
||||||
public HBox leftNavPane, rightNavPane;
|
public HBox leftNavPane, rightNavPane, footerContainer;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public MainController(Settings settings, OrderBookFilter orderBookFilter)
|
public MainController(Settings settings, OrderBookFilter orderBookFilter, IWalletFacade walletFacade)
|
||||||
{
|
{
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
this.orderBookFilter = orderBookFilter;
|
this.orderBookFilter = orderBookFilter;
|
||||||
|
this.walletFacade = walletFacade;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL url, ResourceBundle rb)
|
public void initialize(URL url, ResourceBundle rb)
|
||||||
{
|
{
|
||||||
toggleGroup = new ToggleGroup();
|
buildNavigation();
|
||||||
|
|
||||||
ToggleButton homeButton = addNavButton(leftNavPane, "Overview", Icons.HOME, Icons.HOME, INavigationController.HOME);
|
buildFooter();
|
||||||
ToggleButton buyButton = addNavButton(leftNavPane, "Buy BTC", Icons.NAV_BUY, Icons.NAV_BUY_ACTIVE, INavigationController.TRADE, Direction.BUY);
|
|
||||||
ToggleButton sellButton = addNavButton(leftNavPane, "Sell BTC", Icons.NAV_SELL, Icons.NAV_SELL_ACTIVE, INavigationController.TRADE, Direction.SELL);
|
|
||||||
addNavButton(leftNavPane, "Orders", Icons.ORDERS, Icons.ORDERS, INavigationController.ORDERS);
|
|
||||||
addNavButton(leftNavPane, "History", Icons.HISTORY, Icons.HISTORY, INavigationController.HISTORY);
|
|
||||||
addNavButton(leftNavPane, "Funds", Icons.FUNDS, Icons.FUNDS, INavigationController.FUNDS);
|
|
||||||
addNavButton(leftNavPane, "Message", Icons.MSG, Icons.MSG, INavigationController.MSG);
|
|
||||||
addCurrencyComboBox();
|
|
||||||
addNavButton(rightNavPane, "Settings", Icons.SETTINGS, Icons.SETTINGS, INavigationController.SETTINGS);
|
|
||||||
|
|
||||||
|
walletFacade.initWallet(new ProgressBarUpdater());
|
||||||
sellButton.fire();
|
|
||||||
//homeButton.fire();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IChildController navigateToView(String fxmlView, String title)
|
public IChildController navigateToView(String fxmlView, String title)
|
||||||
{
|
{
|
||||||
|
@ -99,6 +102,34 @@ public class MainController implements Initializable, INavigationController
|
||||||
return childController;
|
return childController;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void buildNavigation()
|
||||||
|
{
|
||||||
|
toggleGroup = new ToggleGroup();
|
||||||
|
|
||||||
|
ToggleButton homeButton = addNavButton(leftNavPane, "Overview", Icons.HOME, Icons.HOME, INavigationController.HOME);
|
||||||
|
ToggleButton buyButton = addNavButton(leftNavPane, "Buy BTC", Icons.NAV_BUY, Icons.NAV_BUY_ACTIVE, INavigationController.TRADE, Direction.BUY);
|
||||||
|
ToggleButton sellButton = addNavButton(leftNavPane, "Sell BTC", Icons.NAV_SELL, Icons.NAV_SELL_ACTIVE, INavigationController.TRADE, Direction.SELL);
|
||||||
|
addNavButton(leftNavPane, "Orders", Icons.ORDERS, Icons.ORDERS, INavigationController.ORDERS);
|
||||||
|
addNavButton(leftNavPane, "History", Icons.HISTORY, Icons.HISTORY, INavigationController.HISTORY);
|
||||||
|
addNavButton(leftNavPane, "Funds", Icons.FUNDS, Icons.FUNDS, INavigationController.FUNDS);
|
||||||
|
addNavButton(leftNavPane, "Message", Icons.MSG, Icons.MSG, INavigationController.MSG);
|
||||||
|
addCurrencyComboBox();
|
||||||
|
addNavButton(rightNavPane, "Settings", Icons.SETTINGS, Icons.SETTINGS, INavigationController.SETTINGS);
|
||||||
|
|
||||||
|
sellButton.fire();
|
||||||
|
//homeButton.fire();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildFooter()
|
||||||
|
{
|
||||||
|
networkSyncInfoLabel = new Label();
|
||||||
|
networkSyncInfoLabel.setText("Synchronize with network...");
|
||||||
|
networkSyncProgressBar = new ProgressBar();
|
||||||
|
networkSyncProgressBar.setPrefWidth(200);
|
||||||
|
networkSyncProgressBar.setProgress(-1);
|
||||||
|
footerContainer.getChildren().addAll(networkSyncProgressBar, networkSyncInfoLabel);
|
||||||
|
}
|
||||||
|
|
||||||
private ToggleButton addNavButton(Pane parent, String title, String iconId, String iconIdActivated, String navTarget)
|
private ToggleButton addNavButton(Pane parent, String title, String iconId, String iconIdActivated, String navTarget)
|
||||||
{
|
{
|
||||||
return addNavButton(parent, title, iconId, iconIdActivated, navTarget, null);
|
return addNavButton(parent, title, iconId, iconIdActivated, navTarget, null);
|
||||||
|
@ -162,4 +193,40 @@ public class MainController implements Initializable, INavigationController
|
||||||
holder.getChildren().add(currencyComboBox);
|
holder.getChildren().add(currencyComboBox);
|
||||||
rightNavPane.getChildren().add(holder);
|
rightNavPane.getChildren().add(holder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setProgress(double percent)
|
||||||
|
{
|
||||||
|
networkSyncProgressBar.setProgress(percent / 100.0);
|
||||||
|
networkSyncInfoLabel.setText("Synchronize with network: " + (int) percent + "%");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doneDownload()
|
||||||
|
{
|
||||||
|
networkSyncInfoLabel.setText("Sync with network: Done");
|
||||||
|
|
||||||
|
FadeTransition fade = new FadeTransition(Duration.millis(700), footerContainer);
|
||||||
|
fade.setToValue(0.0);
|
||||||
|
fade.setCycleCount(1);
|
||||||
|
fade.setInterpolator(Interpolator.EASE_BOTH);
|
||||||
|
fade.play();
|
||||||
|
fade.setOnFinished(e -> footerContainer.getChildren().clear());
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ProgressBarUpdater extends DownloadListener
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected void progress(double percent, int blocksSoFar, Date date)
|
||||||
|
{
|
||||||
|
super.progress(percent, blocksSoFar, date);
|
||||||
|
Platform.runLater(() -> MainController.this.setProgress(percent));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doneDownload()
|
||||||
|
{
|
||||||
|
super.doneDownload();
|
||||||
|
Platform.runLater(MainController.this::doneDownload);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -8,7 +8,9 @@
|
||||||
<children>
|
<children>
|
||||||
<HBox fx:id="leftNavPane" spacing="20" AnchorPane.leftAnchor="10" AnchorPane.topAnchor="5"/>
|
<HBox fx:id="leftNavPane" spacing="20" AnchorPane.leftAnchor="10" AnchorPane.topAnchor="5"/>
|
||||||
<HBox fx:id="rightNavPane" spacing="10" AnchorPane.rightAnchor="10" AnchorPane.topAnchor="5"/>
|
<HBox fx:id="rightNavPane" spacing="10" AnchorPane.rightAnchor="10" AnchorPane.topAnchor="5"/>
|
||||||
<AnchorPane id="content-pane" fx:id="contentPane" AnchorPane.bottomAnchor="0" AnchorPane.leftAnchor="0"
|
<AnchorPane id="content-pane" fx:id="contentPane" AnchorPane.bottomAnchor="20" AnchorPane.leftAnchor="0"
|
||||||
AnchorPane.rightAnchor="0" AnchorPane.topAnchor="60"/>
|
AnchorPane.rightAnchor="0" AnchorPane.topAnchor="60"/>
|
||||||
|
<HBox fx:id="footerContainer" prefHeight="20" spacing="10" AnchorPane.leftAnchor="10"
|
||||||
|
AnchorPane.bottomAnchor="0"/>
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
|
|
|
@ -2,19 +2,25 @@ package io.bitsquare.gui.funds;
|
||||||
|
|
||||||
import io.bitsquare.gui.IChildController;
|
import io.bitsquare.gui.IChildController;
|
||||||
import io.bitsquare.gui.INavigationController;
|
import io.bitsquare.gui.INavigationController;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
|
import javafx.scene.layout.Pane;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
|
||||||
public class FundsController implements Initializable, IChildController
|
public class FundsController implements Initializable, IChildController
|
||||||
{
|
{
|
||||||
|
|
||||||
private INavigationController navigationController;
|
private INavigationController navigationController;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public Pane rootContainer;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL url, ResourceBundle rb)
|
public void initialize(URL url, ResourceBundle rb)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -22,5 +28,6 @@ public class FundsController implements Initializable, IChildController
|
||||||
{
|
{
|
||||||
this.navigationController = navigationController;
|
this.navigationController = navigationController;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?import javafx.scene.control.Label?>
|
<?import javafx.scene.control.Label?>
|
||||||
<?import javafx.scene.layout.Pane?>
|
<?import javafx.scene.layout.Pane?>
|
||||||
<Pane fx:controller="io.bitsquare.gui.funds.FundsController"
|
<Pane fx:controller="io.bitsquare.gui.funds.FundsController"
|
||||||
xmlns:fx="http://javafx.com/fxml">
|
xmlns:fx="http://javafx.com/fxml" fx:id="rootContainer">
|
||||||
<Label text="Wallet"/>
|
<Label text="Wallet"/>
|
||||||
</Pane>
|
</Pane>
|
|
@ -199,7 +199,7 @@ public class TradeProcessController implements Initializable, IChildController
|
||||||
private void onBankTransferInited()
|
private void onBankTransferInited()
|
||||||
{
|
{
|
||||||
infoLabel.setText("Bank transfer has been inited.\nCheck your bank account and continue when you have received the money.\n");
|
infoLabel.setText("Bank transfer has been inited.\nCheck your bank account and continue when you have received the money.\n");
|
||||||
nextButton.setText("Money received on Bank account");
|
nextButton.setText("I have received the bank transfer");
|
||||||
nextButton.setOnAction(e -> releaseBTC());
|
nextButton.setOnAction(e -> releaseBTC());
|
||||||
vBox.getChildren().add(nextButton);
|
vBox.getChildren().add(nextButton);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@ package io.bitsquare.trade;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import io.bitsquare.btc.BlockChainFacade;
|
import io.bitsquare.btc.BlockChainFacade;
|
||||||
|
import io.bitsquare.btc.IWalletFacade;
|
||||||
import io.bitsquare.btc.KeyPair;
|
import io.bitsquare.btc.KeyPair;
|
||||||
import io.bitsquare.btc.MockWalletFacade;
|
|
||||||
import io.bitsquare.crypto.ICryptoFacade;
|
import io.bitsquare.crypto.ICryptoFacade;
|
||||||
import io.bitsquare.msg.IMessageFacade;
|
import io.bitsquare.msg.IMessageFacade;
|
||||||
import io.bitsquare.msg.Message;
|
import io.bitsquare.msg.Message;
|
||||||
|
@ -29,7 +29,7 @@ public class TradingFacade
|
||||||
private User user;
|
private User user;
|
||||||
private IMessageFacade messageFacade;
|
private IMessageFacade messageFacade;
|
||||||
private BlockChainFacade blockChainFacade;
|
private BlockChainFacade blockChainFacade;
|
||||||
private MockWalletFacade walletFacade;
|
private IWalletFacade walletFacade;
|
||||||
private ICryptoFacade cryptoFacade;
|
private ICryptoFacade cryptoFacade;
|
||||||
private Settings settings;
|
private Settings settings;
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ public class TradingFacade
|
||||||
Settings settings,
|
Settings settings,
|
||||||
IMessageFacade messageFacade,
|
IMessageFacade messageFacade,
|
||||||
BlockChainFacade blockChainFacade,
|
BlockChainFacade blockChainFacade,
|
||||||
MockWalletFacade walletFacade,
|
IWalletFacade walletFacade,
|
||||||
ICryptoFacade cryptoFacade)
|
ICryptoFacade cryptoFacade)
|
||||||
{
|
{
|
||||||
this.user = user;
|
this.user = user;
|
||||||
|
|
|
@ -2,7 +2,7 @@ package io.bitsquare.trade.payment.process;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import io.bitsquare.btc.BlockChainFacade;
|
import io.bitsquare.btc.BlockChainFacade;
|
||||||
import io.bitsquare.btc.MockWalletFacade;
|
import io.bitsquare.btc.IWalletFacade;
|
||||||
import io.bitsquare.msg.IMessageFacade;
|
import io.bitsquare.msg.IMessageFacade;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -26,7 +26,7 @@ public class PaymentProcess
|
||||||
protected String takerOutputPayment;
|
protected String takerOutputPayment;
|
||||||
|
|
||||||
protected String multiSigAddress;
|
protected String multiSigAddress;
|
||||||
private MockWalletFacade wallet;
|
private IWalletFacade wallet;
|
||||||
|
|
||||||
public PaymentProcess()
|
public PaymentProcess()
|
||||||
{
|
{
|
||||||
|
@ -39,7 +39,7 @@ public class PaymentProcess
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public void setWallet(MockWalletFacade wallet)
|
public void setWallet(IWalletFacade wallet)
|
||||||
{
|
{
|
||||||
this.wallet = wallet;
|
this.wallet = wallet;
|
||||||
}
|
}
|
||||||
|
|
BIN
src/main/resources/wallet/checkpoints
Normal file
BIN
src/main/resources/wallet/checkpoints
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue