From a2aa0b40b4c11ec39a3249bf8a6891c955a10da5 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Fri, 3 Apr 2015 16:51:36 +0200 Subject: [PATCH] Handle views for trade process --- .../common/taskrunner/TaskRunner.java | 9 +- .../main/portfolio/pending/BuyerSubView.java | 5 +- .../pending/MissingTradeException.java | 30 ++++ .../pending/NoTradeFoundException.java | 30 ++++ .../pending/PendingTradesDataModel.java | 151 ++++++++++-------- .../portfolio/pending/PendingTradesView.java | 84 ++++++++-- .../pending/PendingTradesViewModel.java | 58 ++++--- .../main/portfolio/pending/SellerSubView.java | 5 +- .../main/portfolio/pending/TradeSubView.java | 2 +- .../pending/steps/StartFiatView.java | 3 +- .../pending/steps/TradeStepDetailsView.java | 1 + .../trade/createoffer/CreateOfferView.java | 3 +- .../main/java/io/bitsquare/offer/Offer.java | 3 +- .../io/bitsquare/storage/FileManager.java | 9 +- .../main/java/io/bitsquare/trade/Trade.java | 9 +- .../trade/protocol/trade/ProcessModel.java | 10 -- .../trade/protocol/trade/TradingPeer.java | 21 --- .../trade/protocol/placeoffer/TaskRunner.java | 136 ---------------- 18 files changed, 273 insertions(+), 296 deletions(-) create mode 100644 core/src/main/java/io/bitsquare/gui/main/portfolio/pending/MissingTradeException.java create mode 100644 core/src/main/java/io/bitsquare/gui/main/portfolio/pending/NoTradeFoundException.java delete mode 100644 core/src/test/java/io/bitsquare/trade/protocol/placeoffer/TaskRunner.java diff --git a/core/src/main/java/io/bitsquare/common/taskrunner/TaskRunner.java b/core/src/main/java/io/bitsquare/common/taskrunner/TaskRunner.java index 94023b8e1a..edd6aabc8b 100644 --- a/core/src/main/java/io/bitsquare/common/taskrunner/TaskRunner.java +++ b/core/src/main/java/io/bitsquare/common/taskrunner/TaskRunner.java @@ -61,14 +61,7 @@ public class TaskRunner { try { currentTask = tasks.poll(); log.trace("Run task: " + currentTask.getSimpleName()); - log.debug("sharedModel.getClass() " + sharedModel.getClass()); - log.debug("sharedModel.getClass().getSuperclass() " + sharedModel.getClass().getSuperclass()); - /* Object c = currentTask.getDeclaredConstructor(TaskRunner.class, sharedModel.getClass()); - log.debug("c " + c); - Object c2 = currentTask.getDeclaredConstructor(TaskRunner.class, sharedModel.getClass().getSuperclass()); - log.debug("c getSuperclass " + c2); - Object o = currentTask.getDeclaredConstructor(TaskRunner.class, sharedModel.getClass()).newInstance(this, sharedModel);*/ - //TODO solve in tasks problem with superclasses + // We use also super class as type ein tasks, so we need to support both variants try { currentTask.getDeclaredConstructor(TaskRunner.class, sharedModel.getClass()).newInstance(this, sharedModel).run(); } catch (Throwable throwable) { diff --git a/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/BuyerSubView.java b/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/BuyerSubView.java index 17bd86e42f..13259dd425 100644 --- a/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/BuyerSubView.java +++ b/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/BuyerSubView.java @@ -79,8 +79,11 @@ public class BuyerSubView extends TradeSubView { waitFiatReceived.inactive(); completed.inactive(); + if (tradeStepDetailsView != null) + tradeStepDetailsView.deactivate(); + switch (viewState) { - case EMPTY: + case UNDEFINED: break; case BUYER_WAIT_TX_CONF: showItem(waitTxInBlockchain); diff --git a/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/MissingTradeException.java b/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/MissingTradeException.java new file mode 100644 index 0000000000..e0aac02bf9 --- /dev/null +++ b/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/MissingTradeException.java @@ -0,0 +1,30 @@ +/* + * This file is part of Bitsquare. + * + * Bitsquare is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bitsquare is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bitsquare. If not, see . + */ + +package io.bitsquare.gui.main.portfolio.pending; + +// That is used if trade is null but must not be null in that state +public class MissingTradeException extends RuntimeException { + + public MissingTradeException(String msg) { + super(msg); + } + + public MissingTradeException() { + super("Trade is null.That must not happen."); + } +} diff --git a/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/NoTradeFoundException.java b/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/NoTradeFoundException.java new file mode 100644 index 0000000000..a991254c93 --- /dev/null +++ b/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/NoTradeFoundException.java @@ -0,0 +1,30 @@ +/* + * This file is part of Bitsquare. + * + * Bitsquare is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bitsquare is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bitsquare. If not, see . + */ + +package io.bitsquare.gui.main.portfolio.pending; + +// That is used if trade is null and it is a valid state +public class NoTradeFoundException extends Throwable { + + public NoTradeFoundException(String msg) { + super(msg); + } + + public NoTradeFoundException() { + super("Trade is null"); + } +} diff --git a/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/PendingTradesDataModel.java b/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/PendingTradesDataModel.java index 12aeb330ac..eba40bffeb 100644 --- a/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/PendingTradesDataModel.java +++ b/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/PendingTradesDataModel.java @@ -21,7 +21,11 @@ import io.bitsquare.btc.FeePolicy; import io.bitsquare.btc.WalletService; import io.bitsquare.common.viewfx.model.Activatable; import io.bitsquare.common.viewfx.model.DataModel; +import io.bitsquare.gui.Navigation; import io.bitsquare.gui.components.Popups; +import io.bitsquare.gui.main.MainView; +import io.bitsquare.gui.main.portfolio.PortfolioView; +import io.bitsquare.gui.main.portfolio.closed.ClosedTradesView; import io.bitsquare.offer.Offer; import io.bitsquare.trade.BuyerTrade; import io.bitsquare.trade.Contract; @@ -37,9 +41,8 @@ import com.google.inject.Inject; import java.util.stream.Collectors; -import javafx.beans.property.IntegerProperty; +import javafx.application.Platform; import javafx.beans.property.ObjectProperty; -import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; @@ -56,6 +59,7 @@ class PendingTradesDataModel implements Activatable, DataModel { private final TradeManager tradeManager; private final WalletService walletService; private final User user; + private Navigation navigation; private final ObservableList list = FXCollections.observableArrayList(); @@ -65,7 +69,6 @@ class PendingTradesDataModel implements Activatable, DataModel { private final ListChangeListener tradesListChangeListener; final StringProperty txId = new SimpleStringProperty(); - final IntegerProperty selectedIndex = new SimpleIntegerProperty(-1); final ObjectProperty sellerProcessState = new SimpleObjectProperty<>(); final ObjectProperty buyerProcessState = new SimpleObjectProperty<>(); @@ -73,23 +76,19 @@ class PendingTradesDataModel implements Activatable, DataModel { final ObjectProperty currentTrade = new SimpleObjectProperty<>(); @Inject - public PendingTradesDataModel(TradeManager tradeManager, WalletService walletService, User user) { + public PendingTradesDataModel(TradeManager tradeManager, WalletService walletService, User user, Navigation navigation) { this.tradeManager = tradeManager; this.walletService = walletService; this.user = user; + this.navigation = navigation; tradesListChangeListener = change -> onListChanged(); } @Override public void activate() { - onListChanged(); tradeManager.getPendingTrades().addListener(tradesListChangeListener); - - if (list.size() > 0) { - selectTrade(list.get(0)); - selectedIndex.set(0); - } + onListChanged(); } @Override @@ -105,20 +104,22 @@ class PendingTradesDataModel implements Activatable, DataModel { // we sort by date, earliest first list.sort((o1, o2) -> o2.getTrade().getDate().compareTo(o1.getTrade().getDate())); - if (list.size() > 0) { + log.debug("onListChanged {}", list.size()); + if (list.size() > 0) selectTrade(list.get(0)); - selectedIndex.set(0); - } + else if (list.size() == 0) + selectTrade(null); } - boolean isBuyOffer() { + boolean isBuyOffer() throws NoTradeFoundException { if (getTrade() != null) return getTrade().getOffer().getDirection() == Offer.Direction.BUY; else - return false; + throw new NoTradeFoundException(); } void selectTrade(PendingTradesListItem item) { + log.debug("selectTrade {} {}", item != null, item != null ? item.getTrade().getId() : "null"); // clean up previous selectedItem unbindStates(); @@ -144,52 +145,67 @@ class PendingTradesDataModel implements Activatable, DataModel { } void fiatPaymentStarted() { - if (getTrade() instanceof BuyerTrade) - ((BuyerTrade) getTrade()).onFiatPaymentStarted(); + try { + if (getTrade() instanceof BuyerTrade) + ((BuyerTrade) getTrade()).onFiatPaymentStarted(); + } catch (NoTradeFoundException e) { + throw new MissingTradeException(); + } } void fiatPaymentReceived() { - if (getTrade() instanceof SellerTrade) - ((SellerTrade) getTrade()).onFiatPaymentReceived(); + try { + if (getTrade() instanceof SellerTrade) + ((SellerTrade) getTrade()).onFiatPaymentReceived(); + } catch (NoTradeFoundException e) { + throw new MissingTradeException(); + } } void withdraw(String toAddress) { - if (getTrade() != null) { - tradeManager.requestWithdraw(toAddress, - getTrade(), - () -> log.debug("requestWithdraw was successful"), - (errorMessage, throwable) -> { - log.error(errorMessage); - Popups.openExceptionPopup(throwable); - }); - - -/* - Action response = Popups.openConfirmPopup( - "Withdrawal request", "Confirm your request", - "Your withdrawal request:\n\n" + "Amount: " + amountTextField.getText() + " BTC\n" + "Sending" + - " address: " + withdrawFromTextField.getText() + "\n" + "Receiving address: " + - withdrawToTextField.getText() + "\n" + "Transaction fee: " + - formatter.formatCoinWithCode(FeePolicy.TX_FEE) + "\n" + - "You receive in total: " + - formatter.formatCoinWithCode(amount.subtract(FeePolicy.TX_FEE)) + " BTC\n\n" + - "Are you sure you withdraw that amount?"); - - if (Popups.isOK(response)) { - try { - walletService.sendFunds( - withdrawFromTextField.getText(), withdrawToTextField.getText(), - changeAddressTextField.getText(), amount, callback); - } catch (AddressFormatException e) { - Popups.openErrorPopup("Address invalid", - "The address is not correct. Please check the address format."); - - } catch (InsufficientMoneyException e) { - Popups.openInsufficientMoneyPopup(); - } catch (IllegalArgumentException e) { - Popups.openErrorPopup("Wrong inputs", "Please check the inputs."); + try { + if (getTrade() != null) { + tradeManager.requestWithdraw(toAddress, + getTrade(), + () -> { + log.debug("requestWithdraw was successful"); + Platform.runLater(() -> navigation.navigateTo(MainView.class, PortfolioView.class, ClosedTradesView.class)); + }, + (errorMessage, throwable) -> { + log.error(errorMessage); + Popups.openExceptionPopup(throwable); + }); + + + /* + Action response = Popups.openConfirmPopup( + "Withdrawal request", "Confirm your request", + "Your withdrawal request:\n\n" + "Amount: " + amountTextField.getText() + " BTC\n" + "Sending" + + " address: " + withdrawFromTextField.getText() + "\n" + "Receiving address: " + + withdrawToTextField.getText() + "\n" + "Transaction fee: " + + formatter.formatCoinWithCode(FeePolicy.TX_FEE) + "\n" + + "You receive in total: " + + formatter.formatCoinWithCode(amount.subtract(FeePolicy.TX_FEE)) + " BTC\n\n" + + "Are you sure you withdraw that amount?"); + + if (Popups.isOK(response)) { + try { + walletService.sendFunds( + withdrawFromTextField.getText(), withdrawToTextField.getText(), + changeAddressTextField.getText(), amount, callback); + } catch (AddressFormatException e) { + Popups.openErrorPopup("Address invalid", + "The address is not correct. Please check the address format."); + + } catch (InsufficientMoneyException e) { + Popups.openInsufficientMoneyPopup(); + } catch (IllegalArgumentException e) { + Popups.openErrorPopup("Wrong inputs", "Please check the inputs."); + } + }*/ } - }*/ + } catch (NoTradeFoundException e) { + throw new MissingTradeException(); } } @@ -223,17 +239,19 @@ class PendingTradesDataModel implements Activatable, DataModel { } Throwable getTradeException() { - if (getTrade() != null) + try { return getTrade().getThrowable(); - else + } catch (NoTradeFoundException e) { return null; + } } String getErrorMessage() { - if (getTrade() != null) + try { return getTrade().getErrorMessage(); - else + } catch (NoTradeFoundException e) { return null; + } } public Offer.Direction getDirection(Offer offer) { @@ -247,21 +265,26 @@ class PendingTradesDataModel implements Activatable, DataModel { } public Coin getPayoutAmount() { - return getTrade().getPayoutAmount(); + try { + return getTrade().getPayoutAmount(); + } catch (NoTradeFoundException e) { + return Coin.ZERO; + } } public Contract getContract() { - if (getTrade() != null) + try { return getTrade().getContract(); - else - return null; + } catch (NoTradeFoundException e) { + throw new MissingTradeException(); + } } - public Trade getTrade() { + public Trade getTrade() throws NoTradeFoundException { if (currentTrade.get() != null) return currentTrade.get(); else - return null; + throw new NoTradeFoundException(); } } diff --git a/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/PendingTradesView.java b/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/PendingTradesView.java index da615bbb3f..8b1d6bb132 100644 --- a/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/PendingTradesView.java +++ b/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/PendingTradesView.java @@ -20,6 +20,7 @@ package io.bitsquare.gui.main.portfolio.pending; import io.bitsquare.common.viewfx.view.ActivatableViewAndModel; import io.bitsquare.common.viewfx.view.FxmlView; import io.bitsquare.gui.components.Popups; +import io.bitsquare.trade.Trade; import io.bitsquare.util.Utilities; import org.bitcoinj.core.Coin; @@ -30,6 +31,7 @@ import java.util.Date; import javax.inject.Inject; import javafx.application.Platform; +import javafx.beans.property.ReadOnlyBooleanProperty; import javafx.beans.property.ReadOnlyObjectWrapper; import javafx.beans.value.ChangeListener; import javafx.fxml.FXML; @@ -55,7 +57,9 @@ public class PendingTradesView extends ActivatableViewAndModel selectedItemChangeListener; private TradeSubView currentSubView; - + private ChangeListener appFocusChangeListener; + private ReadOnlyBooleanProperty appFocusProperty; + private ChangeListener currentTradeChangeListener; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor, Initialisation @@ -79,17 +83,43 @@ public class PendingTradesView extends ActivatableViewAndModel { + log.debug("selectedItemChangeListener {}", newValue); + model.selectTrade(newValue); + if (newValue != null) addSubView(); + else + removeSubView(); + }; - model.selectTrade(newValue); + appFocusChangeListener = (observable, oldValue, newValue) -> { + log.debug("appFocusChangeListener {}", newValue); + if (newValue && model.getSelectedItem() != null) { + // Focus selectedItem from model + int index = table.getItems().indexOf(model.getSelectedItem()); + Platform.runLater(() -> { + table.requestFocus(); + Platform.runLater(() -> table.getFocusModel().focus(index)); + }); + } + }; + + currentTradeChangeListener = (observable, oldValue, newValue) -> { + log.debug("currentTradeChangeListener {} {}", newValue, model.getList().size()); + if (newValue != null) + addSubView(); + else + removeSubView(); }; } + @Override public void doActivate() { + appFocusProperty = root.getScene().getWindow().focusedProperty(); + appFocusProperty.addListener(appFocusChangeListener); + model.currentTrade().addListener(currentTradeChangeListener); table.setItems(model.getList()); - table.getSelectionModel().selectedItemProperty().addListener(selectedItemChangeListener); PendingTradesListItem selectedItem = model.getSelectedItem(); if (selectedItem != null) { @@ -117,6 +147,9 @@ public class PendingTradesView extends ActivatableViewAndModel viewState = new SimpleObjectProperty<>(ViewState.EMPTY); + final ObjectProperty viewState = new SimpleObjectProperty<>(ViewState.UNDEFINED); @Inject - public PendingTradesViewModel(PendingTradesDataModel dataModel, Navigation navigation, BSFormatter formatter, + public PendingTradesViewModel(PendingTradesDataModel dataModel, BSFormatter formatter, BtcAddressValidator btcAddressValidator) { super(dataModel); - this.navigation = navigation; this.formatter = formatter; this.btcAddressValidator = btcAddressValidator; @@ -100,7 +91,6 @@ public class PendingTradesViewModel extends ActivatableWithDataModel currentTrade() { + return dataModel.currentTrade; + } public void fiatPaymentStarted() { dataModel.fiatPaymentStarted(); @@ -138,7 +130,6 @@ public class PendingTradesViewModel extends ActivatableWithDataModel navigation.navigateTo(MainView.class, PortfolioView.class, ClosedTradesView.class)); } public void withdrawAddressFocusOut(String text) { @@ -201,7 +192,11 @@ public class PendingTradesViewModel extends ActivatableWithDataModel offererStateChangeListener; protected TradeStepDetailsView tradeStepDetailsView; + protected ChangeListener offererStateChangeListener; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/steps/StartFiatView.java b/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/steps/StartFiatView.java index 3b878dfeda..714489e99d 100644 --- a/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/steps/StartFiatView.java +++ b/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/steps/StartFiatView.java @@ -24,7 +24,6 @@ import io.bitsquare.gui.main.portfolio.pending.PendingTradesViewModel; import io.bitsquare.gui.util.Layout; import io.bitsquare.locale.BSResources; -import javafx.application.Platform; import javafx.beans.value.ChangeListener; import javafx.event.ActionEvent; import javafx.scene.control.*; @@ -84,7 +83,7 @@ public class StartFiatView extends TradeStepDetailsView { super.activate(); model.txId.addListener(txIdChangeListener); - Platform.runLater(() -> txIdTextField.setup(model.getWalletService(), model.txId.get())); + txIdTextField.setup(model.getWalletService(), model.txId.get()); } @Override diff --git a/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/steps/TradeStepDetailsView.java b/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/steps/TradeStepDetailsView.java index 32b550d3cb..5e0ccd6a91 100644 --- a/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/steps/TradeStepDetailsView.java +++ b/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/steps/TradeStepDetailsView.java @@ -54,6 +54,7 @@ public abstract class TradeStepDetailsView extends AnchorPane { buildGridEntries(); } + // That is called at every state change! public void activate() { log.debug("activate"); } diff --git a/core/src/main/java/io/bitsquare/gui/main/trade/createoffer/CreateOfferView.java b/core/src/main/java/io/bitsquare/gui/main/trade/createoffer/CreateOfferView.java index 10d40db7db..a92d8cf55a 100644 --- a/core/src/main/java/io/bitsquare/gui/main/trade/createoffer/CreateOfferView.java +++ b/core/src/main/java/io/bitsquare/gui/main/trade/createoffer/CreateOfferView.java @@ -35,7 +35,6 @@ import io.bitsquare.gui.main.help.Help; import io.bitsquare.gui.main.help.HelpId; import io.bitsquare.gui.main.portfolio.PortfolioView; import io.bitsquare.gui.main.portfolio.offer.OffersView; -import io.bitsquare.gui.main.portfolio.pending.PendingTradesView; import io.bitsquare.gui.main.trade.TradeView; import io.bitsquare.gui.util.ImageUtil; import io.bitsquare.locale.BSResources; @@ -295,7 +294,7 @@ public class CreateOfferView extends ActivatableViewAndModel { } public T read(File file) throws IOException, ClassNotFoundException { + log.debug("read" + file); lock.lock(); try (final FileInputStream fileInputStream = new FileInputStream(file); final ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream)) { @@ -256,6 +257,9 @@ public class FileManager { fileOutputStream = new FileOutputStream(tempFile); objectOutputStream = new ObjectOutputStream(fileOutputStream); + // TODO ConcurrentModificationException happens sometimes at that line + //log.debug("serializable " + serializable.toString()); + log.debug("storageFile " + storageFile.toString()); objectOutputStream.writeObject(serializable); // Attempt to force the bits to hit the disk. In reality the OS or hard disk itself may still decide @@ -271,6 +275,7 @@ public class FileManager { renameTempFileToFile(tempFile, storageFile); } catch (Throwable t) { t.printStackTrace(); + log.error("Error at saveToFile: " + t.getMessage()); } finally { if (tempFile != null && tempFile.exists()) { log.warn("Temp file still exists after failed save. storageFile=" + storageFile); @@ -286,7 +291,7 @@ public class FileManager { } catch (IOException e) { // We swallow that e.printStackTrace(); - log.error("Cannot close resources."); + log.error("Cannot close resources." + e.getMessage()); } lock.unlock(); } diff --git a/core/src/main/java/io/bitsquare/trade/Trade.java b/core/src/main/java/io/bitsquare/trade/Trade.java index 31814f9042..50d0f281ce 100644 --- a/core/src/main/java/io/bitsquare/trade/Trade.java +++ b/core/src/main/java/io/bitsquare/trade/Trade.java @@ -427,7 +427,6 @@ abstract public class Trade implements Model, Serializable { abstract protected void initStates(); - @Override public String toString() { return "Trade{" + @@ -446,10 +445,10 @@ abstract public class Trade implements Model, Serializable { ", lifeCycleState=" + lifeCycleState + ", mailboxMessage=" + mailboxMessage + ", depositTx=" + depositTx + - ", contract=" + contract + - ", contractAsJson='" + contractAsJson + '\'' + - ", sellerContractSignature='" + sellerContractSignature + '\'' + - ", buyerContractSignature='" + buyerContractSignature + '\'' + + /* ", contract=" + contract + + ", contractAsJson='" + contractAsJson + '\'' +*/ + /* ", sellerContractSignature='" + sellerContractSignature + '\'' + + ", buyerContractSignature='" + buyerContractSignature + '\'' +*/ ", payoutTx=" + payoutTx + ", errorMessage='" + errorMessage + '\'' + ", throwable=" + throwable + diff --git a/core/src/main/java/io/bitsquare/trade/protocol/trade/ProcessModel.java b/core/src/main/java/io/bitsquare/trade/protocol/trade/ProcessModel.java index fe03147919..dfe0496faf 100644 --- a/core/src/main/java/io/bitsquare/trade/protocol/trade/ProcessModel.java +++ b/core/src/main/java/io/bitsquare/trade/protocol/trade/ProcessModel.java @@ -167,14 +167,6 @@ public class ProcessModel implements Model, Serializable { return mailboxMessage; } - - @Override - public String toString() { - return "ProcessModel{" + - "offer=" + offer + - '}'; - } - @Nullable public Transaction getPayoutTx() { return payoutTx; @@ -280,11 +272,9 @@ public class ProcessModel implements Model, Serializable { @Override public void persist() { - } @Override public void onComplete() { - } } diff --git a/core/src/main/java/io/bitsquare/trade/protocol/trade/TradingPeer.java b/core/src/main/java/io/bitsquare/trade/protocol/trade/TradingPeer.java index 99bce08f9f..1a1984a369 100644 --- a/core/src/main/java/io/bitsquare/trade/protocol/trade/TradingPeer.java +++ b/core/src/main/java/io/bitsquare/trade/protocol/trade/TradingPeer.java @@ -29,7 +29,6 @@ import java.io.Serializable; import java.security.PublicKey; -import java.util.Arrays; import java.util.List; import org.slf4j.Logger; @@ -178,24 +177,4 @@ public class TradingPeer implements Serializable { public void setContractSignature(String contractSignature) { this.contractSignature = contractSignature; } - - @Override - public String toString() { - return "TradingPeer{" + - "accountId='" + accountId + '\'' + - ", p2pSigPubKey=" + p2pSigPubKey + - ", p2pEncryptPubKey=" + p2pEncryptPubKey + - ", tradeWalletPubKey=" + Arrays.toString(tradeWalletPubKey) + - ", fiatAccount=" + fiatAccount + - ", preparedDepositTx=" + preparedDepositTx + - ", connectedOutputsForAllInputs=" + connectedOutputsForAllInputs + - ", outputs=" + outputs + - ", payoutAmount=" + payoutAmount + - ", payoutAddressString='" + payoutAddressString + '\'' + - ", signature=" + Arrays.toString(signature) + - ", contractAsJson='" + contractAsJson + '\'' + - ", contractSignature='" + contractSignature + '\'' + - '}'; - } - } diff --git a/core/src/test/java/io/bitsquare/trade/protocol/placeoffer/TaskRunner.java b/core/src/test/java/io/bitsquare/trade/protocol/placeoffer/TaskRunner.java deleted file mode 100644 index 4d3921c02b..0000000000 --- a/core/src/test/java/io/bitsquare/trade/protocol/placeoffer/TaskRunner.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * This file is part of Bitsquare. - * - * Bitsquare is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bitsquare is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bitsquare. If not, see . - */ - -package io.bitsquare.trade.protocol.placeoffer; - -import java.util.Queue; -import java.util.concurrent.LinkedBlockingQueue; - -import org.junit.Test; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class TaskRunner { - private static final Logger log = LoggerFactory.getLogger(TaskRunner.class); - - private Queue tasks; - private SharedModel sharedModel = new SharedModel(); - private FaultHandler faultHandler; - private ResultHandler taskCompleted; - private final boolean[] failed = {false}; - - @Test - public void test() { - // Task1.run(); - //Task2.run(); - - tasks = new LinkedBlockingQueue<>(); - tasks.add(Task1.class); - tasks.add(Task2.class); - - faultHandler = (throwable) -> { - log.debug(throwable.getMessage()); - failed[0] = true; - }; - taskCompleted = () -> { - next(); - }; - next(); - /* ResultHandler handleResult = () -> { - Class task = tasks.poll(); - try { - if (!failed[0]) - ((Task) task.newInstance()).run(sharedModel, taskCompleted, faultHandler); - } catch (InstantiationException e1) { - e1.printStackTrace(); - } catch (IllegalAccessException e1) { - e1.printStackTrace(); - } - - };*/ - - - - /* tasks.stream().forEach((e) -> { - try { - ((Task) e.newInstance()).run(sharedModel, faultHandler); - } catch (InstantiationException e1) { - e1.printStackTrace(); - } catch (IllegalAccessException e1) { - e1.printStackTrace(); - } - });*/ - } - - private void next() { - Class task = tasks.poll(); - if (task != null) { - try { - if (!failed[0]) - ((Task) task.newInstance()).run(sharedModel, taskCompleted, faultHandler); - } catch (InstantiationException e1) { - e1.printStackTrace(); - } catch (IllegalAccessException e1) { - e1.printStackTrace(); - } - } - } -} - -interface ResultHandler { - void handleResult(); -} - -interface FaultHandler { - void handleFault(Throwable throwable); -} - -class SharedModel { - public int data = 42; -} - -class Task { - - protected void run(SharedModel sharedModel, ResultHandler resultHandler, FaultHandler faultHandler) { - } - -} - -class Task1 extends Task { - private static final Logger log = LoggerFactory.getLogger(Task1.class); - - @Override - public void run(SharedModel sharedModel, ResultHandler resultHandler, FaultHandler faultHandler) { - log.debug("run " + Task1.class); - log.debug("data " + sharedModel.data); - // faultHandler.handleFault(new Exception("test")); - sharedModel.data++; - resultHandler.handleResult(); - } -} - -class Task2 extends Task { - private static final Logger log = LoggerFactory.getLogger(Task2.class); - - @Override - public void run(SharedModel sharedModel, ResultHandler resultHandler, FaultHandler faultHandler) { - log.debug("run " + Task2.class); - log.debug("data " + sharedModel.data); - resultHandler.handleResult(); - } -} \ No newline at end of file