diff --git a/src/main/java/io/bitsquare/BitSquare.java b/src/main/java/io/bitsquare/BitSquare.java
index 7dede85df0..a058c131bd 100644
--- a/src/main/java/io/bitsquare/BitSquare.java
+++ b/src/main/java/io/bitsquare/BitSquare.java
@@ -32,9 +32,11 @@ import io.bitsquare.storage.Persistence;
import io.bitsquare.user.User;
import io.bitsquare.util.AWTSystemTray;
import io.bitsquare.util.StorageDirectory;
+
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
+
import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
@@ -46,8 +48,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class BitSquare extends Application
-{
+public class BitSquare extends Application {
private static final Logger log = LoggerFactory.getLogger(BitSquare.class);
public static boolean fillFormsWithDummyData = true;
@@ -57,8 +58,7 @@ public class BitSquare extends Application
private WalletFacade walletFacade;
private MessageFacade messageFacade;
- public static void main(String[] args)
- {
+ public static void main(String[] args) {
Profiler.init();
Profiler.printMsgWithTime("BitSquare.main called with args " + Arrays.asList(args).toString());
if (args != null && args.length > 0) APP_NAME = args[0];
@@ -66,19 +66,16 @@ public class BitSquare extends Application
launch(args);
}
- public static Stage getPrimaryStage()
- {
+ public static Stage getPrimaryStage() {
return primaryStage;
}
- public static String getAppName()
- {
+ public static String getAppName() {
return APP_NAME;
}
@Override
- public void start(Stage primaryStage) throws IOException
- {
+ public void start(Stage primaryStage) throws IOException {
Profiler.printMsgWithTime("BitSquare.start called");
BitSquare.primaryStage = primaryStage;
@@ -127,8 +124,7 @@ public class BitSquare extends Application
Profiler.printMsgWithTime("BitSquare: start finished");
}
- private void setupCloseHandlers(Stage primaryStage, Scene scene)
- {
+ private void setupCloseHandlers(Stage primaryStage, Scene scene) {
primaryStage.setOnCloseRequest(e -> AWTSystemTray.setStageHidden());
KeyCodeCombination keyCodeCombination = new KeyCodeCombination(KeyCode.W, KeyCombination.SHORTCUT_DOWN);
@@ -138,8 +134,7 @@ public class BitSquare extends Application
}
@Override
- public void stop() throws Exception
- {
+ public void stop() throws Exception {
walletFacade.shutDown();
messageFacade.shutDown();
diff --git a/src/main/java/io/bitsquare/SeedNode.java b/src/main/java/io/bitsquare/SeedNode.java
index 70edc35bc9..23cbf80a62 100644
--- a/src/main/java/io/bitsquare/SeedNode.java
+++ b/src/main/java/io/bitsquare/SeedNode.java
@@ -18,8 +18,10 @@
package io.bitsquare;
import io.bitsquare.msg.SeedNodeAddress;
+
import java.io.IOException;
import java.util.List;
+
import net.tomp2p.dht.PeerBuilderDHT;
import net.tomp2p.futures.BaseFuture;
import net.tomp2p.futures.BaseFutureListener;
@@ -39,22 +41,19 @@ import org.slf4j.LoggerFactory;
/**
* Well known node which is reachable for all peers for bootstrapping.
* There will be several SeedNodes running on several servers.
- *
+ *
* TODO: Alternative bootstrap methods will follow later (save locally list of known nodes reported form other peers,...)
*/
-public class SeedNode extends Thread
-{
+public class SeedNode extends Thread {
private static final Logger log = LoggerFactory.getLogger(SeedNode.class);
private static final List staticSedNodeAddresses = SeedNodeAddress.StaticSeedNodeAddresses.getAllSeedNodeAddresses();
/**
* @param args If no args passed we use localhost, otherwise the param is used as index for selecting an address from seedNodeAddresses
*/
- public static void main(String[] args)
- {
+ public static void main(String[] args) {
int index = 0;
- if (args.length > 0)
- {
+ if (args.length > 0) {
// use host index passes as param
int param = Integer.valueOf(args[0]);
if (param < staticSedNodeAddresses.size())
@@ -65,12 +64,10 @@ public class SeedNode extends Thread
seedNode.setDaemon(true);
seedNode.start();
- try
- {
+ try {
// keep main thread up
Thread.sleep(Long.MAX_VALUE);
- } catch (InterruptedException e)
- {
+ } catch (InterruptedException e) {
log.error(e.toString());
}
}
@@ -83,8 +80,7 @@ public class SeedNode extends Thread
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
- public SeedNode(SeedNodeAddress seedNodeAddress)
- {
+ public SeedNode(SeedNodeAddress seedNodeAddress) {
this.seedNodeAddress = seedNodeAddress;
}
@@ -93,29 +89,23 @@ public class SeedNode extends Thread
// Public Methods
///////////////////////////////////////////////////////////////////////////////////////////
- public void run()
- {
+ public void run() {
Peer peer = startupPeer();
- for (; ; )
- {
- try
- {
+ for (; ; ) {
+ try {
// ping(peer);
Thread.sleep(300);
- } catch (InterruptedException e)
- {
+ } catch (InterruptedException e) {
log.error(e.toString());
}
}
}
- public Peer startupPeer()
- {
+ public Peer startupPeer() {
Peer peer = null;
- try
- {
+ try {
peer = new PeerBuilder(Number160.createHash(seedNodeAddress.getId())).ports(seedNodeAddress.getPort()).start();
// Need to add all features the clients will use (otherwise msg type is UNKNOWN_ID)
@@ -127,92 +117,71 @@ public class SeedNode extends Thread
log.debug("Peer started. " + peer.peerAddress());
- peer.peerBean().peerMap().addPeerMapChangeListener(new PeerMapChangeListener()
- {
+ peer.peerBean().peerMap().addPeerMapChangeListener(new PeerMapChangeListener() {
@Override
- public void peerInserted(PeerAddress peerAddress, boolean verified)
- {
+ public void peerInserted(PeerAddress peerAddress, boolean verified) {
log.debug("Peer inserted: peerAddress=" + peerAddress + ", verified=" + verified);
}
@Override
- public void peerRemoved(PeerAddress peerAddress, PeerStatatistic peerStatistics)
- {
+ public void peerRemoved(PeerAddress peerAddress, PeerStatatistic peerStatistics) {
log.debug("Peer removed: peerAddress=" + peerAddress + ", peerStatistics=" + peerStatistics);
}
@Override
- public void peerUpdated(PeerAddress peerAddress, PeerStatatistic peerStatistics)
- {
+ public void peerUpdated(PeerAddress peerAddress, PeerStatatistic peerStatistics) {
log.debug("Peer updated: peerAddress=" + peerAddress + ", peerStatistics=" + peerStatistics);
}
});
- } catch (IOException e)
- {
+ } catch (IOException e) {
e.printStackTrace();
}
return peer;
}
- private void ping(Peer peer)
- {
+ private void ping(Peer peer) {
if (peer != null)
return;
- try
- {
+ try {
// Optional pinging
- for (PeerAddress peerAddress : peer.peerBean().peerMap().all())
- {
+ for (PeerAddress peerAddress : peer.peerBean().peerMap().all()) {
BaseFuture future = peer.ping().peerAddress(peerAddress).tcpPing().start();
- future.addListener(new BaseFutureListener()
- {
+ future.addListener(new BaseFutureListener() {
@Override
- public void operationComplete(BaseFuture future) throws Exception
- {
- if (future.isSuccess())
- {
+ public void operationComplete(BaseFuture future) throws Exception {
+ if (future.isSuccess()) {
log.debug("peer online (TCP):" + peerAddress);
- }
- else
- {
+ } else {
log.debug("offline " + peerAddress);
}
}
@Override
- public void exceptionCaught(Throwable t) throws Exception
- {
+ public void exceptionCaught(Throwable t) throws Exception {
log.error("exceptionCaught " + t);
}
});
future = peer.ping().peerAddress(peerAddress).start();
- future.addListener(new BaseFutureListener()
- {
+ future.addListener(new BaseFutureListener() {
@Override
- public void operationComplete(BaseFuture future) throws Exception
- {
- if (future.isSuccess())
- {
+ public void operationComplete(BaseFuture future) throws Exception {
+ if (future.isSuccess()) {
log.debug("peer online (UDP):" + peerAddress);
- }
- else
- {
+ } else {
log.debug("offline " + peerAddress);
}
}
@Override
- public void exceptionCaught(Throwable t) throws Exception
- {
+ public void exceptionCaught(Throwable t) throws Exception {
log.error("exceptionCaught " + t);
}
});
Thread.sleep(1500);
}
- } catch (Exception e)
- {
+ } catch (Exception e) {
log.error("Exception: " + e);
}
}
diff --git a/src/main/java/io/bitsquare/bank/BankAccount.java b/src/main/java/io/bitsquare/bank/BankAccount.java
index 0f612263b1..7a8bffa2c5 100644
--- a/src/main/java/io/bitsquare/bank/BankAccount.java
+++ b/src/main/java/io/bitsquare/bank/BankAccount.java
@@ -18,14 +18,14 @@
package io.bitsquare.bank;
import io.bitsquare.locale.Country;
+
import java.io.Serializable;
import java.util.Currency;
import java.util.Objects;
import javax.annotation.concurrent.Immutable;
@Immutable
-public class BankAccount implements Serializable
-{
+public class BankAccount implements Serializable {
private static final long serialVersionUID = 1792577576443221268L;
private final BankAccountType bankAccountType;
@@ -38,8 +38,7 @@ public class BankAccount implements Serializable
private final Currency currency;
private final String accountTitle;
- public BankAccount(BankAccountType bankAccountType, Currency currency, Country country, String accountTitle, String accountHolderName, String accountPrimaryID, String accountSecondaryID)
- {
+ public BankAccount(BankAccountType bankAccountType, Currency currency, Country country, String accountTitle, String accountHolderName, String accountPrimaryID, String accountSecondaryID) {
this.bankAccountType = bankAccountType;
this.currency = currency;
this.country = country;
@@ -49,13 +48,11 @@ public class BankAccount implements Serializable
this.accountSecondaryID = accountSecondaryID;
}
- public int hashCode()
- {
+ public int hashCode() {
return Objects.hashCode(accountTitle);
}
- public boolean equals(Object obj)
- {
+ public boolean equals(Object obj) {
if (!(obj instanceof BankAccount)) return false;
if (obj == this) return true;
@@ -64,50 +61,41 @@ public class BankAccount implements Serializable
}
- public String getAccountPrimaryID()
- {
+ public String getAccountPrimaryID() {
return accountPrimaryID;
}
- public String getAccountSecondaryID()
- {
+ public String getAccountSecondaryID() {
return accountSecondaryID;
}
- public String getAccountHolderName()
- {
+ public String getAccountHolderName() {
return accountHolderName;
}
- public BankAccountType getBankAccountType()
- {
+ public BankAccountType getBankAccountType() {
return bankAccountType;
}
- public Currency getCurrency()
- {
+ public Currency getCurrency() {
return currency;
}
- public Country getCountry()
- {
+ public Country getCountry() {
return country;
}
// we use the accountTitle as unique id
- public String getUid()
- {
+ public String getUid() {
return accountTitle;
}
- public String getAccountTitle()
- {
+ public String getAccountTitle() {
return accountTitle;
}
@Override
- public String toString()
- {
+ public String toString() {
return "BankAccount{" +
"bankAccountType=" + bankAccountType +
", accountPrimaryID='" + accountPrimaryID + '\'' +
diff --git a/src/main/java/io/bitsquare/bank/BankAccountType.java b/src/main/java/io/bitsquare/bank/BankAccountType.java
index eeaaeee29a..c25d8b8058 100644
--- a/src/main/java/io/bitsquare/bank/BankAccountType.java
+++ b/src/main/java/io/bitsquare/bank/BankAccountType.java
@@ -20,8 +20,7 @@ package io.bitsquare.bank;
import java.util.ArrayList;
import java.util.Arrays;
-public enum BankAccountType
-{
+public enum BankAccountType {
SEPA("IBAN", "BIC"),
WIRE("primary ID", "secondary ID"),
INTERNATIONAL("primary ID", "secondary ID"),
@@ -33,24 +32,20 @@ public enum BankAccountType
private final String primaryId;
private final String secondaryId;
- BankAccountType(String primaryId, String secondaryId)
- {
+ BankAccountType(String primaryId, String secondaryId) {
this.primaryId = primaryId;
this.secondaryId = secondaryId;
}
- public static ArrayList getAllBankAccountTypes()
- {
+ public static ArrayList getAllBankAccountTypes() {
return new ArrayList<>(Arrays.asList(BankAccountType.values()));
}
- public String getPrimaryId()
- {
+ public String getPrimaryId() {
return primaryId;
}
- public String getSecondaryId()
- {
+ public String getSecondaryId() {
return secondaryId;
}
}
diff --git a/src/main/java/io/bitsquare/btc/AddressBasedCoinSelector.java b/src/main/java/io/bitsquare/btc/AddressBasedCoinSelector.java
index 0b4e169576..3e1bcc60f1 100644
--- a/src/main/java/io/bitsquare/btc/AddressBasedCoinSelector.java
+++ b/src/main/java/io/bitsquare/btc/AddressBasedCoinSelector.java
@@ -22,8 +22,10 @@ import com.google.bitcoin.params.RegTestParams;
import com.google.bitcoin.wallet.CoinSelection;
import com.google.bitcoin.wallet.DefaultCoinSelector;
import com.google.common.annotations.VisibleForTesting;
+
import java.math.BigInteger;
import java.util.*;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,8 +34,7 @@ import org.slf4j.LoggerFactory;
* possible. This means that the transaction is the most likely to get confirmed. Note that this means we may end up
* "spending" more priority than would be required to get the transaction we are creating confirmed.
*/
-public class AddressBasedCoinSelector extends DefaultCoinSelector
-{
+public class AddressBasedCoinSelector extends DefaultCoinSelector {
private static final Logger log = LoggerFactory.getLogger(AddressBasedCoinSelector.class);
private final NetworkParameters params;
private final AddressEntry addressEntry;
@@ -48,8 +49,7 @@ public class AddressBasedCoinSelector extends DefaultCoinSelector
this(params, addressInfo, false);
} */
- public AddressBasedCoinSelector(NetworkParameters params, AddressEntry addressEntry, boolean includePending)
- {
+ public AddressBasedCoinSelector(NetworkParameters params, AddressEntry addressEntry, boolean includePending) {
this.params = params;
this.addressEntry = addressEntry;
this.includePending = includePending;
@@ -57,13 +57,10 @@ public class AddressBasedCoinSelector extends DefaultCoinSelector
@SuppressWarnings("WeakerAccess")
@VisibleForTesting
- static void sortOutputs(ArrayList outputs)
- {
- Collections.sort(outputs, new Comparator()
- {
+ static void sortOutputs(ArrayList outputs) {
+ Collections.sort(outputs, new Comparator() {
@Override
- public int compare(TransactionOutput a, TransactionOutput b)
- {
+ public int compare(TransactionOutput a, TransactionOutput b) {
int depth1 = 0;
int depth2 = 0;
TransactionConfidence conf1 = a.getParentTransaction().getConfidence();
@@ -89,8 +86,7 @@ public class AddressBasedCoinSelector extends DefaultCoinSelector
});
}
- private static boolean isInBlockChainOrPending(Transaction tx)
- {
+ private static boolean isInBlockChainOrPending(Transaction tx) {
// Pick chain-included transactions and transactions that are pending.
TransactionConfidence confidence = tx.getConfidence();
TransactionConfidence.ConfidenceType type = confidence.getConfidenceType();
@@ -100,8 +96,7 @@ public class AddressBasedCoinSelector extends DefaultCoinSelector
(confidence.numBroadcastPeers() > 1 || tx.getParams() == RegTestParams.get());
}
- private static boolean isInBlockChain(Transaction tx)
- {
+ private static boolean isInBlockChain(Transaction tx) {
// Only pick chain-included transactions.
TransactionConfidence confidence = tx.getConfidence();
TransactionConfidence.ConfidenceType type = confidence.getConfidenceType();
@@ -111,26 +106,19 @@ public class AddressBasedCoinSelector extends DefaultCoinSelector
/**
* Sub-classes can override this to just customize whether transactions are usable, but keep age sorting.
*/
- protected boolean shouldSelect(Transaction tx)
- {
- if (includePending)
- {
+ protected boolean shouldSelect(Transaction tx) {
+ if (includePending) {
return isInBlockChainOrPending(tx);
- }
- else
- {
+ } else {
return isInBlockChain(tx);
}
}
@SuppressWarnings("WeakerAccess")
- protected boolean matchesRequiredAddress(TransactionOutput transactionOutput)
- {
- if (transactionOutput.getScriptPubKey().isSentToAddress() || transactionOutput.getScriptPubKey().isSentToP2SH())
- {
+ protected boolean matchesRequiredAddress(TransactionOutput transactionOutput) {
+ if (transactionOutput.getScriptPubKey().isSentToAddress() || transactionOutput.getScriptPubKey().isSentToP2SH()) {
Address addressOutput = transactionOutput.getScriptPubKey().getToAddress(params);
- if (addressEntry != null && addressOutput.equals(addressEntry.getAddress()))
- {
+ if (addressEntry != null && addressOutput.equals(addressEntry.getAddress())) {
return true;
}
}
@@ -138,8 +126,7 @@ public class AddressBasedCoinSelector extends DefaultCoinSelector
}
@Override
- public CoinSelection select(Coin target, List candidates)
- {
+ public CoinSelection select(Coin target, List candidates) {
long targetAsLong = target.longValue();
HashSet selected = new HashSet<>();
// Sort the inputs by age*value so we get the highest "coindays" spent.
@@ -147,23 +134,19 @@ public class AddressBasedCoinSelector extends DefaultCoinSelector
ArrayList sortedOutputs = new ArrayList<>(candidates);
// When calculating the wallet balance, we may be asked to select all possible coins, if so, avoid sorting
// them in order to improve performance.
- if (!target.equals(NetworkParameters.MAX_MONEY))
- {
+ if (!target.equals(NetworkParameters.MAX_MONEY)) {
sortOutputs(sortedOutputs);
}
// Now iterate over the sorted outputs until we have got as close to the target as possible or a little
// bit over (excessive value will be change).
long total = 0;
- for (TransactionOutput output : sortedOutputs)
- {
- if (total >= targetAsLong)
- {
+ for (TransactionOutput output : sortedOutputs) {
+ if (total >= targetAsLong) {
break;
}
// Only pick chain-included transactions, or transactions that are ours and pending.
// Only select outputs from our defined address(es)
- if (!shouldSelect(output.getParentTransaction()) || !matchesRequiredAddress(output))
- {
+ if (!shouldSelect(output.getParentTransaction()) || !matchesRequiredAddress(output)) {
continue;
}
diff --git a/src/main/java/io/bitsquare/btc/AddressEntry.java b/src/main/java/io/bitsquare/btc/AddressEntry.java
index 08232d3b2f..9a1889b267 100644
--- a/src/main/java/io/bitsquare/btc/AddressEntry.java
+++ b/src/main/java/io/bitsquare/btc/AddressEntry.java
@@ -21,10 +21,10 @@ import com.google.bitcoin.core.Address;
import com.google.bitcoin.core.NetworkParameters;
import com.google.bitcoin.core.Utils;
import com.google.bitcoin.crypto.DeterministicKey;
+
import java.io.Serializable;
-public class AddressEntry implements Serializable
-{
+public class AddressEntry implements Serializable {
private static final long serialVersionUID = 5501603992599920416L;
private transient DeterministicKey key;
private final NetworkParameters params;
@@ -33,13 +33,11 @@ public class AddressEntry implements Serializable
private final byte[] pubKeyHash;
- public AddressEntry(DeterministicKey key, NetworkParameters params, AddressContext addressContext)
- {
+ public AddressEntry(DeterministicKey key, NetworkParameters params, AddressContext addressContext) {
this(key, params, addressContext, null);
}
- public AddressEntry(DeterministicKey key, NetworkParameters params, AddressContext addressContext, String offerId)
- {
+ public AddressEntry(DeterministicKey key, NetworkParameters params, AddressContext addressContext, String offerId) {
this.key = key;
this.params = params;
this.addressContext = addressContext;
@@ -48,48 +46,39 @@ public class AddressEntry implements Serializable
pubKeyHash = key.getPubOnly().getPubKeyHash();
}
- public String getOfferId()
- {
+ public String getOfferId() {
return offerId;
}
- public AddressContext getAddressContext()
- {
+ public AddressContext getAddressContext() {
return addressContext;
}
- public String getAddressString()
- {
+ public String getAddressString() {
return getAddress().toString();
}
- public String getPubKeyAsHexString()
- {
+ public String getPubKeyAsHexString() {
return Utils.HEX.encode(key.getPubKey());
}
- public DeterministicKey getKey()
- {
+ public DeterministicKey getKey() {
return key;
}
- public Address getAddress()
- {
+ public Address getAddress() {
return key.toAddress(params);
}
- public void setDeterministicKey(DeterministicKey key)
- {
+ public void setDeterministicKey(DeterministicKey key) {
this.key = key;
}
- public byte[] getPubKeyHash()
- {
+ public byte[] getPubKeyHash() {
return pubKeyHash;
}
- public static enum AddressContext
- {
+ public static enum AddressContext {
REGISTRATION_FEE,
TRADE,
ARBITRATOR_DEPOSIT
diff --git a/src/main/java/io/bitsquare/btc/BlockChainFacade.java b/src/main/java/io/bitsquare/btc/BlockChainFacade.java
index 8d38a15fd5..b7d6cd1849 100644
--- a/src/main/java/io/bitsquare/btc/BlockChainFacade.java
+++ b/src/main/java/io/bitsquare/btc/BlockChainFacade.java
@@ -18,29 +18,26 @@
package io.bitsquare.btc;
import io.bitsquare.bank.BankAccount;
+
import javax.inject.Inject;
/**
* That facade delivers blockchain functionality from the bitcoinJ library
*/
@SuppressWarnings({"SameReturnValue", "UnusedParameters"})
-public class BlockChainFacade
-{
+public class BlockChainFacade {
@Inject
- public BlockChainFacade()
- {
+ public BlockChainFacade() {
}
//TODO
- public boolean isAccountBlackListed(String accountID, BankAccount bankAccount)
- {
+ public boolean isAccountBlackListed(String accountID, BankAccount bankAccount) {
return false;
}
//TODO
- public boolean verifyAccountRegistration()
- {
+ public boolean verifyAccountRegistration() {
return true;
// tx id 76982adc582657b2eb68f3e43341596a68aadc4ef6b9590e88e93387d4d5d1f9
@@ -52,37 +49,32 @@ public class BlockChainFacade
return true; */
}
- private boolean findAddressInBlockChain(String address)
- {
+ private boolean findAddressInBlockChain(String address) {
// TODO
// lookup for address in blockchain
return true;
}
- private byte[] getDataForTxWithAddress(String address)
- {
+ private byte[] getDataForTxWithAddress(String address) {
// TODO
// return data after OP_RETURN
return null;
}
- private boolean isFeePayed(String address)
- {
+ private boolean isFeePayed(String address) {
// TODO
// check if fee is payed
return true;
}
- private boolean isAccountIDBlacklisted(String accountID)
- {
+ private boolean isAccountIDBlacklisted(String accountID) {
// TODO
// check if accountID is on blacklist
return false;
}
- private boolean isBankAccountBlacklisted(BankAccount bankAccount)
- {
+ private boolean isBankAccountBlacklisted(BankAccount bankAccount) {
// TODO
// check if accountID is on blacklist
return false;
diff --git a/src/main/java/io/bitsquare/btc/BtcValidator.java b/src/main/java/io/bitsquare/btc/BtcValidator.java
index 73c776abf7..9bb278dca1 100644
--- a/src/main/java/io/bitsquare/btc/BtcValidator.java
+++ b/src/main/java/io/bitsquare/btc/BtcValidator.java
@@ -20,20 +20,18 @@ package io.bitsquare.btc;
import com.google.bitcoin.core.Coin;
import com.google.bitcoin.core.NetworkParameters;
import com.google.bitcoin.core.Transaction;
+
import javax.inject.Inject;
-public class BtcValidator
-{
+public class BtcValidator {
private static NetworkParameters params;
@Inject
- public BtcValidator(NetworkParameters params)
- {
+ public BtcValidator(NetworkParameters params) {
BtcValidator.params = params;
}
- public static boolean isMinSpendableAmount(Coin amount)
- {
+ public static boolean isMinSpendableAmount(Coin amount) {
return amount != null && amount.compareTo(FeePolicy.TX_FEE.add(Transaction.MIN_NONDUST_OUTPUT)) > 0;
}
diff --git a/src/main/java/io/bitsquare/btc/FeePolicy.java b/src/main/java/io/bitsquare/btc/FeePolicy.java
index d536e308e8..621d1feb06 100644
--- a/src/main/java/io/bitsquare/btc/FeePolicy.java
+++ b/src/main/java/io/bitsquare/btc/FeePolicy.java
@@ -18,12 +18,13 @@
package io.bitsquare.btc;
import com.google.bitcoin.core.*;
+
import javax.inject.Inject;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class FeePolicy
-{
+public class FeePolicy {
public static final Coin TX_FEE = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE;
public static final Coin ACCOUNT_REGISTRATION_FEE = Coin.CENT; // 0.01
public static final Coin CREATE_OFFER_FEE = Coin.MILLICOIN; // 0.001
@@ -36,20 +37,16 @@ public class FeePolicy
private final NetworkParameters params;
@Inject
- public FeePolicy(NetworkParameters params)
- {
+ public FeePolicy(NetworkParameters params) {
this.params = params;
}
//TODO other users or dev address? use donation option list? (dev, other users, wikileaks, tor, sub projects (bitcoinj, tomp2p,...)...)
- public Address getAddressForRegistrationFee()
- {
- try
- {
+ public Address getAddressForRegistrationFee() {
+ try {
return new Address(params, registrationFeeAddress);
- } catch (AddressFormatException e)
- {
+ } catch (AddressFormatException e) {
e.printStackTrace();
return null;
}
@@ -57,13 +54,10 @@ public class FeePolicy
//TODO get address form arbitrator list
- public Address getAddressForCreateOfferFee()
- {
- try
- {
+ public Address getAddressForCreateOfferFee() {
+ try {
return new Address(params, createOfferFeeAddress);
- } catch (AddressFormatException e)
- {
+ } catch (AddressFormatException e) {
e.printStackTrace();
return null;
}
@@ -71,13 +65,10 @@ public class FeePolicy
//TODO get address form the intersection of both traders arbitrator lists
- public Address getAddressForTakeOfferFee()
- {
- try
- {
+ public Address getAddressForTakeOfferFee() {
+ try {
return new Address(params, takeOfferFeeAddress);
- } catch (AddressFormatException e)
- {
+ } catch (AddressFormatException e) {
e.printStackTrace();
return null;
}
diff --git a/src/main/java/io/bitsquare/btc/Restritions.java b/src/main/java/io/bitsquare/btc/Restritions.java
index eee451e3db..59385366dc 100644
--- a/src/main/java/io/bitsquare/btc/Restritions.java
+++ b/src/main/java/io/bitsquare/btc/Restritions.java
@@ -19,8 +19,7 @@ package io.bitsquare.btc;
import com.google.bitcoin.core.Coin;
-public class Restritions
-{
+public class Restritions {
public static final Coin MIN_TRADE_AMOUNT = Coin.CENT; // 0.01 Bitcoins
diff --git a/src/main/java/io/bitsquare/btc/WalletFacade.java b/src/main/java/io/bitsquare/btc/WalletFacade.java
index 015f3505a4..8ea4c854d9 100644
--- a/src/main/java/io/bitsquare/btc/WalletFacade.java
+++ b/src/main/java/io/bitsquare/btc/WalletFacade.java
@@ -36,15 +36,19 @@ import io.bitsquare.btc.listeners.ConfidenceListener;
import io.bitsquare.crypto.CryptoFacade;
import io.bitsquare.storage.Persistence;
import io.bitsquare.util.StorageDirectory;
+
import java.io.Serializable;
import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
+
import javafx.application.Platform;
import javafx.util.Pair;
+
import javax.annotation.concurrent.GuardedBy;
import javax.inject.Inject;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -54,8 +58,7 @@ import static com.google.bitcoin.script.ScriptOpCodes.OP_RETURN;
* TODO: use walletextension (with protobuffer) instead of saving addressEntryList via storage
* TODO: use HD wallet features instead of addressEntryList
*/
-public class WalletFacade
-{
+public class WalletFacade {
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";
@@ -88,8 +91,7 @@ public class WalletFacade
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
- public WalletFacade(NetworkParameters params, FeePolicy feePolicy, CryptoFacade cryptoFacade, Persistence persistence)
- {
+ public WalletFacade(NetworkParameters params, FeePolicy feePolicy, CryptoFacade cryptoFacade, Persistence persistence) {
this.params = params;
this.feePolicy = feePolicy;
this.cryptoFacade = cryptoFacade;
@@ -101,8 +103,7 @@ public class WalletFacade
// Public Methods
///////////////////////////////////////////////////////////////////////////////////////////
- public void initialize(StartupListener startupListener)
- {
+ public void initialize(StartupListener startupListener) {
// Tell bitcoinj to execute 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
@@ -110,11 +111,9 @@ public class WalletFacade
Threading.USER_THREAD = Platform::runLater;
// If seed is non-null it means we are restoring from backup.
- walletAppKit = new WalletAppKit(params, StorageDirectory.getStorageDirectory(), WALLET_PREFIX)
- {
+ walletAppKit = new WalletAppKit(params, StorageDirectory.getStorageDirectory(), WALLET_PREFIX) {
@Override
- protected void onSetupCompleted()
- {
+ protected void onSetupCompleted() {
// Don't make the user wait for confirmations for now, as the intention is they're sending it
// their own money!
walletAppKit.wallet().allowSpendingUnconfirmedTransactions();
@@ -127,12 +126,9 @@ public class WalletFacade
};
// 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())
- {
+ if (params == RegTestParams.get()) {
walletAppKit.connectToLocalHost(); // You should run a regtest mode bitcoind locally.
- }
- else if (params == MainNetParams.get())
- {
+ } else if (params == 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
@@ -142,68 +138,58 @@ public class WalletFacade
// walletAppKit.useTor();
}
walletAppKit.setDownloadListener(new BlockChainDownloadListener())
- .setBlockingStartup(false)
- .restoreWalletFromSeed(null)
- .setUserAgent("BitSquare", "0.1");
+ .setBlockingStartup(false)
+ .restoreWalletFromSeed(null)
+ .setUserAgent("BitSquare", "0.1");
walletAppKit.startAsync();
}
- private void initWallet()
- {
+ private void initWallet() {
wallet = walletAppKit.wallet();
wallet.allowSpendingUnconfirmedTransactions();
//walletAppKit.peerGroup().setMaxConnections(11);
- if (params == RegTestParams.get())
- {
+ if (params == RegTestParams.get()) {
walletAppKit.peerGroup().setMinBroadcastConnections(1);
}
/* else
walletAppKit.peerGroup().setMinBroadcastConnections(2); */
- walletEventListener = new WalletEventListener()
- {
+ walletEventListener = new WalletEventListener() {
@Override
- public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance)
- {
+ public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
notifyBalanceListeners();
}
@Override
- public void onCoinsSent(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance)
- {
+ public void onCoinsSent(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
notifyBalanceListeners();
}
@Override
- public void onReorganize(Wallet wallet)
- {
+ public void onReorganize(Wallet wallet) {
}
@Override
- public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx)
- {
+ public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx) {
notifyConfidenceListeners(tx);
}
@Override
- public void onWalletChanged(Wallet wallet)
- {
+ public void onWalletChanged(Wallet wallet) {
}
@Override
- public void onScriptsAdded(Wallet wallet, List