diff --git a/pom.xml b/pom.xml
index 24ffeb56ce..fbf83c9527 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,6 @@
io.bitsquare
bitsquare
0.01-SNAPSHOT
-
BitSquare
A P2P Fiat-Bitcoin Exchange
https://www.bitsquare.io
@@ -21,13 +20,19 @@
- Apache 2
- http://www.apache.org/licenses/LICENSE-2.0
+ GNU AFFERO GENERAL PUBLIC LICENSE
+ http://www.gnu.org/licenses/agpl-3.0.html
repo
+
+ GitHub
+ https://github.com/bitsquare/bitsquare/issues
+
+
+
https://github.com/bitsquare/bitsquare
@@ -56,13 +61,21 @@
+
+ bitsquare
src/main/java
+ true
+
+ **/*.fxml
+ **/*.css
+
src/main/resources
+ false
@@ -78,6 +91,7 @@
+
@@ -92,17 +106,24 @@
4.11
test
-
+
+
+ org.slf4j
+ slf4j-api
+ 1.7.7
+
+
ch.qos.logback
logback-classic
- 1.0.9
+ 1.1.2
compile
@@ -151,6 +172,17 @@
+
+
+
+
+ org.apache.maven.plugins
+ maven-jxr-plugin
+ 2.1
+
+
+
+
UTF-8
diff --git a/src/main/java/io/bitsquare/BitSquare.java b/src/main/java/io/bitsquare/BitSquare.java
index 6831d17e44..839045e234 100644
--- a/src/main/java/io/bitsquare/BitSquare.java
+++ b/src/main/java/io/bitsquare/BitSquare.java
@@ -58,7 +58,7 @@ public class BitSquare extends Application
@Override
public void stop() throws Exception
{
- walletFacade.terminateWallet();
+ walletFacade.shutDown();
super.stop();
}
diff --git a/src/main/java/io/bitsquare/bank/BankAccount.java b/src/main/java/io/bitsquare/bank/BankAccount.java
index 5d535c2c01..60c5dbf903 100644
--- a/src/main/java/io/bitsquare/bank/BankAccount.java
+++ b/src/main/java/io/bitsquare/bank/BankAccount.java
@@ -1,16 +1,20 @@
package io.bitsquare.bank;
import java.io.Serializable;
+import java.util.Locale;
public class BankAccount implements Serializable
{
private static final long serialVersionUID = 1792577576443221268L;
+ private static final long VERSION = 1;
+
+ private BankAccountType bankAccountType;
+ private String accountPrimaryID;
+ private String accountSecondaryID;
+ private String accountHolderName;
+ private Locale locale;
- public BankAccountType bankAccountType;
- public String accountPrimaryID;
- public String accountSecondaryID;
- public String accountHolderName;
private String uid;
// TODO just for mock yet
@@ -19,14 +23,15 @@ public class BankAccount implements Serializable
this.bankAccountType = bankAccountType;
}
- public BankAccount(BankAccountType bankAccountType, String accountPrimaryID, String accountSecondaryID, String accountHolderName)
+ public BankAccount(BankAccountType bankAccountType, String accountPrimaryID, String accountSecondaryID, String accountHolderName, Locale locale)
{
this.bankAccountType = bankAccountType;
this.accountPrimaryID = accountPrimaryID;
this.accountSecondaryID = accountSecondaryID;
this.accountHolderName = accountHolderName;
+ this.locale = locale;
- uid = bankAccountType + "_" + accountPrimaryID + "_" + accountSecondaryID + "_" + accountHolderName;
+ uid = bankAccountType + "_" + accountPrimaryID + "_" + accountSecondaryID + "_" + accountHolderName + "_" + locale.getISO3Country();
}
public String getAccountPrimaryID()
@@ -54,14 +59,16 @@ public class BankAccount implements Serializable
return uid;
}
- @Override
- public String toString()
+ // Changes of that structure must be reflected in VERSION updates
+ public String getStringifiedBankAccount()
{
- return "BankAccount{" +
- "bankAccountType=" + bankAccountType +
- ", accountPrimaryID='" + accountPrimaryID + '\'' +
- ", accountSecondaryID='" + accountSecondaryID + '\'' +
- ", accountHolderName='" + accountHolderName + '\'' +
+ return "{" +
+ "type=" + bankAccountType +
+ ", primaryID='" + accountPrimaryID + '\'' +
+ ", secondaryID='" + accountSecondaryID + '\'' +
+ ", holderName='" + accountHolderName + '\'' +
+ ", country='" + locale.getISO3Country() + '\'' +
+ ", v='" + VERSION + '\'' +
'}';
}
}
diff --git a/src/main/java/io/bitsquare/btc/AccountRegistrationWallet.java b/src/main/java/io/bitsquare/btc/AccountRegistrationWallet.java
index 2a2f143f98..4c3a59ea1c 100644
--- a/src/main/java/io/bitsquare/btc/AccountRegistrationWallet.java
+++ b/src/main/java/io/bitsquare/btc/AccountRegistrationWallet.java
@@ -17,7 +17,6 @@ import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
-import java.util.Set;
import java.util.concurrent.TimeUnit;
import static com.google.bitcoin.script.ScriptOpCodes.OP_RETURN;
@@ -25,8 +24,11 @@ import static com.google.bitcoin.script.ScriptOpCodes.OP_RETURN;
public class AccountRegistrationWallet extends Wallet implements WalletEventListener
{
private static final Logger log = LoggerFactory.getLogger(AccountRegistrationWallet.class);
+ private final File walletFile;
private NetworkParameters networkParameters;
+ private BlockChain chain;
+ private PeerGroup peerGroup;
private List walletListeners = new ArrayList<>();
AccountRegistrationWallet(NetworkParameters networkParameters, BlockChain chain, PeerGroup peerGroup)
@@ -34,8 +36,10 @@ public class AccountRegistrationWallet extends Wallet implements WalletEventList
super(networkParameters);
this.networkParameters = networkParameters;
+ this.chain = chain;
+ this.peerGroup = peerGroup;
- File walletFile = new File(".", "bitsquare_account_reg" + ".wallet");
+ walletFile = new File(".", "bitsquare_account_reg" + ".wallet");
if (walletFile.exists())
{
try
@@ -60,9 +64,27 @@ public class AccountRegistrationWallet extends Wallet implements WalletEventList
chain.addWallet(this);
peerGroup.addWallet(this);
+ try
+ {
+ saveToFile(walletFile);
+ } catch (IOException e)
+ {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
autosaveToFile(walletFile, 1, TimeUnit.SECONDS, null);
}
+ void shutDown()
+ {
+ try
+ {
+ saveToFile(walletFile);
+ } catch (IOException e)
+ {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+ }
+
Address getAddress()
{
return getKey().toAddress(networkParameters);
@@ -148,7 +170,7 @@ public class AccountRegistrationWallet extends Wallet implements WalletEventList
public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx)
{
for (WalletFacade.WalletListener walletListener : walletListeners)
- walletListener.onConfidenceChanged(tx.getConfidence().numBroadcastPeers(), tx.getConfidence().getDepthInBlocks());
+ walletListener.onConfidenceChanged(tx.getConfidence().numBroadcastPeers(), WalletUtil.getConfirmationDepthInBlocks(this));
log.info("onTransactionConfidenceChanged " + tx.getConfidence().toString());
}
@@ -185,24 +207,8 @@ public class AccountRegistrationWallet extends Wallet implements WalletEventList
int getConfirmationNumBroadcastPeers()
{
- Transaction transaction = getTransaction();
+ Transaction transaction = WalletUtil.getTransaction(this);
return (transaction == null || transaction.getConfidence() == null) ? 0 : transaction.getConfidence().numBroadcastPeers();
}
- int getConfirmationDepthInBlocks()
- {
- Transaction transaction = getTransaction();
- return (transaction == null || transaction.getConfidence() == null) ? 0 : transaction.getConfidence().getDepthInBlocks();
- }
-
- //TODO only 1 tx supported yet...
- private Transaction getTransaction()
- {
- Set transactions = getTransactions(true);
- if (transactions != null && transactions.size() == 1)
- {
- return transactions.iterator().next();
- }
- return null;
- }
}
diff --git a/src/main/java/io/bitsquare/btc/WalletFacade.java b/src/main/java/io/bitsquare/btc/WalletFacade.java
index b89054c32c..f2cd1eb1d2 100644
--- a/src/main/java/io/bitsquare/btc/WalletFacade.java
+++ b/src/main/java/io/bitsquare/btc/WalletFacade.java
@@ -87,8 +87,10 @@ public class WalletFacade implements WalletEventListener
log.info(walletAppKit.wallet().toString());
}
- public void terminateWallet()
+ public void shutDown()
{
+ if (accountRegistrationWallet != null)
+ accountRegistrationWallet.shutDown();
walletAppKit.stopAsync();
walletAppKit.awaitTerminated();
}
@@ -176,7 +178,7 @@ public class WalletFacade implements WalletEventListener
public int getRegistrationConfirmationDepthInBlocks()
{
- return getAccountRegistrationWallet().getConfirmationDepthInBlocks();
+ return WalletUtil.getConfirmationDepthInBlocks(getAccountRegistrationWallet());
}
// WalletEventListener
@@ -193,7 +195,7 @@ public class WalletFacade implements WalletEventListener
public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx)
{
for (WalletListener walletListener : walletListeners)
- walletListener.onConfidenceChanged(tx.getConfidence().numBroadcastPeers(), tx.getConfidence().getDepthInBlocks());
+ walletListener.onConfidenceChanged(tx.getConfidence().numBroadcastPeers(), WalletUtil.getConfirmationDepthInBlocks(walletAppKit.wallet()));
log.info("onTransactionConfidenceChanged " + tx.getConfidence().toString());
}
@@ -271,4 +273,6 @@ public class WalletFacade implements WalletEventListener
void onCoinsReceived(BigInteger newBalance);
}
+
+
}
\ No newline at end of file
diff --git a/src/main/java/io/bitsquare/btc/WalletUtil.java b/src/main/java/io/bitsquare/btc/WalletUtil.java
new file mode 100644
index 0000000000..3f74975634
--- /dev/null
+++ b/src/main/java/io/bitsquare/btc/WalletUtil.java
@@ -0,0 +1,42 @@
+package io.bitsquare.btc;
+
+import com.google.bitcoin.core.Transaction;
+import com.google.bitcoin.core.TransactionConfidence;
+import com.google.bitcoin.core.Wallet;
+
+import java.math.BigInteger;
+import java.util.Set;
+
+public class WalletUtil
+{
+
+ // TODO check if that is correct and safe
+ public static int getConfirmationDepthInBlocks(Wallet wallet)
+ {
+ Transaction transaction = WalletUtil.getTransaction(wallet);
+ if (transaction != null && transaction.getConfidence() != null)
+ {
+ int appearedAtChainHeight = (transaction.getConfidence().getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING) ? transaction.getConfidence().getAppearedAtChainHeight() : 0;
+ return wallet.getLastBlockSeenHeight() - appearedAtChainHeight + 1;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+
+ // TODO check if that is correct and safe
+ public static Transaction getTransaction(Wallet wallet)
+ {
+ Set transactions = wallet.getTransactions(true);
+ if (transactions != null)
+ {
+ for (Transaction transaction : transactions)
+ {
+ if (transaction.getValueSentFromMe(wallet).compareTo(BigInteger.ZERO) == 0)
+ return transaction;
+ }
+ }
+ return null;
+ }
+}
diff --git a/src/main/java/io/bitsquare/gui/MainController.java b/src/main/java/io/bitsquare/gui/MainController.java
index 077e88ddb5..7cf9ac8d63 100644
--- a/src/main/java/io/bitsquare/gui/MainController.java
+++ b/src/main/java/io/bitsquare/gui/MainController.java
@@ -46,18 +46,18 @@ public class MainController implements Initializable, NavigationController, Wall
private ToggleGroup toggleGroup;
private ToggleButton prevToggleButton;
private Image prevToggleButtonIcon;
- // public ProgressBar networkSyncProgressBar;
- //public Label networkSyncInfoLabel;
private Pane setupView;
private SetupController setupController;
+ private NetworkSyncPane networkSyncPane;
@FXML
public Pane contentPane;
+ @FXML
public HBox leftNavPane, rightNavPane;
+ @FXML
public StackPane rootContainer;
+ @FXML
public AnchorPane anchorPane;
- private NetworkSyncPane networkSyncPane;
-
@Inject
public MainController(Settings settings, User user, OrderBookFilter orderBookFilter, WalletFacade walletFacade)
@@ -74,24 +74,20 @@ public class MainController implements Initializable, NavigationController, Wall
networkSyncPane = new NetworkSyncPane();
networkSyncPane.setSpacing(10);
networkSyncPane.setPrefHeight(20);
- AnchorPane.setBottomAnchor(networkSyncPane, 0.0);
- AnchorPane.setLeftAnchor(networkSyncPane, 0.0);
walletFacade.addDownloadListener(this);
walletFacade.initWallet();
-
buildNavigation();
- if (user.getAccountID() != null)
- {
- anchorPane.getChildren().add(networkSyncPane);
- }
- else
+ if (user.getAccountID() == null)
{
buildSetupView();
anchorPane.setOpacity(0);
setupController.setNetworkSyncPane(networkSyncPane);
rootContainer.getChildren().add(setupView);
}
+
+ AnchorPane.setBottomAnchor(networkSyncPane, 0.0);
+ AnchorPane.setLeftAnchor(networkSyncPane, 0.0);
}
diff --git a/src/main/java/io/bitsquare/gui/MainView.fxml b/src/main/java/io/bitsquare/gui/MainView.fxml
index 381167ba76..caa4b0afd8 100644
--- a/src/main/java/io/bitsquare/gui/MainView.fxml
+++ b/src/main/java/io/bitsquare/gui/MainView.fxml
@@ -7,7 +7,7 @@
-
diff --git a/src/main/java/io/bitsquare/gui/setup/SetupController.java b/src/main/java/io/bitsquare/gui/setup/SetupController.java
index 65ec1a7271..fc5cd27064 100644
--- a/src/main/java/io/bitsquare/gui/setup/SetupController.java
+++ b/src/main/java/io/bitsquare/gui/setup/SetupController.java
@@ -18,8 +18,6 @@ import io.bitsquare.gui.util.Formatter;
import io.bitsquare.settings.Settings;
import io.bitsquare.storage.Storage;
import io.bitsquare.user.User;
-import javafx.beans.value.ChangeListener;
-import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
@@ -29,6 +27,7 @@ import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
+import javafx.util.StringConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -47,11 +46,11 @@ public class SetupController implements Initializable, ChildController, WalletFa
private Storage storage;
private List processStepItems = new ArrayList();
- private int depthInBlocks = 0;
private NavigationController navigationController;
private ImageView confirmIconImageView;
- private TextField balanceLabel, confirmationsLabel;
+ private TextField balanceLabel, confirmationsLabel, accountHolderName, accountPrimaryID, accountSecondaryID;
+ private ComboBox countryComboBox, bankTransferTypeComboBox;
@FXML
private AnchorPane rootContainer;
@@ -102,8 +101,6 @@ public class SetupController implements Initializable, ChildController, WalletFa
@Override
public void onConfidenceChanged(int numBroadcastPeers, int depthInBlocks)
{
- this.depthInBlocks = depthInBlocks;
-
updateCreateAccountButton();
confirmIconImageView.setImage(getConfirmIconImage(numBroadcastPeers, depthInBlocks));
confirmationsLabel.setText(getConfirmationsText(numBroadcastPeers, depthInBlocks));
@@ -145,6 +142,12 @@ public class SetupController implements Initializable, ChildController, WalletFa
return Icons.getIconImage(Icons.getIconIDForPeersSeenTx(numBroadcastPeers));
}
+ private void updateCreateAccountButton()
+ {
+ boolean funded = walletFacade.getAccountRegistrationBalance().compareTo(BigInteger.ZERO) > 0;
+ nextButton.setDisable(!funded || walletFacade.getRegistrationConfirmationDepthInBlocks() == 0);
+ }
+
///////////////////////////////////////////////////////////////////////////////////
// GUI BUILDER
@@ -202,9 +205,7 @@ public class SetupController implements Initializable, ChildController, WalletFa
buildStep1();
});
- skipButton.setOnAction(e -> {
- close();
- });
+ skipButton.setOnAction(e -> close());
}
private void buildStep1()
@@ -215,45 +216,81 @@ public class SetupController implements Initializable, ChildController, WalletFa
formGridPane.getChildren().clear();
int gridRow = -1;
- ComboBox bankTransferTypes = FormBuilder.addComboBox(formGridPane, "Bank account type:", settings.getAllBankAccountTypes(), ++gridRow);
- bankTransferTypes.setPromptText("Select");
- //TODO dev
- bankTransferTypes.getSelectionModel().select(1);
- TextField accountHolderName = FormBuilder.addInputField(formGridPane, "Bank account holder name:", "Bob Brown", ++gridRow);
- TextField accountPrimaryID = FormBuilder.addInputField(formGridPane, "Bank account primary ID", "dummy IBAN", ++gridRow);
- TextField accountSecondaryID = FormBuilder.addInputField(formGridPane, "Bank account secondary ID:", "dummy BIC", ++gridRow);
+ bankTransferTypeComboBox = FormBuilder.addComboBox(formGridPane, "Bank account type:", settings.getAllBankAccountTypes(), ++gridRow);
+ bankTransferTypeComboBox.setPromptText("Select bank account type");
+ accountHolderName = FormBuilder.addInputField(formGridPane, "Bank account holder name:", "", ++gridRow);
+ accountPrimaryID = FormBuilder.addInputField(formGridPane, "Bank account primary ID", "", ++gridRow);
+ accountSecondaryID = FormBuilder.addInputField(formGridPane, "Bank account secondary ID:", "", ++gridRow);
+
+ countryComboBox = FormBuilder.addComboBox(formGridPane, "Country:", settings.getAllLocales("displayCountry"), ++gridRow);
+ countryComboBox.setPromptText("Select country");
+ countryComboBox.setConverter(new StringConverter()
+ {
+ @Override
+ public String toString(Object o)
+ {
+ return ((Locale) o).getDisplayCountry();
+ }
+
+ @Override
+ public Object fromString(String s)
+ {
+ return s;
+ }
+ });
+
+
Button addButton = new Button("Add other Bank account");
formGridPane.add(addButton, 1, ++gridRow);
nextButton.setText("Create account");
- nextButton.setDisable(true);
+ checkCreateAccountButtonState();
skipButton.setText("Register later");
// handlers
- bankTransferTypes.valueProperty().addListener(new ChangeListener