From 7d6ca37d066b490f5d8fbad6632e9dfb6f169613 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Tue, 26 Aug 2014 09:20:10 +0200 Subject: [PATCH] Apply formatting to Java sources This is essentially the default IDEA formatting settings, with one tweak made to allow same-line field annotations (useful particularly in the case of the @FXML annotation) --- src/main/java/io/bitsquare/BitSquare.java | 23 +- src/main/java/io/bitsquare/SeedNode.java | 99 ++--- .../java/io/bitsquare/bank/BankAccount.java | 40 +- .../io/bitsquare/bank/BankAccountType.java | 15 +- .../btc/AddressBasedCoinSelector.java | 57 +-- .../java/io/bitsquare/btc/AddressEntry.java | 37 +- .../io/bitsquare/btc/BlockChainFacade.java | 28 +- .../java/io/bitsquare/btc/BtcValidator.java | 10 +- src/main/java/io/bitsquare/btc/FeePolicy.java | 35 +- .../java/io/bitsquare/btc/Restritions.java | 3 +- .../java/io/bitsquare/btc/WalletFacade.java | 329 ++++++---------- .../btc/listeners/BalanceListener.java | 15 +- .../btc/listeners/ConfidenceListener.java | 12 +- .../io/bitsquare/crypto/CryptoFacade.java | 41 +- .../java/io/bitsquare/di/BitSquareModule.java | 19 +- .../java/io/bitsquare/di/GuiceFXMLLoader.java | 47 +-- .../bitsquare/gui/CachedViewController.java | 16 +- .../java/io/bitsquare/gui/MainController.java | 130 +++--- .../java/io/bitsquare/gui/NavigationItem.java | 18 +- .../java/io/bitsquare/gui/ViewController.java | 16 +- .../ArbitratorOverviewController.java | 86 ++-- .../profile/ArbitratorProfileController.java | 36 +- .../ArbitratorRegistrationController.java | 228 ++++------- src/main/java/io/bitsquare/gui/bitsquare.css | 27 +- .../gui/components/CachingTabPane.java | 41 +- .../io/bitsquare/gui/components/HSpacer.java | 12 +- .../gui/components/NetworkSyncPane.java | 12 +- .../gui/components/NoFocusScrollPane.java | 9 +- .../io/bitsquare/gui/components/Popups.java | 63 ++- .../io/bitsquare/gui/components/VSpacer.java | 12 +- .../gui/components/ValidatedTextField.java | 106 ++--- .../gui/components/ValidatingTextField.java | 70 ++-- .../gui/components/btc/AddressTextField.java | 29 +- .../gui/components/btc/BalanceTextField.java | 48 +-- .../ConfidenceProgressIndicator.java | 78 ++-- .../ConfidenceProgressIndicatorBehavior.java | 7 +- .../skin/ConfidenceProgressIndicatorSkin.java | 346 ++++++---------- .../components/processbar/ProcessStepBar.java | 25 +- .../processbar/ProcessStepBarSkin.java | 62 ++- .../processbar/ProcessStepItem.java | 21 +- .../bitsquare/gui/funds/FundsController.java | 20 +- .../gui/funds/deposit/DepositController.java | 110 ++---- .../gui/funds/deposit/DepositListItem.java | 6 +- .../transactions/TransactionsController.java | 63 ++- .../transactions/TransactionsListItem.java | 99 ++--- .../withdrawal/WithdrawalController.java | 156 +++----- .../funds/withdrawal/WithdrawalListItem.java | 60 +-- .../io/bitsquare/gui/home/HomeController.java | 32 +- .../io/bitsquare/gui/msg/MsgController.java | 23 +- .../gui/orders/OrdersController.java | 26 +- .../orders/closed/ClosedTradeController.java | 17 +- .../gui/orders/offer/OfferController.java | 69 ++-- .../gui/orders/offer/OfferListItem.java | 24 +- .../pending/PendingTradeController.java | 200 ++++------ .../orders/pending/PendingTradesListItem.java | 9 +- .../gui/settings/SettingsController.java | 372 +++++++----------- .../io/bitsquare/gui/trade/BuyController.java | 6 +- .../bitsquare/gui/trade/SellController.java | 6 +- .../bitsquare/gui/trade/TradeController.java | 59 +-- .../createoffer/CreateOfferController.java | 98 ++--- .../trade/orderbook/OrderBookController.java | 282 +++++-------- .../trade/orderbook/OrderBookListItem.java | 18 +- .../trade/takeoffer/TakerOfferController.java | 143 +++---- .../gui/util/BitSquareFormatter.java | 101 ++--- .../gui/util/BitSquareValidator.java | 106 ++--- .../io/bitsquare/gui/util/BtcValidator.java | 25 +- .../java/io/bitsquare/gui/util/Colors.java | 3 +- .../bitsquare/gui/util/ConfidenceDisplay.java | 105 ++--- .../io/bitsquare/gui/util/FiatValidator.java | 20 +- .../java/io/bitsquare/gui/util/ImageUtil.java | 9 +- .../bitsquare/gui/util/NumberValidator.java | 44 +-- .../java/io/bitsquare/gui/util/Profiler.java | 27 +- .../io/bitsquare/gui/util/Transitions.java | 39 +- .../bitsquare/gui/util/ValidationHelper.java | 54 +-- .../java/io/bitsquare/locale/Country.java | 30 +- .../java/io/bitsquare/locale/CountryUtil.java | 41 +- .../io/bitsquare/locale/CurrencyUtil.java | 9 +- .../io/bitsquare/locale/LanguageUtil.java | 12 +- .../io/bitsquare/locale/Localisation.java | 47 +-- src/main/java/io/bitsquare/locale/Region.java | 27 +- .../io/bitsquare/msg/BootstrapListener.java | 3 +- .../msg/BootstrappedPeerFactory.java | 151 +++---- .../java/io/bitsquare/msg/MessageBroker.java | 3 +- .../java/io/bitsquare/msg/MessageFacade.java | 282 +++++-------- src/main/java/io/bitsquare/msg/P2PNode.java | 147 +++---- .../io/bitsquare/msg/SeedNodeAddress.java | 36 +- .../msg/listeners/ArbitratorListener.java | 4 +- .../msg/listeners/GetPeerAddressListener.java | 3 +- .../IncomingTradeMessageListener.java | 3 +- .../msg/listeners/OrderBookListener.java | 4 +- .../OutgoingTradeMessageListener.java | 3 +- .../msg/listeners/PingPeerListener.java | 3 +- .../listeners/TakeOfferRequestListener.java | 3 +- .../java/io/bitsquare/settings/Settings.java | 58 +-- .../io/bitsquare/storage/Persistence.java | 154 +++----- .../java/io/bitsquare/trade/Contract.java | 37 +- .../java/io/bitsquare/trade/Direction.java | 3 +- src/main/java/io/bitsquare/trade/Offer.java | 70 ++-- src/main/java/io/bitsquare/trade/Trade.java | 86 ++-- .../java/io/bitsquare/trade/TradeManager.java | 338 +++++++--------- .../trade/handlers/ErrorMessageHandler.java | 3 +- .../trade/handlers/ExceptionHandler.java | 3 +- .../trade/handlers/FaultHandler.java | 3 +- .../trade/handlers/ResultHandler.java | 3 +- .../handlers/TransactionResultHandler.java | 3 +- .../bitsquare/trade/orderbook/OrderBook.java | 140 +++---- .../trade/orderbook/OrderBookFilter.java | 24 +- .../trade/protocol/TradeMessage.java | 3 +- .../createoffer/CreateOfferCoordinator.java | 50 +-- .../tasks/BroadCastOfferFeeTx.java | 37 +- .../createoffer/tasks/CreateOfferFeeTx.java | 15 +- .../createoffer/tasks/PublishOfferToDHT.java | 15 +- .../createoffer/tasks/ValidateOffer.java | 14 +- .../offerer/BankTransferInitedMessage.java | 28 +- .../protocol/offerer/CreateDepositTx.java | 15 +- .../offerer/DepositTxPublishedMessage.java | 13 +- .../offerer/HandleTakeOfferRequest.java | 21 +- .../offerer/ProtocolForOffererAsBuyer.java | 153 ++++--- .../ProtocolForOffererAsBuyerListener.java | 3 +- .../offerer/RequestTakerDepositPayment.java | 15 +- .../RequestTakerDepositPaymentMessage.java | 25 +- .../RespondToTakeOfferRequestMessage.java | 13 +- .../offerer/SendDepositTxIdToTaker.java | 15 +- .../protocol/offerer/SendSignedPayoutTx.java | 33 +- ...etupListenerForBlockChainConfirmation.java | 18 +- .../offerer/SignAndPublishDepositTx.java | 52 ++- .../offerer/VerifyAndSignContract.java | 11 +- .../offerer/VerifyTakeOfferFeePayment.java | 9 +- .../protocol/offerer/VerifyTakerAccount.java | 6 +- .../old/BuyOffererPaymentProcess.java | 15 +- .../protocol/old/BuyTakerPaymentProcess.java | 15 +- .../trade/protocol/old/PaymentProcess.java | 95 ++--- .../old/SellOffererPaymentProcess.java | 18 +- .../protocol/old/SellTakerPaymentProcess.java | 18 +- .../protocol/shared/VerifyPeerAccount.java | 20 +- .../protocol/taker/CreateAndSignContract.java | 17 +- .../trade/protocol/taker/GetPeerAddress.java | 20 +- .../trade/protocol/taker/PayDeposit.java | 27 +- .../trade/protocol/taker/PayTakeOfferFee.java | 24 +- .../taker/PayoutTxPublishedMessage.java | 13 +- .../taker/ProtocolForTakerAsSeller.java | 138 +++---- .../ProtocolForTakerAsSellerListener.java | 3 +- ...RequestOffererPublishDepositTxMessage.java | 43 +- .../protocol/taker/RequestTakeOffer.java | 15 +- .../taker/RequestTakeOfferMessage.java | 10 +- .../protocol/taker/SendPayoutTxToOfferer.java | 15 +- .../taker/SendSignedTakerDepositTxAsHex.java | 45 +-- .../taker/SendTakeOfferFeePayedTxId.java | 15 +- .../taker/SignAndPublishPayoutTx.java | 56 ++- .../taker/TakeOfferFeePayedMessage.java | 19 +- .../protocol/taker/VerifyOffererAccount.java | 6 +- .../java/io/bitsquare/user/Arbitrator.java | 88 ++--- .../java/io/bitsquare/user/Reputation.java | 10 +- src/main/java/io/bitsquare/user/User.java | 83 ++-- .../java/io/bitsquare/util/AWTSystemTray.java | 42 +- .../java/io/bitsquare/util/DSAKeyUtil.java | 17 +- src/main/java/io/bitsquare/util/FileUtil.java | 27 +- .../io/bitsquare/util/StorageDirectory.java | 37 +- .../java/io/bitsquare/util/Utilities.java | 83 ++-- .../java/io/bitsquare/util/Validator.java | 15 +- .../java/io/bitsquare/BitSquareTestSuite.java | 17 +- .../io/bitsquare/btc/BtcValidatorTest.java | 6 +- .../gui/util/BitSquareConverterTest.java | 6 +- .../util/BitSquareNumberValidatorTest.java | 9 +- .../bitsquare/gui/util/BtcValidatorTest.java | 6 +- .../bitsquare/gui/util/FiatValidatorTest.java | 6 +- .../java/io/bitsquare/msg/P2PNodeTest.java | 105 ++--- src/test/java/io/bitsquare/msg/UtilsDHT2.java | 201 ++++------ 168 files changed, 3005 insertions(+), 5439 deletions(-) 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