From 59860f685ae584ca7cc5bd6176a965a82b28e5cd Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 9 Sep 2020 21:19:44 -0500 Subject: [PATCH 01/56] Refactor: Rename method --- .../main/portfolio/pendingtrades/steps/TradeStepView.java | 4 ++-- .../portfolio/pendingtrades/steps/buyer/BuyerStep2View.java | 2 +- .../portfolio/pendingtrades/steps/buyer/BuyerStep4View.java | 2 +- .../portfolio/pendingtrades/steps/seller/SellerStep2View.java | 2 +- .../portfolio/pendingtrades/steps/seller/SellerStep3View.java | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java index cfc35e89681..a2b2101b156 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java @@ -141,7 +141,7 @@ protected TradeStepView(PendingTradesViewModel model) { AnchorPane.setTopAnchor(this, -10d); AnchorPane.setBottomAnchor(this, 0d); - addContent(); + initialize(); errorMessageListener = (observable, oldValue, newValue) -> { if (newValue != null) @@ -268,7 +268,7 @@ public void deactivate() { // Content /////////////////////////////////////////////////////////////////////////////////////////// - protected void addContent() { + protected void initialize() { addTradeInfoBlock(); addInfoBlock(); } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java index d6d2aeabe33..dc647a86f34 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java @@ -216,7 +216,7 @@ public void deactivate() { /////////////////////////////////////////////////////////////////////////////////////////// @Override - protected void addContent() { + protected void initialize() { gridPane.getColumnConstraints().get(1).setHgrow(Priority.ALWAYS); addTradeInfoBlock(); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep4View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep4View.java index 29076fd47ef..23897610456 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep4View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep4View.java @@ -104,7 +104,7 @@ public void deactivate() { /////////////////////////////////////////////////////////////////////////////////////////// @Override - protected void addContent() { + protected void initialize() { gridPane.getColumnConstraints().get(1).setHgrow(Priority.SOMETIMES); TitledGroupBg completedTradeLabel = new TitledGroupBg(); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java index 425634d2fb3..4edb5a98db7 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java @@ -54,7 +54,7 @@ public SellerStep2View(PendingTradesViewModel model) { } @Override - protected void addContent() { + protected void initialize() { addTradeInfoBlock(); addInfoBlock(); checkNotNull(model.dataModel.getTrade(), "No trade found"); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java index e9136153b1e..f23415baf10 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java @@ -194,7 +194,7 @@ public void deactivate() { /////////////////////////////////////////////////////////////////////////////////////////// @Override - protected void addContent() { + protected void initialize() { gridPane.getColumnConstraints().get(1).setHgrow(Priority.ALWAYS); addTradeInfoBlock(); From 3ef7599b5843eb2f184d7bffa5c348d1ac0972f8 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 9 Sep 2020 21:27:43 -0500 Subject: [PATCH 02/56] Refactor: Move initialize before activate, add separator lines --- .../pendingtrades/steps/TradeStepView.java | 21 +- .../steps/buyer/BuyerStep1View.java | 6 +- .../steps/buyer/BuyerStep2View.java | 201 +++++++++--------- .../steps/buyer/BuyerStep3View.java | 11 +- .../steps/buyer/BuyerStep4View.java | 34 +-- .../steps/seller/SellerStep1View.java | 3 +- .../steps/seller/SellerStep2View.java | 6 +- .../steps/seller/SellerStep3View.java | 182 ++++++++-------- .../steps/seller/SellerStep4View.java | 2 +- 9 files changed, 246 insertions(+), 220 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java index a2b2101b156..a71fc21816a 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java @@ -100,7 +100,7 @@ public abstract class TradeStepView extends AnchorPane { /////////////////////////////////////////////////////////////////////////////////////////// - // Constructor, Initialisation + // Constructor /////////////////////////////////////////////////////////////////////////////////////////// protected TradeStepView(PendingTradesViewModel model) { @@ -160,6 +160,16 @@ public void onMinuteTick() { }; } + + /////////////////////////////////////////////////////////////////////////////////////////// + // Life cycle + /////////////////////////////////////////////////////////////////////////////////////////// + + protected void initialize() { + addTradeInfoBlock(); + addInfoBlock(); + } + public void activate() { if (txIdTextField != null) { if (txIdSubscription != null) @@ -264,15 +274,6 @@ public void deactivate() { tradeStepInfo.setOnAction(null); } - /////////////////////////////////////////////////////////////////////////////////////////// - // Content - /////////////////////////////////////////////////////////////////////////////////////////// - - protected void initialize() { - addTradeInfoBlock(); - addInfoBlock(); - } - protected void addTradeInfoBlock() { TitledGroupBg tradeInfoTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 3, Res.get("portfolio.pending.tradeInformation")); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep1View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep1View.java index 184dcd038f9..c7f84684582 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep1View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep1View.java @@ -27,13 +27,17 @@ public class BuyerStep1View extends TradeStepView { /////////////////////////////////////////////////////////////////////////////////////////// - // Constructor, Initialisation + // Constructor /////////////////////////////////////////////////////////////////////////////////////////// public BuyerStep1View(PendingTradesViewModel model) { super(model); } + /////////////////////////////////////////////////////////////////////////////////////////// + // Life cycle + /////////////////////////////////////////////////////////////////////////////////////////// + @Override public void activate() { super.activate(); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java index dc647a86f34..dfbc9d1ea36 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java @@ -105,114 +105,18 @@ public class BuyerStep2View extends TradeStepView { private Subscription tradeStatePropertySubscription; private Timer timeoutTimer; + /////////////////////////////////////////////////////////////////////////////////////////// - // Constructor, Initialisation + // Constructor /////////////////////////////////////////////////////////////////////////////////////////// public BuyerStep2View(PendingTradesViewModel model) { super(model); } - @Override - public void activate() { - super.activate(); - - try { - DelayedPayoutTxValidation.validatePayoutTx(trade, - trade.getDelayedPayoutTx(), - model.dataModel.daoFacade, - model.dataModel.btcWalletService); - } catch (DelayedPayoutTxValidation.DonationAddressException | - DelayedPayoutTxValidation.InvalidTxException | - DelayedPayoutTxValidation.AmountMismatchException | - DelayedPayoutTxValidation.InvalidLockTimeException e) { - if (!model.dataModel.tradeManager.isAllowFaultyDelayedTxs()) { - new Popup().warning(Res.get("portfolio.pending.invalidDelayedPayoutTx", e.getMessage())).show(); - } - } catch (DelayedPayoutTxValidation.MissingDelayedPayoutTxException ignore) { - // We don't react on those errors as a failed trade might get listed initially but getting removed from the - // trade manager after initPendingTrades which happens after activate might be called. - } - - if (timeoutTimer != null) - timeoutTimer.stop(); - - //TODO we get called twice, check why - if (tradeStatePropertySubscription == null) { - tradeStatePropertySubscription = EasyBind.subscribe(trade.stateProperty(), state -> { - if (timeoutTimer != null) - timeoutTimer.stop(); - - if (trade.isDepositConfirmed() && !trade.isFiatSent()) { - showPopup(); - } else if (state.ordinal() <= Trade.State.BUYER_SEND_FAILED_FIAT_PAYMENT_INITIATED_MSG.ordinal()) { - if (!trade.hasFailed()) { - switch (state) { - case BUYER_CONFIRMED_IN_UI_FIAT_PAYMENT_INITIATED: - case BUYER_SENT_FIAT_PAYMENT_INITIATED_MSG: - busyAnimation.play(); - // confirmButton.setDisable(true); - statusLabel.setText(Res.get("shared.sendingConfirmation")); - model.setMessageStateProperty(MessageState.SENT); - timeoutTimer = UserThread.runAfter(() -> { - busyAnimation.stop(); - // confirmButton.setDisable(false); - statusLabel.setText(Res.get("shared.sendingConfirmationAgain")); - }, 10); - break; - case BUYER_SAW_ARRIVED_FIAT_PAYMENT_INITIATED_MSG: - busyAnimation.stop(); - statusLabel.setText(Res.get("shared.messageArrived")); - model.setMessageStateProperty(MessageState.ARRIVED); - break; - case BUYER_STORED_IN_MAILBOX_FIAT_PAYMENT_INITIATED_MSG: - busyAnimation.stop(); - statusLabel.setText(Res.get("shared.messageStoredInMailbox")); - model.setMessageStateProperty(MessageState.STORED_IN_MAILBOX); - break; - case BUYER_SEND_FAILED_FIAT_PAYMENT_INITIATED_MSG: - // We get a popup and the trade closed, so we dont need to show anything here - busyAnimation.stop(); - // confirmButton.setDisable(false); - statusLabel.setText(""); - model.setMessageStateProperty(MessageState.FAILED); - break; - default: - log.warn("Unexpected case: State={}, tradeId={} " + state.name(), trade.getId()); - busyAnimation.stop(); - // confirmButton.setDisable(false); - statusLabel.setText(Res.get("shared.sendingConfirmationAgain")); - break; - } - } else { - log.warn("confirmButton gets disabled because trade contains error message {}", trade.getErrorMessage()); - // confirmButton.setDisable(true); - statusLabel.setText(""); - } - } - }); - } - - confirmButton.setDisable(isDisputed()); - } - - @Override - public void deactivate() { - super.deactivate(); - - busyAnimation.stop(); - - if (timeoutTimer != null) - timeoutTimer.stop(); - - if (tradeStatePropertySubscription != null) { - tradeStatePropertySubscription.unsubscribe(); - tradeStatePropertySubscription = null; - } - } /////////////////////////////////////////////////////////////////////////////////////////// - // Content + // Life cycle /////////////////////////////////////////////////////////////////////////////////////////// @Override @@ -358,6 +262,105 @@ protected void initialize() { statusLabel = tuple3.third; } + @Override + public void activate() { + super.activate(); + + try { + DelayedPayoutTxValidation.validatePayoutTx(trade, + trade.getDelayedPayoutTx(), + model.dataModel.daoFacade, + model.dataModel.btcWalletService); + } catch (DelayedPayoutTxValidation.DonationAddressException | + DelayedPayoutTxValidation.InvalidTxException | + DelayedPayoutTxValidation.AmountMismatchException | + DelayedPayoutTxValidation.InvalidLockTimeException e) { + if (!model.dataModel.tradeManager.isAllowFaultyDelayedTxs()) { + new Popup().warning(Res.get("portfolio.pending.invalidDelayedPayoutTx", e.getMessage())).show(); + } + } catch (DelayedPayoutTxValidation.MissingDelayedPayoutTxException ignore) { + // We don't react on those errors as a failed trade might get listed initially but getting removed from the + // trade manager after initPendingTrades which happens after activate might be called. + } + + if (timeoutTimer != null) + timeoutTimer.stop(); + + //TODO we get called twice, check why + if (tradeStatePropertySubscription == null) { + tradeStatePropertySubscription = EasyBind.subscribe(trade.stateProperty(), state -> { + if (timeoutTimer != null) + timeoutTimer.stop(); + + if (trade.isDepositConfirmed() && !trade.isFiatSent()) { + showPopup(); + } else if (state.ordinal() <= Trade.State.BUYER_SEND_FAILED_FIAT_PAYMENT_INITIATED_MSG.ordinal()) { + if (!trade.hasFailed()) { + switch (state) { + case BUYER_CONFIRMED_IN_UI_FIAT_PAYMENT_INITIATED: + case BUYER_SENT_FIAT_PAYMENT_INITIATED_MSG: + busyAnimation.play(); + // confirmButton.setDisable(true); + statusLabel.setText(Res.get("shared.sendingConfirmation")); + model.setMessageStateProperty(MessageState.SENT); + timeoutTimer = UserThread.runAfter(() -> { + busyAnimation.stop(); + // confirmButton.setDisable(false); + statusLabel.setText(Res.get("shared.sendingConfirmationAgain")); + }, 10); + break; + case BUYER_SAW_ARRIVED_FIAT_PAYMENT_INITIATED_MSG: + busyAnimation.stop(); + statusLabel.setText(Res.get("shared.messageArrived")); + model.setMessageStateProperty(MessageState.ARRIVED); + break; + case BUYER_STORED_IN_MAILBOX_FIAT_PAYMENT_INITIATED_MSG: + busyAnimation.stop(); + statusLabel.setText(Res.get("shared.messageStoredInMailbox")); + model.setMessageStateProperty(MessageState.STORED_IN_MAILBOX); + break; + case BUYER_SEND_FAILED_FIAT_PAYMENT_INITIATED_MSG: + // We get a popup and the trade closed, so we dont need to show anything here + busyAnimation.stop(); + // confirmButton.setDisable(false); + statusLabel.setText(""); + model.setMessageStateProperty(MessageState.FAILED); + break; + default: + log.warn("Unexpected case: State={}, tradeId={} " + state.name(), trade.getId()); + busyAnimation.stop(); + // confirmButton.setDisable(false); + statusLabel.setText(Res.get("shared.sendingConfirmationAgain")); + break; + } + } else { + log.warn("confirmButton gets disabled because trade contains error message {}", trade.getErrorMessage()); + // confirmButton.setDisable(true); + statusLabel.setText(""); + } + } + }); + } + + confirmButton.setDisable(isDisputed()); + } + + @Override + public void deactivate() { + super.deactivate(); + + busyAnimation.stop(); + + if (timeoutTimer != null) + timeoutTimer.stop(); + + if (tradeStatePropertySubscription != null) { + tradeStatePropertySubscription.unsubscribe(); + tradeStatePropertySubscription = null; + } + } + + /////////////////////////////////////////////////////////////////////////////////////////// // Warning /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep3View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep3View.java index f04305aefe9..80e5b4d26e9 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep3View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep3View.java @@ -41,7 +41,7 @@ public class BuyerStep3View extends TradeStepView { /////////////////////////////////////////////////////////////////////////////////////////// - // Constructor, Initialisation + // Constructor /////////////////////////////////////////////////////////////////////////////////////////// public BuyerStep3View(PendingTradesViewModel model) { @@ -52,6 +52,15 @@ public BuyerStep3View(PendingTradesViewModel model) { }; } + /////////////////////////////////////////////////////////////////////////////////////////// + // Life cycle + /////////////////////////////////////////////////////////////////////////////////////////// + + @Override + protected void initialize() { + super.initialize(); + } + @Override public void activate() { super.activate(); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep4View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep4View.java index 23897610456..5d8e35a6232 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep4View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep4View.java @@ -79,28 +79,15 @@ public class BuyerStep4View extends TradeStepView { private TitledGroupBg withdrawTitledGroupBg; /////////////////////////////////////////////////////////////////////////////////////////// - // Constructor, Initialisation + // Constructor /////////////////////////////////////////////////////////////////////////////////////////// public BuyerStep4View(PendingTradesViewModel model) { super(model); } - @Override - public void activate() { - super.activate(); - // Don't display any trade step info when trade is complete - hideTradeStepInfo(); - } - - @Override - public void deactivate() { - super.deactivate(); - } - - /////////////////////////////////////////////////////////////////////////////////////////// - // Content + // Life cycle /////////////////////////////////////////////////////////////////////////////////////////// @Override @@ -167,6 +154,23 @@ protected void initialize() { } } + @Override + public void activate() { + super.activate(); + // Don't display any trade step info when trade is complete + hideTradeStepInfo(); + } + + @Override + public void deactivate() { + super.deactivate(); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Private + /////////////////////////////////////////////////////////////////////////////////////////// + private void onWithdrawal() { withdrawAddressTextField.setManaged(true); withdrawAddressTextField.setVisible(true); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep1View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep1View.java index a2034ec31d5..94432888127 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep1View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep1View.java @@ -25,13 +25,14 @@ public class SellerStep1View extends TradeStepView { /////////////////////////////////////////////////////////////////////////////////////////// - // Constructor, Initialisation + // Constructor /////////////////////////////////////////////////////////////////////////////////////////// public SellerStep1View(PendingTradesViewModel model) { super(model); } + /////////////////////////////////////////////////////////////////////////////////////////// // Info /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java index 4edb5a98db7..e36a8f5b41d 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java @@ -46,13 +46,17 @@ public class SellerStep2View extends TradeStepView { private Timer timer; /////////////////////////////////////////////////////////////////////////////////////////// - // Constructor, Initialisation + // Constructor /////////////////////////////////////////////////////////////////////////////////////////// public SellerStep2View(PendingTradesViewModel model) { super(model); } + /////////////////////////////////////////////////////////////////////////////////////////// + // Life cycle + /////////////////////////////////////////////////////////////////////////////////////////// + @Override protected void initialize() { addTradeInfoBlock(); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java index f23415baf10..7c71b408ef8 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java @@ -93,104 +93,15 @@ public class SellerStep3View extends TradeStepView { /////////////////////////////////////////////////////////////////////////////////////////// - // Constructor, Initialisation + // Constructor /////////////////////////////////////////////////////////////////////////////////////////// public SellerStep3View(PendingTradesViewModel model) { super(model); } - @Override - public void activate() { - super.activate(); - - if (timeoutTimer != null) - timeoutTimer.stop(); - - tradeStatePropertySubscription = EasyBind.subscribe(trade.stateProperty(), state -> { - if (timeoutTimer != null) - timeoutTimer.stop(); - - if (trade.isFiatSent() && !trade.isFiatReceived()) { - showPopup(); - } else if (trade.isFiatReceived()) { - if (!trade.hasFailed()) { - switch (state) { - case SELLER_CONFIRMED_IN_UI_FIAT_PAYMENT_RECEIPT: - case SELLER_PUBLISHED_PAYOUT_TX: - case SELLER_SENT_PAYOUT_TX_PUBLISHED_MSG: - busyAnimation.play(); - // confirmButton.setDisable(true); - statusLabel.setText(Res.get("shared.sendingConfirmation")); - - timeoutTimer = UserThread.runAfter(() -> { - busyAnimation.stop(); - // confirmButton.setDisable(false); - statusLabel.setText(Res.get("shared.sendingConfirmationAgain")); - }, 10); - break; - case SELLER_SAW_ARRIVED_PAYOUT_TX_PUBLISHED_MSG: - busyAnimation.stop(); - statusLabel.setText(Res.get("shared.messageArrived")); - break; - case SELLER_STORED_IN_MAILBOX_PAYOUT_TX_PUBLISHED_MSG: - busyAnimation.stop(); - statusLabel.setText(Res.get("shared.messageStoredInMailbox")); - break; - case SELLER_SEND_FAILED_PAYOUT_TX_PUBLISHED_MSG: - // We get a popup and the trade closed, so we dont need to show anything here - busyAnimation.stop(); - // confirmButton.setDisable(false); - statusLabel.setText(""); - break; - default: - log.warn("Unexpected case: State={}, tradeId={} " + state.name(), trade.getId()); - busyAnimation.stop(); - // confirmButton.setDisable(false); - statusLabel.setText(Res.get("shared.sendingConfirmationAgain")); - break; - } - } else { - log.warn("confirmButton gets disabled because trade contains error message {}", trade.getErrorMessage()); - // confirmButton.setDisable(true); - statusLabel.setText(""); - } - } - }); - - if (isXmrTrade()) { - proofResultListener = (observable, oldValue, newValue) -> { - applyAssetTxProofResult(trade.getAssetTxProofResult()); - }; - trade.getAssetTxProofResultUpdateProperty().addListener(proofResultListener); - - applyAssetTxProofResult(trade.getAssetTxProofResult()); - } - } - - @Override - public void deactivate() { - super.deactivate(); - - if (tradeStatePropertySubscription != null) { - tradeStatePropertySubscription.unsubscribe(); - tradeStatePropertySubscription = null; - } - - busyAnimation.stop(); - - if (timeoutTimer != null) { - timeoutTimer.stop(); - } - - if (isXmrTrade()) { - trade.getAssetTxProofResultUpdateProperty().removeListener(proofResultListener); - } - } - - /////////////////////////////////////////////////////////////////////////////////////////// - // Content + // Life cycle /////////////////////////////////////////////////////////////////////////////////////////// @Override @@ -309,6 +220,95 @@ protected void initialize() { statusLabel = tuple.third; } + @Override + public void activate() { + super.activate(); + + if (timeoutTimer != null) + timeoutTimer.stop(); + + tradeStatePropertySubscription = EasyBind.subscribe(trade.stateProperty(), state -> { + if (timeoutTimer != null) + timeoutTimer.stop(); + + if (trade.isFiatSent() && !trade.isFiatReceived()) { + showPopup(); + } else if (trade.isFiatReceived()) { + if (!trade.hasFailed()) { + switch (state) { + case SELLER_CONFIRMED_IN_UI_FIAT_PAYMENT_RECEIPT: + case SELLER_PUBLISHED_PAYOUT_TX: + case SELLER_SENT_PAYOUT_TX_PUBLISHED_MSG: + busyAnimation.play(); + // confirmButton.setDisable(true); + statusLabel.setText(Res.get("shared.sendingConfirmation")); + + timeoutTimer = UserThread.runAfter(() -> { + busyAnimation.stop(); + // confirmButton.setDisable(false); + statusLabel.setText(Res.get("shared.sendingConfirmationAgain")); + }, 10); + break; + case SELLER_SAW_ARRIVED_PAYOUT_TX_PUBLISHED_MSG: + busyAnimation.stop(); + statusLabel.setText(Res.get("shared.messageArrived")); + break; + case SELLER_STORED_IN_MAILBOX_PAYOUT_TX_PUBLISHED_MSG: + busyAnimation.stop(); + statusLabel.setText(Res.get("shared.messageStoredInMailbox")); + break; + case SELLER_SEND_FAILED_PAYOUT_TX_PUBLISHED_MSG: + // We get a popup and the trade closed, so we dont need to show anything here + busyAnimation.stop(); + // confirmButton.setDisable(false); + statusLabel.setText(""); + break; + default: + log.warn("Unexpected case: State={}, tradeId={} " + state.name(), trade.getId()); + busyAnimation.stop(); + // confirmButton.setDisable(false); + statusLabel.setText(Res.get("shared.sendingConfirmationAgain")); + break; + } + } else { + log.warn("confirmButton gets disabled because trade contains error message {}", trade.getErrorMessage()); + // confirmButton.setDisable(true); + statusLabel.setText(""); + } + } + }); + + if (isXmrTrade()) { + proofResultListener = (observable, oldValue, newValue) -> { + applyAssetTxProofResult(trade.getAssetTxProofResult()); + }; + trade.getAssetTxProofResultUpdateProperty().addListener(proofResultListener); + + applyAssetTxProofResult(trade.getAssetTxProofResult()); + } + } + + @Override + public void deactivate() { + super.deactivate(); + + if (tradeStatePropertySubscription != null) { + tradeStatePropertySubscription.unsubscribe(); + tradeStatePropertySubscription = null; + } + + busyAnimation.stop(); + + if (timeoutTimer != null) { + timeoutTimer.stop(); + } + + if (isXmrTrade()) { + trade.getAssetTxProofResultUpdateProperty().removeListener(proofResultListener); + } + } + + @Override protected void updateConfirmButtonDisableState(boolean isDisabled) { confirmButton.setDisable(isDisabled); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep4View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep4View.java index d9d2f06df9b..97446aae5fb 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep4View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep4View.java @@ -25,7 +25,7 @@ public class SellerStep4View extends BuyerStep4View { /////////////////////////////////////////////////////////////////////////////////////////// - // Constructor, Initialisation + // Constructor /////////////////////////////////////////////////////////////////////////////////////////// public SellerStep4View(PendingTradesViewModel model) { From 2bfdcfbcf4fab37134bf0ea3903772d7fb6056c0 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 9 Sep 2020 21:30:02 -0500 Subject: [PATCH 03/56] Refactor: Move methods --- .../pendingtrades/steps/TradeStepView.java | 57 ++++++++++--------- .../steps/seller/SellerStep2View.java | 31 +++++----- .../steps/seller/SellerStep3View.java | 4 ++ 3 files changed, 53 insertions(+), 39 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java index a71fc21816a..528c6575674 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java @@ -220,6 +220,37 @@ public void onUpdatedDataReceived() { infoLabel.setText(getInfoText()); } + public void deactivate() { + if (txIdSubscription != null) + txIdSubscription.unsubscribe(); + + if (txIdTextField != null) + txIdTextField.cleanup(); + + if (errorMessageListener != null) + trade.errorMessageProperty().removeListener(errorMessageListener); + + if (disputeStateSubscription != null) + disputeStateSubscription.unsubscribe(); + + if (mediationResultStateSubscription != null) + mediationResultStateSubscription.unsubscribe(); + + if (tradePeriodStateSubscription != null) + tradePeriodStateSubscription.unsubscribe(); + + if (clockListener != null) + model.clockWatcher.removeListener(clockListener); + + if (tradeStepInfo != null) + tradeStepInfo.setOnAction(null); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Private + /////////////////////////////////////////////////////////////////////////////////////////// + private void registerSubscriptions() { disputeStateSubscription = EasyBind.subscribe(trade.disputeStateProperty(), newValue -> { if (newValue != null) { @@ -248,32 +279,6 @@ private void openChat() { } } - public void deactivate() { - if (txIdSubscription != null) - txIdSubscription.unsubscribe(); - - if (txIdTextField != null) - txIdTextField.cleanup(); - - if (errorMessageListener != null) - trade.errorMessageProperty().removeListener(errorMessageListener); - - if (disputeStateSubscription != null) - disputeStateSubscription.unsubscribe(); - - if (mediationResultStateSubscription != null) - mediationResultStateSubscription.unsubscribe(); - - if (tradePeriodStateSubscription != null) - tradePeriodStateSubscription.unsubscribe(); - - if (clockListener != null) - model.clockWatcher.removeListener(clockListener); - - if (tradeStepInfo != null) - tradeStepInfo.setOnAction(null); - } - protected void addTradeInfoBlock() { TitledGroupBg tradeInfoTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 3, Res.get("portfolio.pending.tradeInformation")); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java index e36a8f5b41d..644101a659e 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java @@ -53,6 +53,7 @@ public SellerStep2View(PendingTradesViewModel model) { super(model); } + /////////////////////////////////////////////////////////////////////////////////////////// // Life cycle /////////////////////////////////////////////////////////////////////////////////////////// @@ -73,6 +74,23 @@ protected void initialize() { addRefreshBlock(); } + @Override + public void activate() { + super.activate(); + activateRefreshButton(); + } + + @Override + public void deactivate() { + super.deactivate(); + deActivateRefreshButtonTimer(); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Private + /////////////////////////////////////////////////////////////////////////////////////////// + private void addRefreshBlock() { refreshButtonPane = new GridPane(); addTitledGroupBg(refreshButtonPane, 0, 1, @@ -88,19 +106,6 @@ private void addRefreshBlock() { gridPane.getChildren().add(refreshButtonPane); } - - @Override - public void activate() { - super.activate(); - activateRefreshButton(); - } - - @Override - public void deactivate() { - super.deactivate(); - deActivateRefreshButtonTimer(); - } - private void activateRefreshButton() { checkNotNull(model.dataModel.getTrade(), "No trade found"); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java index 7c71b408ef8..5ae395b91d0 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java @@ -309,6 +309,10 @@ public void deactivate() { } + /////////////////////////////////////////////////////////////////////////////////////////// + // ConfirmButton + /////////////////////////////////////////////////////////////////////////////////////////// + @Override protected void updateConfirmButtonDisableState(boolean isDisabled) { confirmButton.setDisable(isDisabled); From 115983665bdfb737c0d6936f8174f23525bcc377 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 9 Sep 2020 21:32:34 -0500 Subject: [PATCH 04/56] Refactor: Make initialize public --- .../main/portfolio/pendingtrades/steps/TradeStepView.java | 2 +- .../portfolio/pendingtrades/steps/buyer/BuyerStep2View.java | 2 +- .../portfolio/pendingtrades/steps/buyer/BuyerStep3View.java | 2 +- .../portfolio/pendingtrades/steps/buyer/BuyerStep4View.java | 2 +- .../portfolio/pendingtrades/steps/seller/SellerStep2View.java | 2 +- .../portfolio/pendingtrades/steps/seller/SellerStep3View.java | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java index 528c6575674..4a6c4fe16d9 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java @@ -165,7 +165,7 @@ public void onMinuteTick() { // Life cycle /////////////////////////////////////////////////////////////////////////////////////////// - protected void initialize() { + public void initialize() { addTradeInfoBlock(); addInfoBlock(); } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java index dfbc9d1ea36..8d49839c817 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java @@ -120,7 +120,7 @@ public BuyerStep2View(PendingTradesViewModel model) { /////////////////////////////////////////////////////////////////////////////////////////// @Override - protected void initialize() { + public void initialize() { gridPane.getColumnConstraints().get(1).setHgrow(Priority.ALWAYS); addTradeInfoBlock(); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep3View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep3View.java index 80e5b4d26e9..c97f3d3d9c4 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep3View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep3View.java @@ -57,7 +57,7 @@ public BuyerStep3View(PendingTradesViewModel model) { /////////////////////////////////////////////////////////////////////////////////////////// @Override - protected void initialize() { + public void initialize() { super.initialize(); } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep4View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep4View.java index 5d8e35a6232..bc7eb740ac6 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep4View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep4View.java @@ -91,7 +91,7 @@ public BuyerStep4View(PendingTradesViewModel model) { /////////////////////////////////////////////////////////////////////////////////////////// @Override - protected void initialize() { + public void initialize() { gridPane.getColumnConstraints().get(1).setHgrow(Priority.SOMETIMES); TitledGroupBg completedTradeLabel = new TitledGroupBg(); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java index 644101a659e..e181990ebfa 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java @@ -59,7 +59,7 @@ public SellerStep2View(PendingTradesViewModel model) { /////////////////////////////////////////////////////////////////////////////////////////// @Override - protected void initialize() { + public void initialize() { addTradeInfoBlock(); addInfoBlock(); checkNotNull(model.dataModel.getTrade(), "No trade found"); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java index 5ae395b91d0..f296b2e98ac 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java @@ -105,7 +105,7 @@ public SellerStep3View(PendingTradesViewModel model) { /////////////////////////////////////////////////////////////////////////////////////////// @Override - protected void initialize() { + public void initialize() { gridPane.getColumnConstraints().get(1).setHgrow(Priority.ALWAYS); addTradeInfoBlock(); From 59e4e986b5c8a1234b3c3e43a78f33cd0db43b18 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 9 Sep 2020 21:34:56 -0500 Subject: [PATCH 05/56] Functional change: Do not call initialize in constructor To call initialize from constructor would adds issues with later changes. It is more clean to have a clear call order of: Constructor -> initialize -> activate --- .../bisq/desktop/main/portfolio/pendingtrades/TradeSubView.java | 1 + .../main/portfolio/pendingtrades/steps/TradeStepView.java | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/TradeSubView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/TradeSubView.java index 8f0f9d76aee..88703738438 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/TradeSubView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/TradeSubView.java @@ -144,6 +144,7 @@ private void createAndAddTradeStepView(Class viewClass) tradeStepView.deactivate(); try { tradeStepView = viewClass.getDeclaredConstructor(PendingTradesViewModel.class).newInstance(model); + tradeStepView.initialize(); contentPane.getChildren().setAll(tradeStepView); tradeStepView.setTradeStepInfo(tradeStepInfo); ChatCallback chatCallback = trade -> { diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java index 4a6c4fe16d9..40fd2b3eb1e 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java @@ -141,8 +141,6 @@ protected TradeStepView(PendingTradesViewModel model) { AnchorPane.setTopAnchor(this, -10d); AnchorPane.setBottomAnchor(this, 0d); - initialize(); - errorMessageListener = (observable, oldValue, newValue) -> { if (newValue != null) new Popup().error(newValue).show(); From 17ba6e9c6859bd74771f5d90d34ac0f21c1977f1 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 9 Sep 2020 21:40:24 -0500 Subject: [PATCH 06/56] Refactor: Do check for trade.getPayoutTx() == null at beginning and return. --- .../tasks/SendPayoutTxPublishedMessage.java | 84 ++++++++++--------- 1 file changed, 43 insertions(+), 41 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/SendPayoutTxPublishedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/SendPayoutTxPublishedMessage.java index c48aa3e5ffb..9e18a8e96f0 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/SendPayoutTxPublishedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/SendPayoutTxPublishedMessage.java @@ -48,49 +48,51 @@ public SendPayoutTxPublishedMessage(TaskRunner taskHandler, Trade trade) { protected void run() { try { runInterceptHook(); - if (trade.getPayoutTx() != null) { - String id = processModel.getOfferId(); - TradeMessage message = getMessage(id); - setStateSent(); - NodeAddress peersNodeAddress = trade.getTradingPeerNodeAddress(); - log.info("Send {} to peer {}. tradeId={}, uid={}", - message.getClass().getSimpleName(), peersNodeAddress, message.getTradeId(), message.getUid()); - - processModel.getP2PService().sendEncryptedMailboxMessage( - peersNodeAddress, - processModel.getTradingPeer().getPubKeyRing(), - message, - new SendMailboxMessageListener() { - @Override - public void onArrived() { - log.info("{} arrived at peer {}. tradeId={}, uid={}", - message.getClass().getSimpleName(), peersNodeAddress, message.getTradeId(), message.getUid()); - setStateArrived(); - complete(); - } - - @Override - public void onStoredInMailbox() { - log.info("{} stored in mailbox for peer {}. tradeId={}, uid={}", - message.getClass().getSimpleName(), peersNodeAddress, message.getTradeId(), message.getUid()); - setStateStoredInMailbox(); - complete(); - } - - @Override - public void onFault(String errorMessage) { - log.error("{} failed: Peer {}. tradeId={}, uid={}, errorMessage={}", - message.getClass().getSimpleName(), peersNodeAddress, message.getTradeId(), message.getUid(), errorMessage); - setStateFault(); - appendToErrorMessage("Sending message failed: message=" + message + "\nerrorMessage=" + errorMessage); - failed(errorMessage); - } - } - ); - } else { - log.error("trade.getPayoutTx() = " + trade.getPayoutTx()); + + if (trade.getPayoutTx() == null) { + log.error("PayoutTx is null"); failed("PayoutTx is null"); + return; } + + String id = processModel.getOfferId(); + TradeMessage message = getMessage(id); + setStateSent(); + NodeAddress peersNodeAddress = trade.getTradingPeerNodeAddress(); + log.info("Send {} to peer {}. tradeId={}, uid={}", + message.getClass().getSimpleName(), peersNodeAddress, message.getTradeId(), message.getUid()); + + processModel.getP2PService().sendEncryptedMailboxMessage( + peersNodeAddress, + processModel.getTradingPeer().getPubKeyRing(), + message, + new SendMailboxMessageListener() { + @Override + public void onArrived() { + log.info("{} arrived at peer {}. tradeId={}, uid={}", + message.getClass().getSimpleName(), peersNodeAddress, message.getTradeId(), message.getUid()); + setStateArrived(); + complete(); + } + + @Override + public void onStoredInMailbox() { + log.info("{} stored in mailbox for peer {}. tradeId={}, uid={}", + message.getClass().getSimpleName(), peersNodeAddress, message.getTradeId(), message.getUid()); + setStateStoredInMailbox(); + complete(); + } + + @Override + public void onFault(String errorMessage) { + log.error("{} failed: Peer {}. tradeId={}, uid={}, errorMessage={}", + message.getClass().getSimpleName(), peersNodeAddress, message.getTradeId(), message.getUid(), errorMessage); + setStateFault(); + appendToErrorMessage("Sending message failed: message=" + message + "\nerrorMessage=" + errorMessage); + failed(errorMessage); + } + } + ); } catch (Throwable t) { failed(t); } From 1e2ea6d835764266f2bb311b885e73277e58233b Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 9 Sep 2020 21:41:42 -0500 Subject: [PATCH 07/56] Refactor: Move check for trade.getPayoutTx() == null to sub classes -> We will later use that class for more generic use cases. --- .../trade/protocol/tasks/SendPayoutTxPublishedMessage.java | 6 ------ .../mediation/SendMediatedPayoutTxPublishedMessage.java | 6 ++++++ .../tasks/seller/SellerSendPayoutTxPublishedMessage.java | 6 ++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/SendPayoutTxPublishedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/SendPayoutTxPublishedMessage.java index 9e18a8e96f0..eb30c88c9e3 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/SendPayoutTxPublishedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/SendPayoutTxPublishedMessage.java @@ -49,12 +49,6 @@ protected void run() { try { runInterceptHook(); - if (trade.getPayoutTx() == null) { - log.error("PayoutTx is null"); - failed("PayoutTx is null"); - return; - } - String id = processModel.getOfferId(); TradeMessage message = getMessage(id); setStateSent(); diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutTxPublishedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutTxPublishedMessage.java index b97e782d092..6cf2cb64c8b 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutTxPublishedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutTxPublishedMessage.java @@ -77,6 +77,12 @@ protected void run() { try { runInterceptHook(); + if (trade.getPayoutTx() == null) { + log.error("PayoutTx is null"); + failed("PayoutTx is null"); + return; + } + super.run(); } catch (Throwable t) { failed(t); diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerSendPayoutTxPublishedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerSendPayoutTxPublishedMessage.java index c8af73c7328..b5a0279cede 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerSendPayoutTxPublishedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerSendPayoutTxPublishedMessage.java @@ -75,6 +75,12 @@ protected void run() { try { runInterceptHook(); + if (trade.getPayoutTx() == null) { + log.error("PayoutTx is null"); + failed("PayoutTx is null"); + return; + } + super.run(); } catch (Throwable t) { failed(t); From 88cd5b2142e04593e1750d81b706b56c1a002d8d Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 9 Sep 2020 21:42:21 -0500 Subject: [PATCH 08/56] Refactor: Rename class for more generic use cases. --- ...outTxPublishedMessage.java => SendMailboxMessageTask.java} | 4 ++-- .../tasks/mediation/SendMediatedPayoutTxPublishedMessage.java | 4 ++-- .../tasks/seller/SellerSendPayoutTxPublishedMessage.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) rename core/src/main/java/bisq/core/trade/protocol/tasks/{SendPayoutTxPublishedMessage.java => SendMailboxMessageTask.java} (95%) diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/SendPayoutTxPublishedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/SendMailboxMessageTask.java similarity index 95% rename from core/src/main/java/bisq/core/trade/protocol/tasks/SendPayoutTxPublishedMessage.java rename to core/src/main/java/bisq/core/trade/protocol/tasks/SendMailboxMessageTask.java index eb30c88c9e3..032e9d4e309 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/SendPayoutTxPublishedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/SendMailboxMessageTask.java @@ -28,9 +28,9 @@ import lombok.extern.slf4j.Slf4j; @Slf4j -public abstract class SendPayoutTxPublishedMessage extends TradeTask { +public abstract class SendMailboxMessageTask extends TradeTask { @SuppressWarnings({"unused"}) - public SendPayoutTxPublishedMessage(TaskRunner taskHandler, Trade trade) { + public SendMailboxMessageTask(TaskRunner taskHandler, Trade trade) { super(taskHandler, trade); } diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutTxPublishedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutTxPublishedMessage.java index 6cf2cb64c8b..5e9bd221ee5 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutTxPublishedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutTxPublishedMessage.java @@ -21,7 +21,7 @@ import bisq.core.trade.Trade; import bisq.core.trade.messages.MediatedPayoutTxPublishedMessage; import bisq.core.trade.messages.TradeMessage; -import bisq.core.trade.protocol.tasks.SendPayoutTxPublishedMessage; +import bisq.core.trade.protocol.tasks.SendMailboxMessageTask; import bisq.common.taskrunner.TaskRunner; @@ -35,7 +35,7 @@ @Slf4j -public class SendMediatedPayoutTxPublishedMessage extends SendPayoutTxPublishedMessage { +public class SendMediatedPayoutTxPublishedMessage extends SendMailboxMessageTask { @SuppressWarnings({"unused"}) public SendMediatedPayoutTxPublishedMessage(TaskRunner taskHandler, Trade trade) { super(taskHandler, trade); diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerSendPayoutTxPublishedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerSendPayoutTxPublishedMessage.java index b5a0279cede..002b4308ec2 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerSendPayoutTxPublishedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerSendPayoutTxPublishedMessage.java @@ -20,7 +20,7 @@ import bisq.core.trade.Trade; import bisq.core.trade.messages.PayoutTxPublishedMessage; import bisq.core.trade.messages.TradeMessage; -import bisq.core.trade.protocol.tasks.SendPayoutTxPublishedMessage; +import bisq.core.trade.protocol.tasks.SendMailboxMessageTask; import bisq.common.taskrunner.TaskRunner; @@ -33,7 +33,7 @@ import static com.google.common.base.Preconditions.checkNotNull; @Slf4j -public class SellerSendPayoutTxPublishedMessage extends SendPayoutTxPublishedMessage { +public class SellerSendPayoutTxPublishedMessage extends SendMailboxMessageTask { @SuppressWarnings({"unused"}) public SellerSendPayoutTxPublishedMessage(TaskRunner taskHandler, Trade trade) { super(taskHandler, trade); From 5f1d5f37cc697659d3d35c738f7a87df2b0e4c6e Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 9 Sep 2020 21:43:54 -0500 Subject: [PATCH 09/56] Functional change: Avoid possibility to add duplicated tradable to list --- core/src/main/java/bisq/core/trade/TradableList.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/TradableList.java b/core/src/main/java/bisq/core/trade/TradableList.java index eae2c3a60b1..5f4303b6ecd 100644 --- a/core/src/main/java/bisq/core/trade/TradableList.java +++ b/core/src/main/java/bisq/core/trade/TradableList.java @@ -111,10 +111,13 @@ public static TradableList fromProto(protobuf.TradableList proto, /////////////////////////////////////////////////////////////////////////////////////////// public boolean add(T tradable) { - boolean changed = list.add(tradable); - if (changed) + if (!list.contains(tradable)) { + list.add(tradable); storage.queueUpForSave(); - return changed; + return true; + } else { + return false; + } } public boolean remove(T tradable) { From 1f2241ffaa0cd3663544991f96b33a0b3ccd4145 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 9 Sep 2020 22:07:08 -0500 Subject: [PATCH 10/56] Add cancel trade domain --- .../core/btc/wallet/TradeWalletService.java | 62 +++++- .../network/CoreNetworkProtoResolver.java | 10 + .../bisq/core/trade/CanceledTradeState.java | 50 +++++ core/src/main/java/bisq/core/trade/Trade.java | 15 ++ .../core/trade/TradeCancellationManager.java | 117 +++++++++++ .../java/bisq/core/trade/TradeManager.java | 10 + .../CancelTradeRequestAcceptedMessage.java | 91 +++++++++ .../CancelTradeRequestRejectedMessage.java | 80 ++++++++ .../messages/RequestCancelTradeMessage.java | 99 +++++++++ .../core/trade/protocol/ProcessModel.java | 17 +- .../core/trade/protocol/TradeProtocol.java | 141 +++++++++++++ .../bisq/core/trade/protocol/TradingPeer.java | 5 + .../BroadcastCanceledTradePayoutTx.java | 50 +++++ .../cancel/FinalizeCanceledTradePayoutTx.java | 119 +++++++++++ ...cessCancelTradeRequestAcceptedMessage.java | 81 ++++++++ ...cessCancelTradeRequestRejectedMessage.java | 56 +++++ .../ProcessRequestCancelTradeMessage.java | 60 ++++++ ...SendCancelTradeRequestAcceptedMessage.java | 91 +++++++++ ...SendCancelTradeRequestRejectedMessage.java | 79 +++++++ .../cancel/SendRequestCancelTradeMessage.java | 92 +++++++++ .../SetupCanceledTradePayoutTxListener.java | 54 +++++ .../cancel/SignCanceledTradePayoutTx.java | 105 ++++++++++ .../resources/i18n/displayStrings.properties | 25 +++ .../pendingtrades/PendingTradesDataModel.java | 6 +- .../pendingtrades/PendingTradesViewModel.java | 1 + .../HandleCancelTradeRequestPresentation.java | 159 +++++++++++++++ .../steps/RequestCancelTradePresentation.java | 192 ++++++++++++++++++ .../pendingtrades/steps/TradeStepView.java | 13 +- .../steps/buyer/BuyerStep2View.java | 23 ++- .../steps/buyer/BuyerStep3View.java | 12 ++ .../steps/buyer/BuyerStep4View.java | 1 - .../steps/seller/SellerStep2View.java | 14 ++ .../steps/seller/SellerStep3View.java | 18 ++ proto/src/main/proto/pb.proto | 28 +++ 34 files changed, 1968 insertions(+), 8 deletions(-) create mode 100644 core/src/main/java/bisq/core/trade/CanceledTradeState.java create mode 100644 core/src/main/java/bisq/core/trade/TradeCancellationManager.java create mode 100644 core/src/main/java/bisq/core/trade/messages/CancelTradeRequestAcceptedMessage.java create mode 100644 core/src/main/java/bisq/core/trade/messages/CancelTradeRequestRejectedMessage.java create mode 100644 core/src/main/java/bisq/core/trade/messages/RequestCancelTradeMessage.java create mode 100644 core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java create mode 100644 core/src/main/java/bisq/core/trade/protocol/tasks/cancel/FinalizeCanceledTradePayoutTx.java create mode 100644 core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java create mode 100644 core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java create mode 100644 core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java create mode 100644 core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java create mode 100644 core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java create mode 100644 core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java create mode 100644 core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java create mode 100644 core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SignCanceledTradePayoutTx.java create mode 100644 desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/HandleCancelTradeRequestPresentation.java create mode 100644 desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/RequestCancelTradePresentation.java diff --git a/core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java b/core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java index 07671fe6871..0fe16426d1a 100644 --- a/core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java +++ b/core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java @@ -58,7 +58,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.Objects; import java.util.stream.Collectors; import org.slf4j.Logger; @@ -833,6 +832,67 @@ public Transaction sellerSignsAndFinalizesPayoutTx(Transaction depositTx, return payoutTx; } + /////////////////////////////////////////////////////////////////////////////////////////// + // Canceled trade payoutTx + /////////////////////////////////////////////////////////////////////////////////////////// + + public byte[] signCanceledTradePayoutTx(Transaction depositTx, + Coin buyerPayoutAmount, + Coin sellerPayoutAmount, + String buyerPayoutAddressString, + String sellerPayoutAddressString, + DeterministicKey myMultiSigKeyPair, + byte[] buyerPubKey, + byte[] sellerPubKey) + throws AddressFormatException, TransactionVerificationException { + Transaction preparedPayoutTx = createPayoutTx(depositTx, buyerPayoutAmount, sellerPayoutAmount, buyerPayoutAddressString, sellerPayoutAddressString); + // MS redeemScript + Script redeemScript = get2of2MultiSigRedeemScript(buyerPubKey, sellerPubKey); + // MS output from prev. tx is index 0 + Sha256Hash sigHash = preparedPayoutTx.hashForSignature(0, redeemScript, Transaction.SigHash.ALL, false); + checkNotNull(myMultiSigKeyPair, "myMultiSigKeyPair must not be null"); + if (myMultiSigKeyPair.isEncrypted()) { + checkNotNull(aesKey); + } + ECKey.ECDSASignature mySignature = myMultiSigKeyPair.sign(sigHash, aesKey).toCanonicalised(); + WalletService.printTx("prepared canceled trade payoutTx for sig creation", preparedPayoutTx); + WalletService.verifyTransaction(preparedPayoutTx); + return mySignature.encodeToDER(); + } + + public Transaction finalizeCanceledTradePayoutTx(Transaction depositTx, + byte[] buyerSignature, + byte[] sellerSignature, + Coin buyerPayoutAmount, + Coin sellerPayoutAmount, + String buyerPayoutAddressString, + String sellerPayoutAddressString, + DeterministicKey multiSigKeyPair, + byte[] buyerPubKey, + byte[] sellerPubKey) + throws AddressFormatException, TransactionVerificationException, WalletException { + Transaction payoutTx = createPayoutTx(depositTx, buyerPayoutAmount, sellerPayoutAmount, buyerPayoutAddressString, sellerPayoutAddressString); + // MS redeemScript + Script redeemScript = get2of2MultiSigRedeemScript(buyerPubKey, sellerPubKey); + // MS output from prev. tx is index 0 + checkNotNull(multiSigKeyPair, "multiSigKeyPair must not be null"); + TransactionSignature buyerTxSig = new TransactionSignature(ECKey.ECDSASignature.decodeFromDER(buyerSignature), + Transaction.SigHash.ALL, false); + TransactionSignature sellerTxSig = new TransactionSignature(ECKey.ECDSASignature.decodeFromDER(sellerSignature), + Transaction.SigHash.ALL, false); + // Take care of order of signatures. Need to be reversed here. See comment below at getMultiSigRedeemScript (seller, buyer) + Script inputScript = ScriptBuilder.createP2SHMultiSigInputScript(ImmutableList.of(sellerTxSig, buyerTxSig), redeemScript); + TransactionInput input = payoutTx.getInput(0); + input.setScriptSig(inputScript); + WalletService.printTx("canceled trade payoutTx", payoutTx); + WalletService.verifyTransaction(payoutTx); + WalletService.checkWalletConsistency(wallet); + WalletService.checkScriptSig(payoutTx, input, 0); + checkNotNull(input.getConnectedOutput(), "input.getConnectedOutput() must not be null"); + input.verify(input.getConnectedOutput()); + return payoutTx; + } + /////////////////////////////////////////////////////////////////////////////////////////// // Mediated payoutTx diff --git a/core/src/main/java/bisq/core/proto/network/CoreNetworkProtoResolver.java b/core/src/main/java/bisq/core/proto/network/CoreNetworkProtoResolver.java index 8d57a75c14b..ec5b0ee7f33 100644 --- a/core/src/main/java/bisq/core/proto/network/CoreNetworkProtoResolver.java +++ b/core/src/main/java/bisq/core/proto/network/CoreNetworkProtoResolver.java @@ -46,6 +46,8 @@ import bisq.core.support.dispute.messages.PeerOpenedDisputeMessage; import bisq.core.support.dispute.refund.refundagent.RefundAgent; import bisq.core.support.messages.ChatMessage; +import bisq.core.trade.messages.CancelTradeRequestAcceptedMessage; +import bisq.core.trade.messages.CancelTradeRequestRejectedMessage; import bisq.core.trade.messages.CounterCurrencyTransferStartedMessage; import bisq.core.trade.messages.DelayedPayoutTxSignatureRequest; import bisq.core.trade.messages.DelayedPayoutTxSignatureResponse; @@ -58,6 +60,7 @@ import bisq.core.trade.messages.PayoutTxPublishedMessage; import bisq.core.trade.messages.PeerPublishedDelayedPayoutTxMessage; import bisq.core.trade.messages.RefreshTradeStateRequest; +import bisq.core.trade.messages.RequestCancelTradeMessage; import bisq.core.trade.messages.TraderSignedWitnessMessage; import bisq.core.trade.statistics.TradeStatistics; @@ -174,6 +177,13 @@ public NetworkEnvelope fromProto(protobuf.NetworkEnvelope proto) throws Protobuf case MEDIATED_PAYOUT_TX_PUBLISHED_MESSAGE: return MediatedPayoutTxPublishedMessage.fromProto(proto.getMediatedPayoutTxPublishedMessage(), messageVersion); + case REQUEST_CANCEL_TRADE_MESSAGE: + return RequestCancelTradeMessage.fromProto(proto.getRequestCancelTradeMessage(), messageVersion); + case CANCEL_TRADE_ACCEPTED_MESSAGE: + return CancelTradeRequestAcceptedMessage.fromProto(proto.getCancelTradeAcceptedMessage(), messageVersion); + case CANCEL_TRADE_REJECTED_MESSAGE: + return CancelTradeRequestRejectedMessage.fromProto(proto.getCancelTradeRejectedMessage(), messageVersion); + case OPEN_NEW_DISPUTE_MESSAGE: return OpenNewDisputeMessage.fromProto(proto.getOpenNewDisputeMessage(), this, messageVersion); case PEER_OPENED_DISPUTE_MESSAGE: diff --git a/core/src/main/java/bisq/core/trade/CanceledTradeState.java b/core/src/main/java/bisq/core/trade/CanceledTradeState.java new file mode 100644 index 00000000000..89ea9afbf3b --- /dev/null +++ b/core/src/main/java/bisq/core/trade/CanceledTradeState.java @@ -0,0 +1,50 @@ +/* + * This file is part of Bisq. + * + * Bisq 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. + * + * Bisq 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 Bisq. If not, see . + */ + +package bisq.core.trade; + +public enum CanceledTradeState { + REQUEST_MSG_SENT, + REQUEST_MSG_ARRIVED, + REQUEST_MSG_IN_MAILBOX, + REQUEST_MSG_SEND_FAILED, + + // Peer received request + RECEIVED_CANCEL_REQUEST, + + // Requester received reject msg + RECEIVED_ACCEPTED_MSG, + + // Peer accepted + PAYOUT_TX_PUBLISHED, + PAYOUT_TX_PUBLISHED_MSG_SENT, + PAYOUT_TX_PUBLISHED_MSG_ARRIVED, + PAYOUT_TX_PUBLISHED_MSG_IN_MAILBOX, + PAYOUT_TX_PUBLISHED_MSG_SEND_FAILED, + + // Request sees tx + PAYOUT_TX_SEEN_IN_NETWORK, + + // Peer rejected + REQUEST_CANCELED_MSG_SENT, + REQUEST_CANCELED_MSG_ARRIVED, + REQUEST_CANCELED_MSG_IN_MAILBOX, + REQUEST_CANCELED_MSG_SEND_FAILED, + + // Requester received reject msg + RECEIVED_REJECTED_MSG, +} diff --git a/core/src/main/java/bisq/core/trade/Trade.java b/core/src/main/java/bisq/core/trade/Trade.java index a00fe2dca89..16acf8c6f26 100644 --- a/core/src/main/java/bisq/core/trade/Trade.java +++ b/core/src/main/java/bisq/core/trade/Trade.java @@ -450,6 +450,12 @@ public static protobuf.Trade.TradePeriodState toProtoMessage(Trade.TradePeriodSt @Getter transient final private IntegerProperty assetTxProofResultUpdateProperty = new SimpleIntegerProperty(); + @Getter + // Added at v1.3.9 + public CanceledTradeState canceledTradeState; + @Getter + transient final private ObjectProperty canceledTradeStateProperty = new SimpleObjectProperty<>(); + /////////////////////////////////////////////////////////////////////////////////////////// // Constructor, initialization @@ -563,6 +569,7 @@ public Message toProtoMessage() { Optional.ofNullable(delayedPayoutTxBytes).ifPresent(e -> builder.setDelayedPayoutTxBytes(ByteString.copyFrom(delayedPayoutTxBytes))); Optional.ofNullable(counterCurrencyExtraData).ifPresent(e -> builder.setCounterCurrencyExtraData(counterCurrencyExtraData)); Optional.ofNullable(assetTxProofResult).ifPresent(e -> builder.setAssetTxProofResult(assetTxProofResult.name())); + Optional.ofNullable(canceledTradeState).ifPresent(e -> builder.setCanceledTradeState(canceledTradeState.name())); return builder.build(); } @@ -605,6 +612,8 @@ public static Trade fromProto(Trade trade, protobuf.Trade proto, CoreProtoResolv } trade.setAssetTxProofResult(persistedAssetTxProofResult); + trade.setCanceledTradeState(ProtoUtil.enumFromProto(CanceledTradeState.class, proto.getCanceledTradeState())); + trade.chatMessages.addAll(proto.getChatMessageList().stream() .map(ChatMessage::fromPayloadProto) .collect(Collectors.toList())); @@ -893,6 +902,11 @@ public void setAssetTxProofResult(@Nullable AssetTxProofResult assetTxProofResul persist(); } + public void setCanceledTradeState(CanceledTradeState canceledTradeState) { + this.canceledTradeState = canceledTradeState; + canceledTradeStateProperty.set(canceledTradeState); + persist(); + } /////////////////////////////////////////////////////////////////////////////////////////// // Getter @@ -1230,6 +1244,7 @@ public String toString() { ",\n refundResultState=" + refundResultState + ",\n refundResultStateProperty=" + refundResultStateProperty + ",\n lastRefreshRequestDate=" + lastRefreshRequestDate + + ",\n canceledTradeState=" + canceledTradeState + "\n}"; } } diff --git a/core/src/main/java/bisq/core/trade/TradeCancellationManager.java b/core/src/main/java/bisq/core/trade/TradeCancellationManager.java new file mode 100644 index 00000000000..4b63a5ea419 --- /dev/null +++ b/core/src/main/java/bisq/core/trade/TradeCancellationManager.java @@ -0,0 +1,117 @@ +/* + * This file is part of Bisq. + * + * Bisq 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. + * + * Bisq 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 Bisq. If not, see . + */ + +package bisq.core.trade; + +import bisq.core.btc.wallet.Restrictions; +import bisq.core.offer.Offer; +import bisq.core.trade.protocol.ProcessModel; + +import bisq.common.handlers.ErrorMessageHandler; +import bisq.common.handlers.ResultHandler; + +import org.bitcoinj.core.Coin; + +import com.google.inject.Inject; +import com.google.inject.Singleton; + +import lombok.extern.slf4j.Slf4j; + +import static com.google.common.base.Preconditions.checkNotNull; + +@Slf4j +@Singleton +public final class TradeCancellationManager { + + /////////////////////////////////////////////////////////////////////////////////////////// + // Constructor + /////////////////////////////////////////////////////////////////////////////////////////// + + @Inject + public TradeCancellationManager() { + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // API + /////////////////////////////////////////////////////////////////////////////////////////// + + public void requestCancelTrade(Trade trade, + ResultHandler resultHandler, + ErrorMessageHandler errorMessageHandler) { + ProcessModel processModel = trade.getProcessModel(); + Offer offer = checkNotNull(trade.getOffer()); + Coin secDepositOfRequester = getSecurityDepositForRequester(); + Coin totalSecDeposit = offer.getSellerSecurityDeposit().add(offer.getBuyerSecurityDeposit()); + Coin secDepositForForPeer = totalSecDeposit.subtract(secDepositOfRequester); + Coin tradeAmount = checkNotNull(trade.getTradeAmount(), "tradeAmount must not be null"); + if (trade instanceof BuyerTrade) { + processModel.setBuyerPayoutAmountFromCanceledTrade(secDepositOfRequester.value); + processModel.setSellerPayoutAmountFromCanceledTrade(tradeAmount.add(secDepositForForPeer).value); + } else { + processModel.setBuyerPayoutAmountFromCanceledTrade(secDepositForForPeer.value); + processModel.setSellerPayoutAmountFromCanceledTrade(tradeAmount.add(secDepositOfRequester).value); + } + trade.getTradeProtocol().onRequestCancelTrade(resultHandler, errorMessageHandler); + } + + public Coin getSecurityDepositForRequester() { + return Restrictions.getMinRefundAtMediatedDispute(); + } + + private Coin getTotalSecDepositForAcceptingTrader(Offer offer) { + Coin totalSecDeposit = offer.getSellerSecurityDeposit().add(offer.getBuyerSecurityDeposit()); + return totalSecDeposit.subtract(getSecurityDepositForRequester()); + } + + public Coin getDefaultSecDepositOfAcceptingTrader(Trade trade) { + Offer offer = checkNotNull(trade.getOffer()); + return trade instanceof BuyerTrade ? + offer.getBuyerSecurityDeposit() : + offer.getSellerSecurityDeposit(); + } + + public Coin getLostSecDepositOfRequestingTrader(Trade trade) { + Offer offer = checkNotNull(trade.getOffer()); + return getTotalSecDepositForAcceptingTrader(offer).subtract(getDefaultSecDepositOfAcceptingTrader(trade)); + } + + public void acceptCancelTradeRequest(Trade trade, + ResultHandler resultHandler, + ErrorMessageHandler errorMessageHandler) { + ProcessModel processModel = trade.getProcessModel(); + Offer offer = checkNotNull(trade.getOffer()); + Coin secDepositOfRequester = getSecurityDepositForRequester(); + Coin totalSecDeposit = offer.getSellerSecurityDeposit().add(offer.getBuyerSecurityDeposit()); + Coin secDepositOfAcceptingTrader = totalSecDeposit.subtract(secDepositOfRequester); + Coin tradeAmount = checkNotNull(trade.getTradeAmount(), "tradeAmount must not be null"); + if (trade instanceof BuyerTrade) { + processModel.setBuyerPayoutAmountFromCanceledTrade(secDepositOfAcceptingTrader.value); + processModel.setSellerPayoutAmountFromCanceledTrade(tradeAmount.add(secDepositOfRequester).value); + } else { + processModel.setBuyerPayoutAmountFromCanceledTrade(secDepositOfRequester.value); + processModel.setSellerPayoutAmountFromCanceledTrade(tradeAmount.add(secDepositOfAcceptingTrader).value); + } + trade.getTradeProtocol().onAcceptCancelTradeRequest(resultHandler, errorMessageHandler); + } + + public void rejectCancelTradeRequest(Trade trade, + ResultHandler resultHandler, + ErrorMessageHandler errorMessageHandler) { + trade.getTradeProtocol().onRejectCancelTradeRequest(resultHandler, errorMessageHandler); + } +} diff --git a/core/src/main/java/bisq/core/trade/TradeManager.java b/core/src/main/java/bisq/core/trade/TradeManager.java index 66962f10d68..3cc270a6b86 100644 --- a/core/src/main/java/bisq/core/trade/TradeManager.java +++ b/core/src/main/java/bisq/core/trade/TradeManager.java @@ -673,6 +673,16 @@ private void removeTrade(Trade trade) { } + /////////////////////////////////////////////////////////////////////////////////////////// + // Canceled trade + /////////////////////////////////////////////////////////////////////////////////////////// + + public void closeCanceledTrade(Trade trade) { + addTradeToClosedTrades(trade); + btcWalletService.swapTradeEntryToAvailableEntry(trade.getId(), AddressEntry.Context.TRADE_PAYOUT); + } + + /////////////////////////////////////////////////////////////////////////////////////////// // Dispute /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/core/src/main/java/bisq/core/trade/messages/CancelTradeRequestAcceptedMessage.java b/core/src/main/java/bisq/core/trade/messages/CancelTradeRequestAcceptedMessage.java new file mode 100644 index 00000000000..521d821b540 --- /dev/null +++ b/core/src/main/java/bisq/core/trade/messages/CancelTradeRequestAcceptedMessage.java @@ -0,0 +1,91 @@ +/* + * This file is part of Bisq. + * + * Bisq 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. + * + * Bisq 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 Bisq. If not, see . + */ + +package bisq.core.trade.messages; + +import bisq.network.p2p.MailboxMessage; +import bisq.network.p2p.NodeAddress; + +import bisq.common.app.Version; +import bisq.common.proto.network.NetworkEnvelope; +import bisq.common.util.Utilities; + +import com.google.protobuf.ByteString; + +import lombok.EqualsAndHashCode; +import lombok.Value; + +@EqualsAndHashCode(callSuper = true) +@Value +public final class CancelTradeRequestAcceptedMessage extends TradeMessage implements MailboxMessage { + private final byte[] payoutTx; + private final NodeAddress senderNodeAddress; + + public CancelTradeRequestAcceptedMessage(String tradeId, + byte[] payoutTx, + NodeAddress senderNodeAddress, + String uid) { + this(tradeId, + payoutTx, + senderNodeAddress, + uid, + Version.getP2PMessageVersion()); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // PROTO BUFFER + /////////////////////////////////////////////////////////////////////////////////////////// + + private CancelTradeRequestAcceptedMessage(String tradeId, + byte[] payoutTx, + NodeAddress senderNodeAddress, + String uid, + int messageVersion) { + super(messageVersion, tradeId, uid); + this.payoutTx = payoutTx; + this.senderNodeAddress = senderNodeAddress; + } + + @Override + public protobuf.NetworkEnvelope toProtoNetworkEnvelope() { + return getNetworkEnvelopeBuilder() + .setCancelTradeAcceptedMessage(protobuf.CancelTradeRequestAcceptedMessage.newBuilder() + .setTradeId(tradeId) + .setPayoutTx(ByteString.copyFrom(payoutTx)) + .setSenderNodeAddress(senderNodeAddress.toProtoMessage()) + .setUid(uid)) + .build(); + } + + public static NetworkEnvelope fromProto(protobuf.CancelTradeRequestAcceptedMessage proto, int messageVersion) { + return new CancelTradeRequestAcceptedMessage(proto.getTradeId(), + proto.getPayoutTx().toByteArray(), + NodeAddress.fromProto(proto.getSenderNodeAddress()), + proto.getUid(), + messageVersion); + } + + @Override + public String toString() { + return "CancelTradeRequestAcceptedMessage{" + + "\n payoutTx=" + Utilities.bytesAsHexString(payoutTx) + + ",\n senderNodeAddress=" + senderNodeAddress + + ",\n uid='" + uid + '\'' + + "\n} " + super.toString(); + } +} diff --git a/core/src/main/java/bisq/core/trade/messages/CancelTradeRequestRejectedMessage.java b/core/src/main/java/bisq/core/trade/messages/CancelTradeRequestRejectedMessage.java new file mode 100644 index 00000000000..a6bc084eb2c --- /dev/null +++ b/core/src/main/java/bisq/core/trade/messages/CancelTradeRequestRejectedMessage.java @@ -0,0 +1,80 @@ +/* + * This file is part of Bisq. + * + * Bisq 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. + * + * Bisq 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 Bisq. If not, see . + */ + +package bisq.core.trade.messages; + +import bisq.network.p2p.MailboxMessage; +import bisq.network.p2p.NodeAddress; + +import bisq.common.app.Version; +import bisq.common.proto.network.NetworkEnvelope; + +import lombok.EqualsAndHashCode; +import lombok.Value; + +@EqualsAndHashCode(callSuper = true) +@Value +public final class CancelTradeRequestRejectedMessage extends TradeMessage implements MailboxMessage { + private final NodeAddress senderNodeAddress; + + public CancelTradeRequestRejectedMessage(String tradeId, + NodeAddress senderNodeAddress, + String uid) { + this(tradeId, + senderNodeAddress, + uid, + Version.getP2PMessageVersion()); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // PROTO BUFFER + /////////////////////////////////////////////////////////////////////////////////////////// + + private CancelTradeRequestRejectedMessage(String tradeId, + NodeAddress senderNodeAddress, + String uid, + int messageVersion) { + super(messageVersion, tradeId, uid); + this.senderNodeAddress = senderNodeAddress; + } + + @Override + public protobuf.NetworkEnvelope toProtoNetworkEnvelope() { + return getNetworkEnvelopeBuilder() + .setCancelTradeRejectedMessage(protobuf.CancelTradeRequestRejectedMessage.newBuilder() + .setTradeId(tradeId) + .setSenderNodeAddress(senderNodeAddress.toProtoMessage()) + .setUid(uid)) + .build(); + } + + public static NetworkEnvelope fromProto(protobuf.CancelTradeRequestRejectedMessage proto, int messageVersion) { + return new CancelTradeRequestRejectedMessage(proto.getTradeId(), + NodeAddress.fromProto(proto.getSenderNodeAddress()), + proto.getUid(), + messageVersion); + } + + @Override + public String toString() { + return "CancelTradeRequestRejectedMessage{" + + ",\n senderNodeAddress=" + senderNodeAddress + + ",\n uid='" + uid + '\'' + + "\n} " + super.toString(); + } +} diff --git a/core/src/main/java/bisq/core/trade/messages/RequestCancelTradeMessage.java b/core/src/main/java/bisq/core/trade/messages/RequestCancelTradeMessage.java new file mode 100644 index 00000000000..e8461cb4fbd --- /dev/null +++ b/core/src/main/java/bisq/core/trade/messages/RequestCancelTradeMessage.java @@ -0,0 +1,99 @@ +/* + * This file is part of Bisq. + * + * Bisq 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. + * + * Bisq 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 Bisq. If not, see . + */ + +package bisq.core.trade.messages; + +import bisq.network.p2p.MailboxMessage; +import bisq.network.p2p.NodeAddress; + +import bisq.common.app.Version; +import bisq.common.util.Utilities; + +import com.google.protobuf.ByteString; + +import lombok.EqualsAndHashCode; +import lombok.Value; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Value +@EqualsAndHashCode(callSuper = true) +public class RequestCancelTradeMessage extends TradeMessage implements MailboxMessage { + private final byte[] txSignature; + private final NodeAddress senderNodeAddress; + + public RequestCancelTradeMessage(byte[] txSignature, + String tradeId, + NodeAddress senderNodeAddress, + String uid) { + this(txSignature, + tradeId, + senderNodeAddress, + uid, + Version.getP2PMessageVersion()); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // PROTO BUFFER + /////////////////////////////////////////////////////////////////////////////////////////// + + private RequestCancelTradeMessage(byte[] txSignature, + String tradeId, + NodeAddress senderNodeAddress, + String uid, + int messageVersion) { + super(messageVersion, tradeId, uid); + this.txSignature = txSignature; + this.senderNodeAddress = senderNodeAddress; + } + + @Override + public protobuf.NetworkEnvelope toProtoNetworkEnvelope() { + return getNetworkEnvelopeBuilder() + .setRequestCancelTradeMessage(protobuf.RequestCancelTradeMessage.newBuilder() + .setTxSignature(ByteString.copyFrom(txSignature)) + .setTradeId(tradeId) + .setSenderNodeAddress(senderNodeAddress.toProtoMessage()) + .setUid(uid)) + .build(); + } + + public static RequestCancelTradeMessage fromProto(protobuf.RequestCancelTradeMessage proto, + int messageVersion) { + return new RequestCancelTradeMessage(proto.getTxSignature().toByteArray(), + proto.getTradeId(), + NodeAddress.fromProto(proto.getSenderNodeAddress()), + proto.getUid(), + messageVersion); + } + + @Override + public String getTradeId() { + return tradeId; + } + + + @Override + public String toString() { + return "CanceledTradePayoutSignatureMessage{" + + "\n txSignature=" + Utilities.bytesAsHexString(txSignature) + + ",\n tradeId='" + tradeId + '\'' + + ",\n senderNodeAddress=" + senderNodeAddress + + "\n} " + super.toString(); + } +} diff --git a/core/src/main/java/bisq/core/trade/protocol/ProcessModel.java b/core/src/main/java/bisq/core/trade/protocol/ProcessModel.java index 27317d7569c..20780d7d604 100644 --- a/core/src/main/java/bisq/core/trade/protocol/ProcessModel.java +++ b/core/src/main/java/bisq/core/trade/protocol/ProcessModel.java @@ -158,6 +158,15 @@ public class ProcessModel implements Model, PersistablePayload { @Setter private long sellerPayoutAmountFromMediation; + // Added in v.1.3.9 + @Nullable + @Setter + private byte[] canceledTradePayoutTxSignature; + @Setter + private long buyerPayoutAmountFromCanceledTrade; + @Setter + private long sellerPayoutAmountFromCanceledTrade; + // The only trade message where we want to indicate the user the state of the message delivery is the // CounterCurrencyTransferStartedMessage. We persist the state with the processModel. @Setter @@ -183,7 +192,9 @@ public protobuf.ProcessModel toProtoMessage() { .setFundsNeededForTradeAsLong(fundsNeededForTradeAsLong) .setPaymentStartedMessageState(paymentStartedMessageStateProperty.get().name()) .setBuyerPayoutAmountFromMediation(buyerPayoutAmountFromMediation) - .setSellerPayoutAmountFromMediation(sellerPayoutAmountFromMediation); + .setSellerPayoutAmountFromMediation(sellerPayoutAmountFromMediation) + .setBuyerPayoutAmountFromCanceledTrade(buyerPayoutAmountFromCanceledTrade) + .setSellerPayoutAmountFromCanceledTrade(sellerPayoutAmountFromCanceledTrade); Optional.ofNullable(takeOfferFeeTxId).ifPresent(builder::setTakeOfferFeeTxId); Optional.ofNullable(payoutTxSignature).ifPresent(e -> builder.setPayoutTxSignature(ByteString.copyFrom(payoutTxSignature))); @@ -194,6 +205,7 @@ public protobuf.ProcessModel toProtoMessage() { Optional.ofNullable(myMultiSigPubKey).ifPresent(e -> builder.setMyMultiSigPubKey(ByteString.copyFrom(myMultiSigPubKey))); Optional.ofNullable(tempTradingPeerNodeAddress).ifPresent(e -> builder.setTempTradingPeerNodeAddress(tempTradingPeerNodeAddress.toProtoMessage())); Optional.ofNullable(mediatedPayoutTxSignature).ifPresent(e -> builder.setMediatedPayoutTxSignature(ByteString.copyFrom(e))); + Optional.ofNullable(canceledTradePayoutTxSignature).ifPresent(e -> builder.setCanceledTradePayoutTxSignature(ByteString.copyFrom(e))); return builder.build(); } @@ -209,6 +221,8 @@ public static ProcessModel fromProto(protobuf.ProcessModel proto, CoreProtoResol processModel.setFundsNeededForTradeAsLong(proto.getFundsNeededForTradeAsLong()); processModel.setBuyerPayoutAmountFromMediation(proto.getBuyerPayoutAmountFromMediation()); processModel.setSellerPayoutAmountFromMediation(proto.getSellerPayoutAmountFromMediation()); + processModel.setBuyerPayoutAmountFromCanceledTrade(proto.getBuyerPayoutAmountFromCanceledTrade()); + processModel.setSellerPayoutAmountFromCanceledTrade(proto.getSellerPayoutAmountFromCanceledTrade()); // nullable processModel.setTakeOfferFeeTxId(ProtoUtil.stringOrNullFromProto(proto.getTakeOfferFeeTxId())); @@ -225,6 +239,7 @@ public static ProcessModel fromProto(protobuf.ProcessModel proto, CoreProtoResol ObjectProperty paymentStartedMessageStateProperty = processModel.getPaymentStartedMessageStateProperty(); paymentStartedMessageStateProperty.set(ProtoUtil.enumFromProto(MessageState.class, paymentStartedMessageState)); processModel.setMediatedPayoutTxSignature(ProtoUtil.byteArrayOrNullFromProto(proto.getMediatedPayoutTxSignature())); + processModel.setCanceledTradePayoutTxSignature(ProtoUtil.byteArrayOrNullFromProto(proto.getCanceledTradePayoutTxSignature())); return processModel; } diff --git a/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java b/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java index c561b242741..9b340dbb994 100644 --- a/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java @@ -20,15 +20,28 @@ import bisq.core.trade.MakerTrade; import bisq.core.trade.Trade; import bisq.core.trade.TradeManager; +import bisq.core.trade.messages.CancelTradeRequestAcceptedMessage; +import bisq.core.trade.messages.CancelTradeRequestRejectedMessage; import bisq.core.trade.messages.CounterCurrencyTransferStartedMessage; import bisq.core.trade.messages.InputsForDepositTxRequest; import bisq.core.trade.messages.MediatedPayoutTxPublishedMessage; import bisq.core.trade.messages.MediatedPayoutTxSignatureMessage; import bisq.core.trade.messages.PeerPublishedDelayedPayoutTxMessage; +import bisq.core.trade.messages.RequestCancelTradeMessage; import bisq.core.trade.messages.TradeMessage; import bisq.core.trade.messages.TraderSignedWitnessMessage; import bisq.core.trade.protocol.tasks.ApplyFilter; import bisq.core.trade.protocol.tasks.ProcessPeerPublishedDelayedPayoutTxMessage; +import bisq.core.trade.protocol.tasks.cancel.BroadcastCanceledTradePayoutTx; +import bisq.core.trade.protocol.tasks.cancel.FinalizeCanceledTradePayoutTx; +import bisq.core.trade.protocol.tasks.cancel.ProcessCancelTradeRequestAcceptedMessage; +import bisq.core.trade.protocol.tasks.cancel.ProcessCancelTradeRequestRejectedMessage; +import bisq.core.trade.protocol.tasks.cancel.ProcessRequestCancelTradeMessage; +import bisq.core.trade.protocol.tasks.cancel.SendCancelTradeRequestAcceptedMessage; +import bisq.core.trade.protocol.tasks.cancel.SendCancelTradeRequestRejectedMessage; +import bisq.core.trade.protocol.tasks.cancel.SendRequestCancelTradeMessage; +import bisq.core.trade.protocol.tasks.cancel.SetupCanceledTradePayoutTxListener; +import bisq.core.trade.protocol.tasks.cancel.SignCanceledTradePayoutTx; import bisq.core.trade.protocol.tasks.mediation.BroadcastMediatedPayoutTx; import bisq.core.trade.protocol.tasks.mediation.FinalizeMediatedPayoutTx; import bisq.core.trade.protocol.tasks.mediation.ProcessMediatedPayoutSignatureMessage; @@ -210,6 +223,128 @@ protected void handle(MediatedPayoutTxPublishedMessage tradeMessage, NodeAddress } + /////////////////////////////////////////////////////////////////////////////////////////// + // Cancel trade: Called from UI if trader requests cancellation + /////////////////////////////////////////////////////////////////////////////////////////// + + // Trader request a cancellation and sends signature + public void onRequestCancelTrade(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { + TradeTaskRunner taskRunner = new TradeTaskRunner(trade, + () -> { + resultHandler.handleResult(); + handleTaskRunnerSuccess("onRequestCancelTrade"); + }, + (errorMessage) -> { + errorMessageHandler.handleErrorMessage(errorMessage); + handleTaskRunnerFault(errorMessage); + }); + taskRunner.addTasks( + ApplyFilter.class, + SignCanceledTradePayoutTx.class, + SendRequestCancelTradeMessage.class, + SetupCanceledTradePayoutTxListener.class + ); + taskRunner.run(); + } + + + // Peer has received a cancel request and accept the request and creates the payout tx. + public void onAcceptCancelTradeRequest(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { + if (trade.getPayoutTx() != null) { + errorMessageHandler.handleErrorMessage("Payout tx is already published."); + return; + } + + TradeTaskRunner taskRunner = new TradeTaskRunner(trade, + () -> { + resultHandler.handleResult(); + handleTaskRunnerSuccess("onAcceptCancelTradeRequest"); + }, + (errorMessage) -> { + errorMessageHandler.handleErrorMessage(errorMessage); + handleTaskRunnerFault(errorMessage); + }); + taskRunner.addTasks( + ApplyFilter.class, + SignCanceledTradePayoutTx.class, + FinalizeCanceledTradePayoutTx.class, + BroadcastCanceledTradePayoutTx.class, + SendCancelTradeRequestAcceptedMessage.class + ); + taskRunner.run(); + } + + // Trader has rejected the request. + public void onRejectCancelTradeRequest(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { + if (trade.getPayoutTx() != null) { + errorMessageHandler.handleErrorMessage("Payout tx is already published."); + return; + } + + TradeTaskRunner taskRunner = new TradeTaskRunner(trade, + () -> { + resultHandler.handleResult(); + handleTaskRunnerSuccess("onRejectCancelTradeRequest"); + }, + (errorMessage) -> { + errorMessageHandler.handleErrorMessage(errorMessage); + handleTaskRunnerFault(errorMessage); + }); + taskRunner.addTasks( + ApplyFilter.class, + SendCancelTradeRequestRejectedMessage.class + ); + taskRunner.run(); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Cancel trade: incoming message + /////////////////////////////////////////////////////////////////////////////////////////// + + protected void handle(RequestCancelTradeMessage tradeMessage, NodeAddress sender) { + processModel.setTradeMessage(tradeMessage); + processModel.setTempTradingPeerNodeAddress(sender); + + TradeTaskRunner taskRunner = new TradeTaskRunner(trade, + () -> handleTaskRunnerSuccess(tradeMessage, "handle RequestCancelTradeMessage"), + errorMessage -> handleTaskRunnerFault(tradeMessage, errorMessage)); + + taskRunner.addTasks( + ProcessRequestCancelTradeMessage.class + ); + taskRunner.run(); + } + + protected void handle(CancelTradeRequestAcceptedMessage tradeMessage, NodeAddress sender) { + processModel.setTradeMessage(tradeMessage); + processModel.setTempTradingPeerNodeAddress(sender); + + TradeTaskRunner taskRunner = new TradeTaskRunner(trade, + () -> handleTaskRunnerSuccess(tradeMessage, "handle CancelTradeRequestAcceptedMessage"), + errorMessage -> handleTaskRunnerFault(tradeMessage, errorMessage)); + + taskRunner.addTasks( + ProcessCancelTradeRequestAcceptedMessage.class + ); + taskRunner.run(); + } + + protected void handle(CancelTradeRequestRejectedMessage tradeMessage, NodeAddress sender) { + processModel.setTradeMessage(tradeMessage); + processModel.setTempTradingPeerNodeAddress(sender); + + TradeTaskRunner taskRunner = new TradeTaskRunner(trade, + () -> handleTaskRunnerSuccess(tradeMessage, "handle CancelTradeRequestRejectedMessage"), + errorMessage -> handleTaskRunnerFault(tradeMessage, errorMessage)); + + taskRunner.addTasks( + ProcessCancelTradeRequestRejectedMessage.class + ); + taskRunner.run(); + } + + /////////////////////////////////////////////////////////////////////////////////////////// // Peer has published the delayed payout tx /////////////////////////////////////////////////////////////////////////////////////////// @@ -248,6 +383,12 @@ protected void doHandleDecryptedMessage(TradeMessage tradeMessage, NodeAddress s handle((MediatedPayoutTxSignatureMessage) tradeMessage, sender); } else if (tradeMessage instanceof MediatedPayoutTxPublishedMessage) { handle((MediatedPayoutTxPublishedMessage) tradeMessage, sender); + } else if (tradeMessage instanceof RequestCancelTradeMessage) { + handle((RequestCancelTradeMessage) tradeMessage, sender); + } else if (tradeMessage instanceof CancelTradeRequestAcceptedMessage) { + handle((CancelTradeRequestAcceptedMessage) tradeMessage, sender); + } else if (tradeMessage instanceof CancelTradeRequestRejectedMessage) { + handle((CancelTradeRequestRejectedMessage) tradeMessage, sender); } else if (tradeMessage instanceof PeerPublishedDelayedPayoutTxMessage) { handle((PeerPublishedDelayedPayoutTxMessage) tradeMessage, sender); } else if (tradeMessage instanceof TraderSignedWitnessMessage) { diff --git a/core/src/main/java/bisq/core/trade/protocol/TradingPeer.java b/core/src/main/java/bisq/core/trade/protocol/TradingPeer.java index 5da74be2083..a613712a0bb 100644 --- a/core/src/main/java/bisq/core/trade/protocol/TradingPeer.java +++ b/core/src/main/java/bisq/core/trade/protocol/TradingPeer.java @@ -88,6 +88,9 @@ public final class TradingPeer implements PersistablePayload { @Nullable private byte[] mediatedPayoutTxSignature; + // Added in v.1.3.9 + @Nullable + private byte[] canceledTradePayoutTxSignature; public TradingPeer() { } @@ -110,6 +113,7 @@ public Message toProtoMessage() { Optional.ofNullable(accountAgeWitnessNonce).ifPresent(e -> builder.setAccountAgeWitnessNonce(ByteString.copyFrom(e))); Optional.ofNullable(accountAgeWitnessSignature).ifPresent(e -> builder.setAccountAgeWitnessSignature(ByteString.copyFrom(e))); Optional.ofNullable(mediatedPayoutTxSignature).ifPresent(e -> builder.setMediatedPayoutTxSignature(ByteString.copyFrom(e))); + Optional.ofNullable(canceledTradePayoutTxSignature).ifPresent(e -> builder.setCanceledTradePayoutTxSignature(ByteString.copyFrom(e))); builder.setCurrentDate(currentDate); return builder.build(); } @@ -139,6 +143,7 @@ public static TradingPeer fromProto(protobuf.TradingPeer proto, CoreProtoResolve tradingPeer.setAccountAgeWitnessSignature(ProtoUtil.byteArrayOrNullFromProto(proto.getAccountAgeWitnessSignature())); tradingPeer.setCurrentDate(proto.getCurrentDate()); tradingPeer.setMediatedPayoutTxSignature(ProtoUtil.byteArrayOrNullFromProto(proto.getMediatedPayoutTxSignature())); + tradingPeer.setCanceledTradePayoutTxSignature(ProtoUtil.byteArrayOrNullFromProto(proto.getCanceledTradePayoutTxSignature())); return tradingPeer; } } diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java new file mode 100644 index 00000000000..c889e889132 --- /dev/null +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java @@ -0,0 +1,50 @@ +/* + * This file is part of Bisq. + * + * Bisq 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. + * + * Bisq 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 Bisq. If not, see . + */ + +package bisq.core.trade.protocol.tasks.cancel; + +import bisq.core.trade.CanceledTradeState; +import bisq.core.trade.Trade; +import bisq.core.trade.protocol.tasks.BroadcastPayoutTx; + +import bisq.common.taskrunner.TaskRunner; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class BroadcastCanceledTradePayoutTx extends BroadcastPayoutTx { + @SuppressWarnings({"unused"}) + public BroadcastCanceledTradePayoutTx(TaskRunner taskHandler, Trade trade) { + super(taskHandler, trade); + } + + @Override + protected void run() { + try { + runInterceptHook(); + + super.run(); + } catch (Throwable t) { + failed(t); + } + } + + @Override + protected void setState() { + trade.setCanceledTradeState(CanceledTradeState.PAYOUT_TX_PUBLISHED); + } +} diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/FinalizeCanceledTradePayoutTx.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/FinalizeCanceledTradePayoutTx.java new file mode 100644 index 00000000000..289ebdac3aa --- /dev/null +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/FinalizeCanceledTradePayoutTx.java @@ -0,0 +1,119 @@ +/* + * This file is part of Bisq. + * + * Bisq 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. + * + * Bisq 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 Bisq. If not, see . + */ + +package bisq.core.trade.protocol.tasks.cancel; + +import bisq.core.btc.model.AddressEntry; +import bisq.core.btc.wallet.BtcWalletService; +import bisq.core.offer.Offer; +import bisq.core.trade.Contract; +import bisq.core.trade.Trade; +import bisq.core.trade.protocol.TradingPeer; +import bisq.core.trade.protocol.tasks.TradeTask; + +import bisq.common.taskrunner.TaskRunner; + +import org.bitcoinj.core.Coin; +import org.bitcoinj.core.Transaction; +import org.bitcoinj.crypto.DeterministicKey; + +import java.util.Arrays; + +import lombok.extern.slf4j.Slf4j; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +@Slf4j +public class FinalizeCanceledTradePayoutTx extends TradeTask { + + @SuppressWarnings({"unused"}) + public FinalizeCanceledTradePayoutTx(TaskRunner taskHandler, Trade trade) { + super(taskHandler, trade); + } + + @Override + protected void run() { + try { + runInterceptHook(); + + Transaction depositTx = checkNotNull(trade.getDepositTx()); + String tradeId = trade.getId(); + TradingPeer tradingPeer = processModel.getTradingPeer(); + BtcWalletService walletService = processModel.getBtcWalletService(); + Offer offer = checkNotNull(trade.getOffer(), "offer must not be null"); + Coin tradeAmount = checkNotNull(trade.getTradeAmount(), "tradeAmount must not be null"); + Contract contract = checkNotNull(trade.getContract(), "contract must not be null"); + + checkNotNull(trade.getTradeAmount(), "trade.getTradeAmount() must not be null"); + + byte[] mySignature = checkNotNull(processModel.getCanceledTradePayoutTxSignature(), + "processModel.getTxSignatureFromCanceledTrade must not be null"); + byte[] peersSignature = checkNotNull(tradingPeer.getCanceledTradePayoutTxSignature(), + "tradingPeer.getTxSignatureFromCanceledTrade must not be null"); + + boolean isMyRoleBuyer = contract.isMyRoleBuyer(processModel.getPubKeyRing()); + byte[] buyerSignature = isMyRoleBuyer ? mySignature : peersSignature; + byte[] sellerSignature = isMyRoleBuyer ? peersSignature : mySignature; + + Coin totalPayoutAmount = offer.getBuyerSecurityDeposit().add(tradeAmount).add(offer.getSellerSecurityDeposit()); + Coin buyerPayoutAmount = Coin.valueOf(processModel.getBuyerPayoutAmountFromCanceledTrade()); + Coin sellerPayoutAmount = Coin.valueOf(processModel.getSellerPayoutAmountFromCanceledTrade()); + checkArgument(totalPayoutAmount.equals(buyerPayoutAmount.add(sellerPayoutAmount)), + "Payout amount does not match buyerPayoutAmount=" + buyerPayoutAmount.toFriendlyString() + + "; sellerPayoutAmount=" + sellerPayoutAmount); + + String myPayoutAddressString = walletService.getOrCreateAddressEntry(tradeId, AddressEntry.Context.TRADE_PAYOUT).getAddressString(); + String peersPayoutAddressString = tradingPeer.getPayoutAddressString(); + String buyerPayoutAddressString = isMyRoleBuyer ? myPayoutAddressString : peersPayoutAddressString; + String sellerPayoutAddressString = isMyRoleBuyer ? peersPayoutAddressString : myPayoutAddressString; + + byte[] myMultiSigPubKey = processModel.getMyMultiSigPubKey(); + byte[] peersMultiSigPubKey = tradingPeer.getMultiSigPubKey(); + byte[] buyerMultiSigPubKey = isMyRoleBuyer ? myMultiSigPubKey : peersMultiSigPubKey; + byte[] sellerMultiSigPubKey = isMyRoleBuyer ? peersMultiSigPubKey : myMultiSigPubKey; + + DeterministicKey multiSigKeyPair = walletService.getMultiSigKeyPair(tradeId, myMultiSigPubKey); + + checkArgument(Arrays.equals(myMultiSigPubKey, + walletService.getOrCreateAddressEntry(tradeId, AddressEntry.Context.MULTI_SIG).getPubKey()), + "myMultiSigPubKey from AddressEntry must match the one from the trade data. trade id =" + tradeId); + + Transaction transaction = processModel.getTradeWalletService().finalizeCanceledTradePayoutTx( + depositTx, + buyerSignature, + sellerSignature, + buyerPayoutAmount, + sellerPayoutAmount, + buyerPayoutAddressString, + sellerPayoutAddressString, + multiSigKeyPair, + buyerMultiSigPubKey, + sellerMultiSigPubKey + ); + + trade.setPayoutTx(transaction); + processModel.getTradeManager().closeCanceledTrade(trade); + walletService.swapTradeEntryToAvailableEntry(tradeId, AddressEntry.Context.MULTI_SIG); + + complete(); + } catch (Throwable t) { + failed(t); + } + } +} + diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java new file mode 100644 index 00000000000..763e26ee9ee --- /dev/null +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java @@ -0,0 +1,81 @@ +/* + * This file is part of Bisq. + * + * Bisq 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. + * + * Bisq 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 Bisq. If not, see . + */ + +package bisq.core.trade.protocol.tasks.cancel; + +import bisq.core.btc.model.AddressEntry; +import bisq.core.btc.wallet.BtcWalletService; +import bisq.core.btc.wallet.WalletService; +import bisq.core.trade.CanceledTradeState; +import bisq.core.trade.Trade; +import bisq.core.trade.messages.CancelTradeRequestAcceptedMessage; +import bisq.core.trade.protocol.tasks.TradeTask; +import bisq.core.util.Validator; + +import bisq.common.UserThread; +import bisq.common.taskrunner.TaskRunner; + +import org.bitcoinj.core.Transaction; + +import lombok.extern.slf4j.Slf4j; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +@Slf4j +public class ProcessCancelTradeRequestAcceptedMessage extends TradeTask { + @SuppressWarnings({"unused"}) + public ProcessCancelTradeRequestAcceptedMessage(TaskRunner taskHandler, Trade trade) { + super(taskHandler, trade); + } + + @Override + protected void run() { + try { + runInterceptHook(); + CancelTradeRequestAcceptedMessage message = (CancelTradeRequestAcceptedMessage) processModel.getTradeMessage(); + Validator.checkTradeId(processModel.getOfferId(), message); + checkNotNull(message); + checkArgument(message.getPayoutTx() != null); + + // update to the latest peer address of our peer if the message is correct + trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress()); + + if (trade.getPayoutTx() == null) { + Transaction committedCanceledTradePayoutTx = WalletService.maybeAddNetworkTxToWallet(message.getPayoutTx(), processModel.getBtcWalletService().getWallet()); + trade.setPayoutTx(committedCanceledTradePayoutTx); + BtcWalletService.printTx("CanceledTradePayoutTx received from peer", committedCanceledTradePayoutTx); + + trade.setCanceledTradeState(CanceledTradeState.RECEIVED_ACCEPTED_MSG); + + // We need to delay that call as we might get executed at startup after mailbox messages are + // applied where we iterate over our pending trades. The closeCanceledTrade method would remove + // that trade from the list causing a ConcurrentModificationException. + // To avoid that we delay for one render frame. + UserThread.execute(() -> processModel.getTradeManager().closeCanceledTrade(trade)); + + processModel.getBtcWalletService().swapTradeEntryToAvailableEntry(trade.getId(), AddressEntry.Context.MULTI_SIG); + } else { + log.info("We got the payout tx already set from SetupCanceledTradePayoutTxListener and do nothing here. trade ID={}", trade.getId()); + } + processModel.removeMailboxMessageAfterProcessing(trade); + complete(); + } catch (Throwable t) { + failed(t); + } + } +} diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java new file mode 100644 index 00000000000..0e1705a3a5f --- /dev/null +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java @@ -0,0 +1,56 @@ +/* + * This file is part of Bisq. + * + * Bisq 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. + * + * Bisq 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 Bisq. If not, see . + */ + +package bisq.core.trade.protocol.tasks.cancel; + +import bisq.core.trade.CanceledTradeState; +import bisq.core.trade.Trade; +import bisq.core.trade.messages.CancelTradeRequestRejectedMessage; +import bisq.core.trade.protocol.tasks.TradeTask; +import bisq.core.util.Validator; + +import bisq.common.taskrunner.TaskRunner; + +import lombok.extern.slf4j.Slf4j; + +import static com.google.common.base.Preconditions.checkNotNull; + +@Slf4j +public class ProcessCancelTradeRequestRejectedMessage extends TradeTask { + @SuppressWarnings({"unused"}) + public ProcessCancelTradeRequestRejectedMessage(TaskRunner taskHandler, Trade trade) { + super(taskHandler, trade); + } + + @Override + protected void run() { + try { + runInterceptHook(); + CancelTradeRequestRejectedMessage message = (CancelTradeRequestRejectedMessage) processModel.getTradeMessage(); + Validator.checkTradeId(processModel.getOfferId(), message); + checkNotNull(message); + + // update to the latest peer address of our peer if the message is correct + trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress()); + trade.setCanceledTradeState(CanceledTradeState.RECEIVED_REJECTED_MSG); + processModel.removeMailboxMessageAfterProcessing(trade); + complete(); + } catch (Throwable t) { + failed(t); + } + } +} diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java new file mode 100644 index 00000000000..dffa4353c26 --- /dev/null +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java @@ -0,0 +1,60 @@ +/* + * This file is part of Bisq. + * + * Bisq 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. + * + * Bisq 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 Bisq. If not, see . + */ + +package bisq.core.trade.protocol.tasks.cancel; + +import bisq.core.trade.CanceledTradeState; +import bisq.core.trade.Trade; +import bisq.core.trade.messages.RequestCancelTradeMessage; +import bisq.core.trade.protocol.tasks.TradeTask; +import bisq.core.util.Validator; + +import bisq.common.taskrunner.TaskRunner; + +import lombok.extern.slf4j.Slf4j; + +import static com.google.common.base.Preconditions.checkNotNull; + +@Slf4j +public class ProcessRequestCancelTradeMessage extends TradeTask { + @SuppressWarnings({"unused"}) + public ProcessRequestCancelTradeMessage(TaskRunner taskHandler, Trade trade) { + super(taskHandler, trade); + } + + @Override + protected void run() { + try { + runInterceptHook(); + RequestCancelTradeMessage message = (RequestCancelTradeMessage) processModel.getTradeMessage(); + Validator.checkTradeId(processModel.getOfferId(), message); + checkNotNull(message); + + processModel.getTradingPeer().setCanceledTradePayoutTxSignature(checkNotNull(message.getTxSignature())); + + // update to the latest peer address of our peer if the message is correct + trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress()); + processModel.removeMailboxMessageAfterProcessing(trade); + + trade.setCanceledTradeState(CanceledTradeState.RECEIVED_CANCEL_REQUEST); + + complete(); + } catch (Throwable t) { + failed(t); + } + } +} diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java new file mode 100644 index 00000000000..72998bbef73 --- /dev/null +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java @@ -0,0 +1,91 @@ +/* + * This file is part of Bisq. + * + * Bisq 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. + * + * Bisq 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 Bisq. If not, see . + */ + +package bisq.core.trade.protocol.tasks.cancel; + +import bisq.core.trade.CanceledTradeState; +import bisq.core.trade.Trade; +import bisq.core.trade.messages.CancelTradeRequestAcceptedMessage; +import bisq.core.trade.messages.TradeMessage; +import bisq.core.trade.protocol.tasks.SendMailboxMessageTask; + +import bisq.common.taskrunner.TaskRunner; + +import org.bitcoinj.core.Transaction; + +import java.util.UUID; + +import lombok.extern.slf4j.Slf4j; + +import static com.google.common.base.Preconditions.checkNotNull; + + +@Slf4j +public class SendCancelTradeRequestAcceptedMessage extends SendMailboxMessageTask { + @SuppressWarnings({"unused"}) + public SendCancelTradeRequestAcceptedMessage(TaskRunner taskHandler, Trade trade) { + super(taskHandler, trade); + } + + @Override + protected TradeMessage getMessage(String id) { + Transaction payoutTx = checkNotNull(trade.getPayoutTx(), "trade.getPayoutTx() must not be null"); + return new CancelTradeRequestAcceptedMessage( + id, + payoutTx.bitcoinSerialize(), + processModel.getMyNodeAddress(), + UUID.randomUUID().toString() + ); + } + + @Override + protected void setStateSent() { + trade.setCanceledTradeState(CanceledTradeState.PAYOUT_TX_PUBLISHED_MSG_SENT); + } + + @Override + protected void setStateArrived() { + trade.setCanceledTradeState(CanceledTradeState.PAYOUT_TX_PUBLISHED_MSG_ARRIVED); + } + + @Override + protected void setStateStoredInMailbox() { + trade.setCanceledTradeState(CanceledTradeState.PAYOUT_TX_PUBLISHED_MSG_IN_MAILBOX); + } + + @Override + protected void setStateFault() { + trade.setCanceledTradeState(CanceledTradeState.PAYOUT_TX_PUBLISHED_MSG_SEND_FAILED); + } + + @Override + protected void run() { + try { + runInterceptHook(); + + if (trade.getPayoutTx() == null) { + log.error("trade.getPayoutTx() = " + trade.getPayoutTx()); + failed("PayoutTx is null"); + return; + } + + super.run(); + } catch (Throwable t) { + failed(t); + } + } +} diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java new file mode 100644 index 00000000000..a28174fe781 --- /dev/null +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java @@ -0,0 +1,79 @@ +/* + * This file is part of Bisq. + * + * Bisq 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. + * + * Bisq 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 Bisq. If not, see . + */ + +package bisq.core.trade.protocol.tasks.cancel; + +import bisq.core.trade.CanceledTradeState; +import bisq.core.trade.Trade; +import bisq.core.trade.messages.CancelTradeRequestRejectedMessage; +import bisq.core.trade.messages.TradeMessage; +import bisq.core.trade.protocol.tasks.SendMailboxMessageTask; + +import bisq.common.taskrunner.TaskRunner; + +import java.util.UUID; + +import lombok.extern.slf4j.Slf4j; + + +@Slf4j +public class SendCancelTradeRequestRejectedMessage extends SendMailboxMessageTask { + @SuppressWarnings({"unused"}) + public SendCancelTradeRequestRejectedMessage(TaskRunner taskHandler, Trade trade) { + super(taskHandler, trade); + } + + @Override + protected TradeMessage getMessage(String id) { + return new CancelTradeRequestRejectedMessage( + id, + processModel.getMyNodeAddress(), + UUID.randomUUID().toString() + ); + } + + @Override + protected void setStateSent() { + trade.setCanceledTradeState(CanceledTradeState.REQUEST_CANCELED_MSG_SENT); + } + + @Override + protected void setStateArrived() { + trade.setCanceledTradeState(CanceledTradeState.REQUEST_CANCELED_MSG_ARRIVED); + } + + @Override + protected void setStateStoredInMailbox() { + trade.setCanceledTradeState(CanceledTradeState.REQUEST_CANCELED_MSG_IN_MAILBOX); + } + + @Override + protected void setStateFault() { + trade.setCanceledTradeState(CanceledTradeState.REQUEST_CANCELED_MSG_SEND_FAILED); + } + + @Override + protected void run() { + try { + runInterceptHook(); + + super.run(); + } catch (Throwable t) { + failed(t); + } + } +} diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java new file mode 100644 index 00000000000..d47a077c421 --- /dev/null +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java @@ -0,0 +1,92 @@ +/* + * This file is part of Bisq. + * + * Bisq 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. + * + * Bisq 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 Bisq. If not, see . + */ + +package bisq.core.trade.protocol.tasks.cancel; + +import bisq.core.trade.CanceledTradeState; +import bisq.core.trade.Contract; +import bisq.core.trade.Trade; +import bisq.core.trade.messages.RequestCancelTradeMessage; +import bisq.core.trade.messages.TradeMessage; +import bisq.core.trade.protocol.tasks.SendMailboxMessageTask; + +import bisq.network.p2p.NodeAddress; +import bisq.network.p2p.P2PService; + +import bisq.common.crypto.PubKeyRing; +import bisq.common.taskrunner.TaskRunner; + +import java.util.UUID; + +import lombok.extern.slf4j.Slf4j; + +import static com.google.common.base.Preconditions.checkNotNull; + +@Slf4j +public class SendRequestCancelTradeMessage extends SendMailboxMessageTask { + @SuppressWarnings({"unused"}) + public SendRequestCancelTradeMessage(TaskRunner taskHandler, Trade trade) { + super(taskHandler, trade); + } + + @Override + protected TradeMessage getMessage(String id) { + PubKeyRing pubKeyRing = processModel.getPubKeyRing(); + Contract contract = checkNotNull(trade.getContract(), "contract must not be null"); + NodeAddress peersNodeAddress = contract.getPeersNodeAddress(pubKeyRing); + P2PService p2PService = processModel.getP2PService(); + RequestCancelTradeMessage message = new RequestCancelTradeMessage(processModel.getCanceledTradePayoutTxSignature(), + trade.getId(), + p2PService.getAddress(), + UUID.randomUUID().toString()); + log.info("Send {} to peer {}. tradeId={}, uid={}", + message.getClass().getSimpleName(), peersNodeAddress, message.getTradeId(), message.getUid()); + + return message; + } + + @Override + protected void setStateSent() { + trade.setCanceledTradeState(CanceledTradeState.REQUEST_MSG_SENT); + } + + @Override + protected void setStateArrived() { + trade.setCanceledTradeState(CanceledTradeState.REQUEST_MSG_ARRIVED); + } + + @Override + protected void setStateStoredInMailbox() { + trade.setCanceledTradeState(CanceledTradeState.REQUEST_MSG_IN_MAILBOX); + } + + @Override + protected void setStateFault() { + trade.setCanceledTradeState(CanceledTradeState.REQUEST_MSG_SEND_FAILED); + } + + @Override + protected void run() { + try { + runInterceptHook(); + + super.run(); + } catch (Throwable t) { + failed(t); + } + } +} diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java new file mode 100644 index 00000000000..71bb02fbf10 --- /dev/null +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java @@ -0,0 +1,54 @@ +/* + * This file is part of Bisq. + * + * Bisq 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. + * + * Bisq 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 Bisq. If not, see . + */ + +package bisq.core.trade.protocol.tasks.cancel; + +import bisq.core.trade.CanceledTradeState; +import bisq.core.trade.Trade; +import bisq.core.trade.protocol.tasks.SetupPayoutTxListener; + +import bisq.common.taskrunner.TaskRunner; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class SetupCanceledTradePayoutTxListener extends SetupPayoutTxListener { + @SuppressWarnings({"unused"}) + public SetupCanceledTradePayoutTxListener(TaskRunner taskHandler, Trade trade) { + super(taskHandler, trade); + } + + @Override + protected void run() { + try { + runInterceptHook(); + + super.run(); + + } catch (Throwable t) { + failed(t); + } + } + + @Override + protected void setState() { + trade.setCanceledTradeState(CanceledTradeState.PAYOUT_TX_SEEN_IN_NETWORK); + if (trade.getPayoutTx() != null) { + processModel.getTradeManager().closeCanceledTrade(trade); + } + } +} diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SignCanceledTradePayoutTx.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SignCanceledTradePayoutTx.java new file mode 100644 index 00000000000..933ab49e423 --- /dev/null +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SignCanceledTradePayoutTx.java @@ -0,0 +1,105 @@ +/* + * This file is part of Bisq. + * + * Bisq 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. + * + * Bisq 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 Bisq. If not, see . + */ + +package bisq.core.trade.protocol.tasks.cancel; + +import bisq.core.btc.model.AddressEntry; +import bisq.core.btc.wallet.BtcWalletService; +import bisq.core.offer.Offer; +import bisq.core.trade.Contract; +import bisq.core.trade.Trade; +import bisq.core.trade.protocol.TradingPeer; +import bisq.core.trade.protocol.tasks.TradeTask; + +import bisq.common.taskrunner.TaskRunner; + +import org.bitcoinj.core.Coin; +import org.bitcoinj.core.Transaction; +import org.bitcoinj.crypto.DeterministicKey; + +import java.util.Arrays; + +import lombok.extern.slf4j.Slf4j; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +@Slf4j +public class SignCanceledTradePayoutTx extends TradeTask { + + @SuppressWarnings({"unused"}) + public SignCanceledTradePayoutTx(TaskRunner taskHandler, Trade trade) { + super(taskHandler, trade); + } + + @Override + protected void run() { + try { + runInterceptHook(); + + TradingPeer tradingPeer = processModel.getTradingPeer(); + String tradeId = trade.getId(); + BtcWalletService walletService = processModel.getBtcWalletService(); + Transaction depositTx = checkNotNull(trade.getDepositTx(), "trade.getDepositTx() must not be null"); + Offer offer = checkNotNull(trade.getOffer(), "offer must not be null"); + Coin tradeAmount = checkNotNull(trade.getTradeAmount(), "tradeAmount must not be null"); + Contract contract = checkNotNull(trade.getContract(), "contract must not be null"); + + Coin totalPayoutAmount = offer.getBuyerSecurityDeposit().add(tradeAmount).add(offer.getSellerSecurityDeposit()); + Coin buyerPayoutAmount = Coin.valueOf(processModel.getBuyerPayoutAmountFromCanceledTrade()); + Coin sellerPayoutAmount = Coin.valueOf(processModel.getSellerPayoutAmountFromCanceledTrade()); + + checkArgument(totalPayoutAmount.equals(buyerPayoutAmount.add(sellerPayoutAmount)), + "Payout amount does not match buyerPayoutAmount=" + buyerPayoutAmount.toFriendlyString() + + "; sellerPayoutAmount=" + sellerPayoutAmount); + + boolean isMyRoleBuyer = contract.isMyRoleBuyer(processModel.getPubKeyRing()); + + String myPayoutAddressString = walletService.getOrCreateAddressEntry(tradeId, AddressEntry.Context.TRADE_PAYOUT).getAddressString(); + String peersPayoutAddressString = tradingPeer.getPayoutAddressString(); + String buyerPayoutAddressString = isMyRoleBuyer ? myPayoutAddressString : peersPayoutAddressString; + String sellerPayoutAddressString = isMyRoleBuyer ? peersPayoutAddressString : myPayoutAddressString; + + byte[] myMultiSigPubKey = processModel.getMyMultiSigPubKey(); + byte[] peersMultiSigPubKey = tradingPeer.getMultiSigPubKey(); + byte[] buyerMultiSigPubKey = isMyRoleBuyer ? myMultiSigPubKey : peersMultiSigPubKey; + byte[] sellerMultiSigPubKey = isMyRoleBuyer ? peersMultiSigPubKey : myMultiSigPubKey; + + DeterministicKey myMultiSigKeyPair = walletService.getMultiSigKeyPair(tradeId, myMultiSigPubKey); + + checkArgument(Arrays.equals(myMultiSigPubKey, + walletService.getOrCreateAddressEntry(tradeId, AddressEntry.Context.MULTI_SIG).getPubKey()), + "myMultiSigPubKey from AddressEntry must match the one from the trade data. trade id =" + tradeId); + + byte[] canceledTradePayoutTx = processModel.getTradeWalletService().signCanceledTradePayoutTx( + depositTx, + buyerPayoutAmount, + sellerPayoutAmount, + buyerPayoutAddressString, + sellerPayoutAddressString, + myMultiSigKeyPair, + buyerMultiSigPubKey, + sellerMultiSigPubKey); + processModel.setCanceledTradePayoutTxSignature(canceledTradePayoutTx); + + complete(); + } catch (Throwable t) { + failed(t); + } + } +} + diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index 78859db8fe0..c4e0c0186da 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -148,6 +148,7 @@ shared.name=Name shared.id=ID shared.dashboard=Dashboard shared.accept=Accept +shared.reject=Reject shared.balance=Balance shared.save=Save shared.onionAddress=Onion address @@ -909,6 +910,30 @@ portfolio.failed.cantUnfail=This trade cannot be moved back to open trades at th portfolio.failed.depositTxNull=The trade cannot be completed. Deposit transaction is null portfolio.failed.delayedPayoutTxNull=The trade cannot be completed. Delayed payout transaction is null +portfolio.pending.cancelTrade=Cancel trade +portfolio.pending.requestSent=Cancel trade request message sent... +portfolio.pending.requestArrived=Cancel trade request message arrived +portfolio.pending.requestInMailbox=Cancel trade request message stored in mailbox +portfolio.pending.requestFailed=Sending cancel trade request message failed +portfolio.pending.requestGotRejected=Your cancel trade request was rejected by the peer +portfolio.pending.doNotDecideYet=Don't decide yet +portfolio.pending.requestCancelTradePopup=You can send a request to your trading peer for canceling the trade.\n\n\ + If the peer accepts your request you will get back a part of your security deposit. The other part will be given to \ + your trading peer as compensation for the lost trade fee, trade opportunity and time.\n\n\ + If the peer accepts your cancel request you will get back {0} from your security deposit.\n\n\ + Do you want to make a request for cancellation? +portfolio.pending.receivedCancelTradeRequestPopup=Your trading peer requested cancellation of the trade.\n\n\ + If you accept you will get back your trade amount, your security deposit and a part of his security deposit as \ + compensation for the lost trade fee, trade opportunity and time.\n\n\ + Your payout would be:\n\ + - Trade amount: {0}\n\ + - Your security deposit: {1}\n\ + - Part of the peer''s security deposit: {2}\n\n\ + If you prefer to continue the trade, reject the peer''s cancel request. If the peer does not complete the trade \ + can open a dispute once the trade period is over.\n\n\ + You can also communicate with the peer via the trader chat to find out about the reason why he want to cancel \ + the trade.\n\n\ + Do you want to accept the request for cancellation? #################################################################### # Funds diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesDataModel.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesDataModel.java index 6d1a288f118..be95a4e56be 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesDataModel.java @@ -49,6 +49,7 @@ import bisq.core.trade.BuyerTrade; import bisq.core.trade.SellerTrade; import bisq.core.trade.Trade; +import bisq.core.trade.TradeCancellationManager; import bisq.core.trade.TradeManager; import bisq.core.trade.messages.RefreshTradeStateRequest; import bisq.core.user.Preferences; @@ -111,7 +112,8 @@ public class PendingTradesDataModel extends ActivatableDataModel { final ObjectProperty selectedItemProperty = new SimpleObjectProperty<>(); public final StringProperty txId = new SimpleStringProperty(); - + @Getter + private final TradeCancellationManager tradeCancellationManager; @Getter private final TraderChatManager traderChatManager; public final Preferences preferences; @@ -131,6 +133,7 @@ public PendingTradesDataModel(TradeManager tradeManager, PubKeyRing pubKeyRing, MediationManager mediationManager, RefundManager refundManager, + TradeCancellationManager tradeCancellationManager, TraderChatManager traderChatManager, Preferences preferences, P2PService p2PService, @@ -145,6 +148,7 @@ public PendingTradesDataModel(TradeManager tradeManager, this.pubKeyRing = pubKeyRing; this.mediationManager = mediationManager; this.refundManager = refundManager; + this.tradeCancellationManager = tradeCancellationManager; this.traderChatManager = traderChatManager; this.preferences = preferences; this.p2PService = p2PService; diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java index ba7b285449c..ea9730aaae3 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesViewModel.java @@ -91,6 +91,7 @@ enum SellerState implements State { STEP4 } + @Getter public final CoinFormatter btcFormatter; private final BsqFormatter bsqFormatter; public final BtcAddressValidator btcAddressValidator; diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/HandleCancelTradeRequestPresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/HandleCancelTradeRequestPresentation.java new file mode 100644 index 00000000000..4fef418e7bf --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/HandleCancelTradeRequestPresentation.java @@ -0,0 +1,159 @@ +/* + * This file is part of Bisq. + * + * Bisq 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. + * + * Bisq 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 Bisq. If not, see . + */ + +package bisq.desktop.main.portfolio.pendingtrades.steps; + +import bisq.desktop.main.overlays.popups.Popup; + +import bisq.core.locale.Res; +import bisq.core.offer.Offer; +import bisq.core.trade.CanceledTradeState; +import bisq.core.trade.Trade; +import bisq.core.trade.TradeCancellationManager; +import bisq.core.util.coin.CoinFormatter; + +import javafx.beans.value.ChangeListener; + +import lombok.extern.slf4j.Slf4j; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Handles the UI aspects of cancelling a trade + * + * todo: handle dispute + */ +@Slf4j +public class HandleCancelTradeRequestPresentation { + private final Trade trade; + private final Offer offer; + private final TradeCancellationManager manager; + private final CoinFormatter formatter; + private ChangeListener canceledTradeStateListener; + + /////////////////////////////////////////////////////////////////////////////////////////// + // Constructor + /////////////////////////////////////////////////////////////////////////////////////////// + + public HandleCancelTradeRequestPresentation(Trade trade, + TradeCancellationManager manager, + CoinFormatter formatter) { + this.trade = trade; + offer = checkNotNull(trade.getOffer()); + this.manager = manager; + this.formatter = formatter; + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Life cycle + /////////////////////////////////////////////////////////////////////////////////////////// + + public void initialize() { + canceledTradeStateListener = (observable, oldValue, newValue) -> onCanceledTradeStateChanged(newValue); + } + + public void activate() { + trade.getCanceledTradeStateProperty().addListener(canceledTradeStateListener); + onCanceledTradeStateChanged(trade.getCanceledTradeStateProperty().get()); + } + + public void deactivate() { + if (canceledTradeStateListener != null) { + trade.getCanceledTradeStateProperty().removeListener(canceledTradeStateListener); + } + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // API + /////////////////////////////////////////////////////////////////////////////////////////// + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Private + /////////////////////////////////////////////////////////////////////////////////////////// + + private void acceptCancelTradeRequest() { + manager.acceptCancelTradeRequest(trade, + () -> { + }, errorMessage -> { + }); + } + + private void rejectCancelTradeRequest() { + manager.rejectCancelTradeRequest(trade, + () -> { + }, errorMessage -> { + }); + } + + + private void onCanceledTradeStateChanged(CanceledTradeState newValue) { + log.error("onCanceledTradeStateChanged {} {}", newValue, trade.getId()); + if (newValue == null) { + return; + } + switch (newValue) { + case REQUEST_MSG_SENT: + break; + case REQUEST_MSG_ARRIVED: + break; + case REQUEST_MSG_IN_MAILBOX: + break; + case REQUEST_MSG_SEND_FAILED: + break; + case RECEIVED_CANCEL_REQUEST: + new Popup().width(850) + .attention(Res.get("portfolio.pending.receivedCancelTradeRequestPopup", + formatter.formatCoinWithCode(trade.getTradeAmount()), + formatter.formatCoinWithCode(manager.getDefaultSecDepositOfAcceptingTrader(trade)), + formatter.formatCoinWithCode(manager.getLostSecDepositOfRequestingTrader(trade)))) + .actionButtonText(Res.get("shared.accept")) + .onAction(this::acceptCancelTradeRequest) + .secondaryActionButtonText(Res.get("shared.reject")) + .onSecondaryAction(this::rejectCancelTradeRequest) + .closeButtonText(Res.get("portfolio.pending.doNotDecideYet")) + .show(); + break; + case RECEIVED_ACCEPTED_MSG: + break; + case PAYOUT_TX_PUBLISHED: + break; + case PAYOUT_TX_PUBLISHED_MSG_SENT: + break; + case PAYOUT_TX_PUBLISHED_MSG_ARRIVED: + break; + case PAYOUT_TX_PUBLISHED_MSG_IN_MAILBOX: + break; + case PAYOUT_TX_PUBLISHED_MSG_SEND_FAILED: + break; + case PAYOUT_TX_SEEN_IN_NETWORK: + break; + case REQUEST_CANCELED_MSG_SENT: + break; + case REQUEST_CANCELED_MSG_ARRIVED: + break; + case REQUEST_CANCELED_MSG_IN_MAILBOX: + break; + case REQUEST_CANCELED_MSG_SEND_FAILED: + break; + case RECEIVED_REJECTED_MSG: + break; + } + } +} diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/RequestCancelTradePresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/RequestCancelTradePresentation.java new file mode 100644 index 00000000000..8cd4503b029 --- /dev/null +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/RequestCancelTradePresentation.java @@ -0,0 +1,192 @@ +/* + * This file is part of Bisq. + * + * Bisq 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. + * + * Bisq 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 Bisq. If not, see . + */ + +package bisq.desktop.main.portfolio.pendingtrades.steps; + +import bisq.desktop.components.AutoTooltipButton; +import bisq.desktop.components.BusyAnimation; +import bisq.desktop.main.overlays.popups.Popup; + +import bisq.core.locale.Res; +import bisq.core.offer.Offer; +import bisq.core.trade.CanceledTradeState; +import bisq.core.trade.Trade; +import bisq.core.trade.TradeCancellationManager; +import bisq.core.util.coin.CoinFormatter; + +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.layout.HBox; + +import javafx.beans.value.ChangeListener; + +import lombok.extern.slf4j.Slf4j; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Handles the UI aspects of cancelling a trade + * + * todo: handle dispute + */ +@Slf4j +public class RequestCancelTradePresentation { + private final Trade trade; + private final Offer offer; + private final TradeCancellationManager manager; + private final CoinFormatter formatter; + private Button cancelTradeButton; + private Label msgSentStatusLabel; + private BusyAnimation msgSentBusyAnimation; + private ChangeListener canceledTradeStateListener; + + /////////////////////////////////////////////////////////////////////////////////////////// + // Constructor + /////////////////////////////////////////////////////////////////////////////////////////// + + public RequestCancelTradePresentation(Trade trade, + TradeCancellationManager manager, + CoinFormatter formatter) { + this.trade = trade; + offer = checkNotNull(trade.getOffer()); + this.manager = manager; + this.formatter = formatter; + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Life cycle + /////////////////////////////////////////////////////////////////////////////////////////// + + public void initialize(HBox hBox, + BusyAnimation msgSentBusyAnimation, + Label msgSentStatusLabel) { + canceledTradeStateListener = (observable, oldValue, newValue) -> onCanceledTradeStateChanged(newValue); + + this.msgSentBusyAnimation = msgSentBusyAnimation; + this.msgSentStatusLabel = msgSentStatusLabel; + + cancelTradeButton = new AutoTooltipButton(Res.get("portfolio.pending.cancelTrade")); + cancelTradeButton.getStyleClass().add("action-button"); + cancelTradeButton.setOnAction(e -> showRequestCancelTradePopup()); + hBox.getChildren().add(1, cancelTradeButton); + } + + public void activate() { + trade.getCanceledTradeStateProperty().addListener(canceledTradeStateListener); + onCanceledTradeStateChanged(trade.getCanceledTradeStateProperty().get()); + } + + public void deactivate() { + if (canceledTradeStateListener != null) { + trade.getCanceledTradeStateProperty().removeListener(canceledTradeStateListener); + } + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // API + /////////////////////////////////////////////////////////////////////////////////////////// + + public void hideCancelButton() { + cancelTradeButton.setVisible(false); + cancelTradeButton.setManaged(false); + } + + public void setDisable(boolean isDisabled) { + //todo + // cancelTradeButton.setDisable(isDisabled); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Private + /////////////////////////////////////////////////////////////////////////////////////////// + + private void requestCancelTrade() { + manager.requestCancelTrade(trade, + () -> { + }, errorMessage -> { + }); + } + + private void showRequestCancelTradePopup() { + new Popup().width(850) + .attention(Res.get("portfolio.pending.requestCancelTradePopup", + formatter.formatCoinWithCode(manager.getSecurityDepositForRequester()))) + .onAction(this::requestCancelTrade) + .actionButtonText(Res.get("shared.yes")) + .closeButtonText(Res.get("shared.no")) + .show(); + } + + private void onCanceledTradeStateChanged(CanceledTradeState newValue) { + log.error("onCanceledTradeStateChanged {} {}", newValue, trade.getId()); + if (newValue == null) { + cancelTradeButton.setDisable(false); + + return; + } + + msgSentBusyAnimation.stop(); + msgSentStatusLabel.setText(""); + + cancelTradeButton.setDisable(true); + switch (newValue) { + case REQUEST_MSG_SENT: + msgSentBusyAnimation.play(); + msgSentStatusLabel.setText(Res.get("portfolio.pending.requestSent")); + break; + case REQUEST_MSG_ARRIVED: + msgSentStatusLabel.setText(Res.get("portfolio.pending.requestArrived")); + break; + case REQUEST_MSG_IN_MAILBOX: + msgSentStatusLabel.setText(Res.get("portfolio.pending.requestInMailbox")); + break; + case REQUEST_MSG_SEND_FAILED: + msgSentStatusLabel.setText(Res.get("portfolio.pending.requestFailed")); + break; + case RECEIVED_CANCEL_REQUEST: + break; + case RECEIVED_ACCEPTED_MSG: + break; + case PAYOUT_TX_PUBLISHED: + break; + case PAYOUT_TX_PUBLISHED_MSG_SENT: + break; + case PAYOUT_TX_PUBLISHED_MSG_ARRIVED: + break; + case PAYOUT_TX_PUBLISHED_MSG_IN_MAILBOX: + break; + case PAYOUT_TX_PUBLISHED_MSG_SEND_FAILED: + break; + case PAYOUT_TX_SEEN_IN_NETWORK: + break; + case REQUEST_CANCELED_MSG_SENT: + break; + case REQUEST_CANCELED_MSG_ARRIVED: + break; + case REQUEST_CANCELED_MSG_IN_MAILBOX: + break; + case REQUEST_CANCELED_MSG_SEND_FAILED: + break; + case RECEIVED_REJECTED_MSG: + msgSentStatusLabel.setText(Res.get("portfolio.pending.requestGotRejected")); + break; + } + } +} diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java index 40fd2b3eb1e..d4516bf1525 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java @@ -28,6 +28,7 @@ import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; +import bisq.core.offer.Offer; import bisq.core.support.dispute.Dispute; import bisq.core.support.dispute.DisputeResult; import bisq.core.trade.Contract; @@ -214,8 +215,9 @@ public void onUpdatedDataReceived() { model.clockWatcher.addListener(clockListener); - if (infoLabel != null) + if (infoLabel != null) { infoLabel.setText(getInfoText()); + } } public void deactivate() { @@ -656,10 +658,19 @@ private void updateTradePeriodState(Trade.TradePeriodState tradePeriodState) { } } + + /////////////////////////////////////////////////////////////////////////////////////////// + // Util + /////////////////////////////////////////////////////////////////////////////////////////// + protected boolean isDisputed() { return trade.getDisputeState() != Trade.DisputeState.NO_DISPUTE; } + protected Offer getOffer() { + return checkNotNull(trade.getOffer()); + } + /////////////////////////////////////////////////////////////////////////////////////////// // TradeDurationLimitInfo diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java index 8d49839c817..48460cd4fea 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java @@ -50,6 +50,7 @@ import bisq.desktop.main.overlays.popups.Popup; import bisq.desktop.main.overlays.windows.SetXmrTxKeyWindow; import bisq.desktop.main.portfolio.pendingtrades.PendingTradesViewModel; +import bisq.desktop.main.portfolio.pendingtrades.steps.RequestCancelTradePresentation; import bisq.desktop.main.portfolio.pendingtrades.steps.TradeStepView; import bisq.desktop.util.DisplayUtils; import bisq.desktop.util.Layout; @@ -104,6 +105,7 @@ public class BuyerStep2View extends TradeStepView { private BusyAnimation busyAnimation; private Subscription tradeStatePropertySubscription; private Timer timeoutTimer; + private RequestCancelTradePresentation requestCancelTradePresentation; /////////////////////////////////////////////////////////////////////////////////////////// @@ -112,6 +114,10 @@ public class BuyerStep2View extends TradeStepView { public BuyerStep2View(PendingTradesViewModel model) { super(model); + + requestCancelTradePresentation = new RequestCancelTradePresentation(trade, + model.dataModel.getTradeCancellationManager(), + model.getBtcFormatter()); } @@ -142,6 +148,7 @@ public void initialize() { Res.get("shared.reasonForPayment"), model.dataModel.getReference(), Layout.COMPACT_FIRST_ROW_AND_GROUP_DISTANCE); + Offer offer = getOffer(); switch (paymentMethodId) { case PaymentMethod.UPHOLD_ID: gridRow = UpholdForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload); @@ -213,8 +220,7 @@ public void initialize() { gridRow = HalCashForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload); break; case PaymentMethod.F2F_ID: - checkNotNull(model.dataModel.getTrade().getOffer(), "model.dataModel.getTrade().getOffer() must not be null"); - gridRow = F2FForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload, model.dataModel.getTrade().getOffer(), 0); + gridRow = F2FForm.addFormForBuyer(gridPane, gridRow, paymentAccountPayload, offer, 0); break; case PaymentMethod.BLOCK_CHAINS_ID: case PaymentMethod.BLOCK_CHAINS_INSTANT_ID: @@ -233,7 +239,6 @@ public void initialize() { Trade trade = model.getTrade(); if (trade != null && model.getUser().getPaymentAccounts() != null) { - Offer offer = trade.getOffer(); List possiblePaymentAccounts = PaymentAccountUtil.getPossiblePaymentAccounts(offer, model.getUser().getPaymentAccounts(), model.dataModel.getAccountAgeWitnessService()); PaymentAccountPayload buyersPaymentAccountPayload = model.dataModel.getBuyersPaymentAccountPayload(); @@ -260,6 +265,9 @@ public void initialize() { confirmButton.setOnAction(e -> onPaymentStarted()); busyAnimation = tuple3.second; statusLabel = tuple3.third; + HBox hBox = tuple3.fourth; + + requestCancelTradePresentation.initialize(hBox, busyAnimation, statusLabel); } @Override @@ -343,6 +351,8 @@ public void activate() { } confirmButton.setDisable(isDisputed()); + + requestCancelTradePresentation.activate(); } @Override @@ -358,6 +368,8 @@ public void deactivate() { tradeStatePropertySubscription.unsubscribe(); tradeStatePropertySubscription = null; } + + requestCancelTradePresentation.deactivate(); } @@ -518,6 +530,8 @@ private void showConfirmPaymentStartedPopup() { } private void confirmPaymentStarted() { + requestCancelTradePresentation.hideCancelButton(); + // confirmButton.setDisable(true); busyAnimation.play(); statusLabel.setText(Res.get("shared.sendingConfirmation")); @@ -638,5 +652,8 @@ private void showPopup() { @Override protected void updateConfirmButtonDisableState(boolean isDisabled) { confirmButton.setDisable(isDisabled); + + //TODO + requestCancelTradePresentation.setDisable(isDisabled); } } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep3View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep3View.java index c97f3d3d9c4..647eb69c2a1 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep3View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep3View.java @@ -19,6 +19,7 @@ import bisq.desktop.components.TextFieldWithIcon; import bisq.desktop.main.portfolio.pendingtrades.PendingTradesViewModel; +import bisq.desktop.main.portfolio.pendingtrades.steps.HandleCancelTradeRequestPresentation; import bisq.desktop.main.portfolio.pendingtrades.steps.TradeStepView; import bisq.desktop.util.Layout; @@ -37,6 +38,7 @@ public class BuyerStep3View extends TradeStepView { private final ChangeListener messageStateChangeListener; + private final HandleCancelTradeRequestPresentation handleCancelTradeRequestPresentation; private TextFieldWithIcon textFieldWithIcon; @@ -50,6 +52,10 @@ public BuyerStep3View(PendingTradesViewModel model) { messageStateChangeListener = (observable, oldValue, newValue) -> { updateMessageStateInfo(); }; + + handleCancelTradeRequestPresentation = new HandleCancelTradeRequestPresentation(trade, + model.dataModel.getTradeCancellationManager(), + model.getBtcFormatter()); } /////////////////////////////////////////////////////////////////////////////////////////// @@ -59,6 +65,8 @@ public BuyerStep3View(PendingTradesViewModel model) { @Override public void initialize() { super.initialize(); + + handleCancelTradeRequestPresentation.initialize(); } @Override @@ -68,12 +76,16 @@ public void activate() { model.getMessageStateProperty().addListener(messageStateChangeListener); updateMessageStateInfo(); + + handleCancelTradeRequestPresentation.activate(); } public void deactivate() { super.deactivate(); model.getMessageStateProperty().removeListener(messageStateChangeListener); + + handleCancelTradeRequestPresentation.deactivate(); } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep4View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep4View.java index bc7eb740ac6..69364c3fd10 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep4View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep4View.java @@ -185,7 +185,6 @@ private void onWithdrawal() { reviewWithdrawal(); } }); - } private void reviewWithdrawal() { diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java index e181990ebfa..2479633197d 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java @@ -19,6 +19,7 @@ import bisq.desktop.components.paymentmethods.F2FForm; import bisq.desktop.main.portfolio.pendingtrades.PendingTradesViewModel; +import bisq.desktop.main.portfolio.pendingtrades.steps.HandleCancelTradeRequestPresentation; import bisq.desktop.main.portfolio.pendingtrades.steps.TradeStepView; import bisq.desktop.util.Layout; @@ -44,6 +45,7 @@ public class SellerStep2View extends TradeStepView { private GridPane refreshButtonPane; private Timer timer; + private HandleCancelTradeRequestPresentation handleCancelTradeRequestPresentation; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor @@ -51,6 +53,10 @@ public class SellerStep2View extends TradeStepView { public SellerStep2View(PendingTradesViewModel model) { super(model); + + handleCancelTradeRequestPresentation = new HandleCancelTradeRequestPresentation(trade, + model.dataModel.getTradeCancellationManager(), + model.getBtcFormatter()); } @@ -72,18 +78,26 @@ public void initialize() { } addRefreshBlock(); + + handleCancelTradeRequestPresentation.initialize(); } @Override public void activate() { super.activate(); + activateRefreshButton(); + + handleCancelTradeRequestPresentation.activate(); } @Override public void deactivate() { super.deactivate(); + deActivateRefreshButtonTimer(); + + handleCancelTradeRequestPresentation.deactivate(); } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java index f296b2e98ac..3c8f5c03808 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java @@ -24,6 +24,7 @@ import bisq.desktop.components.indicator.TxConfidenceIndicator; import bisq.desktop.main.overlays.popups.Popup; import bisq.desktop.main.portfolio.pendingtrades.PendingTradesViewModel; +import bisq.desktop.main.portfolio.pendingtrades.steps.RequestCancelTradePresentation; import bisq.desktop.main.portfolio.pendingtrades.steps.TradeStepView; import bisq.desktop.util.DisplayUtils; import bisq.desktop.util.GUIUtil; @@ -90,6 +91,7 @@ public class SellerStep3View extends TradeStepView { private TxConfidenceIndicator assetTxConfidenceIndicator; @Nullable private ChangeListener proofResultListener; + private RequestCancelTradePresentation requestCancelTradePresentation; /////////////////////////////////////////////////////////////////////////////////////////// @@ -98,6 +100,10 @@ public class SellerStep3View extends TradeStepView { public SellerStep3View(PendingTradesViewModel model) { super(model); + + requestCancelTradePresentation = new RequestCancelTradePresentation(trade, + model.dataModel.getTradeCancellationManager(), + model.getBtcFormatter()); } /////////////////////////////////////////////////////////////////////////////////////////// @@ -218,6 +224,9 @@ public void initialize() { confirmButton.setOnAction(e -> onPaymentReceived()); busyAnimation = tuple.second; statusLabel = tuple.third; + HBox hBox = tuple.fourth; + + requestCancelTradePresentation.initialize(hBox, busyAnimation, statusLabel); } @Override @@ -286,6 +295,8 @@ public void activate() { applyAssetTxProofResult(trade.getAssetTxProofResult()); } + + requestCancelTradePresentation.activate(); } @Override @@ -306,6 +317,8 @@ public void deactivate() { if (isXmrTrade()) { trade.getAssetTxProofResultUpdateProperty().removeListener(proofResultListener); } + + requestCancelTradePresentation.deactivate(); } @@ -316,6 +329,9 @@ public void deactivate() { @Override protected void updateConfirmButtonDisableState(boolean isDisabled) { confirmButton.setDisable(isDisabled); + + //TODO + requestCancelTradePresentation.setDisable(isDisabled); } @@ -459,6 +475,8 @@ else if (paymentAccountPayload instanceof F2FAccountPayload) } private void confirmPaymentReceived() { + requestCancelTradePresentation.hideCancelButton(); + log.info("User pressed the [Confirm payment receipt] button for Trade {}", trade.getShortId()); busyAnimation.play(); statusLabel.setText(Res.get("shared.sendingConfirmation")); diff --git a/proto/src/main/proto/pb.proto b/proto/src/main/proto/pb.proto index 2f334e06e03..e97a6c50cda 100644 --- a/proto/src/main/proto/pb.proto +++ b/proto/src/main/proto/pb.proto @@ -78,6 +78,10 @@ message NetworkEnvelope { RefreshTradeStateRequest refresh_trade_state_request = 50; TraderSignedWitnessMessage trader_signed_witness_message = 51; + + RequestCancelTradeMessage request_cancel_trade_message = 52; + CancelTradeRequestAcceptedMessage cancel_trade_accepted_message = 53; + CancelTradeRequestRejectedMessage cancel_trade_rejected_message = 54; } } @@ -325,6 +329,25 @@ message MediatedPayoutTxSignatureMessage { NodeAddress sender_node_address = 4; } +message RequestCancelTradeMessage { + string uid = 1; + string trade_id = 3; + bytes tx_signature = 2; + NodeAddress sender_node_address = 4; +} + +message CancelTradeRequestAcceptedMessage { + string trade_id = 1; + bytes payout_tx = 2; + NodeAddress sender_node_address = 3; + string uid = 4; +} +message CancelTradeRequestRejectedMessage { + string trade_id = 1; + NodeAddress sender_node_address = 2; + string uid = 3; +} + message RefreshTradeStateRequest { string uid = 1; string trade_id = 2; @@ -1398,6 +1421,7 @@ message Trade { int64 last_refresh_request_date = 36; string counter_currency_extra_data = 37; string asset_tx_proof_result = 38; // name of AssetTxProofResult enum + string canceled_trade_state = 39; } message BuyerAsMakerTrade { @@ -1437,6 +1461,9 @@ message ProcessModel { bytes mediated_payout_tx_signature = 18; int64 buyer_payout_amount_from_mediation = 19; int64 seller_payout_amount_from_mediation = 20; + bytes canceled_trade_payout_tx_signature = 21; + int64 buyer_payout_amount_from_canceled_trade = 22; + int64 seller_payout_amount_from_canceled_trade = 23; } message TradingPeer { @@ -1455,6 +1482,7 @@ message TradingPeer { bytes account_age_witness_signature = 13; int64 current_date = 14; bytes mediated_payout_tx_signature = 15; + bytes canceled_trade_payout_tx_signature = 16; } /////////////////////////////////////////////////////////////////////////////////////////// From 5dd81cbf0564e243f173692fcc7d36cda3aa2cf4 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 9 Sep 2020 22:15:45 -0500 Subject: [PATCH 11/56] Refactor: Rename id to tradeId --- .../core/trade/protocol/tasks/SendMailboxMessageTask.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/SendMailboxMessageTask.java b/core/src/main/java/bisq/core/trade/protocol/tasks/SendMailboxMessageTask.java index 032e9d4e309..04a711e5ded 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/SendMailboxMessageTask.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/SendMailboxMessageTask.java @@ -34,7 +34,7 @@ public SendMailboxMessageTask(TaskRunner taskHandler, Trade trade) { super(taskHandler, trade); } - protected abstract TradeMessage getMessage(String id); + protected abstract TradeMessage getMessage(String tradeId); protected abstract void setStateSent(); @@ -49,8 +49,8 @@ protected void run() { try { runInterceptHook(); - String id = processModel.getOfferId(); - TradeMessage message = getMessage(id); + String tradeId = processModel.getOfferId(); + TradeMessage message = getMessage(tradeId); setStateSent(); NodeAddress peersNodeAddress = trade.getTradingPeerNodeAddress(); log.info("Send {} to peer {}. tradeId={}, uid={}", From d50d8257ac13eddafb6d809e9dea03427b6abae2 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 9 Sep 2020 22:18:08 -0500 Subject: [PATCH 12/56] Remove unused field --- .../pendingtrades/steps/RequestCancelTradePresentation.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/RequestCancelTradePresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/RequestCancelTradePresentation.java index 8cd4503b029..10767e5da3a 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/RequestCancelTradePresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/RequestCancelTradePresentation.java @@ -22,7 +22,6 @@ import bisq.desktop.main.overlays.popups.Popup; import bisq.core.locale.Res; -import bisq.core.offer.Offer; import bisq.core.trade.CanceledTradeState; import bisq.core.trade.Trade; import bisq.core.trade.TradeCancellationManager; @@ -36,8 +35,6 @@ import lombok.extern.slf4j.Slf4j; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Handles the UI aspects of cancelling a trade * @@ -46,7 +43,6 @@ @Slf4j public class RequestCancelTradePresentation { private final Trade trade; - private final Offer offer; private final TradeCancellationManager manager; private final CoinFormatter formatter; private Button cancelTradeButton; @@ -62,7 +58,6 @@ public RequestCancelTradePresentation(Trade trade, TradeCancellationManager manager, CoinFormatter formatter) { this.trade = trade; - offer = checkNotNull(trade.getOffer()); this.manager = manager; this.formatter = formatter; } From 25db77572e9ae1277584c22fde6b9f8eb99143ef Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 9 Sep 2020 22:34:26 -0500 Subject: [PATCH 13/56] Refactor: Rename CanceledTradeState to HandleCancelTradeRequestState We will separate state for requester and peer in the next commits --- ...e.java => HandleCancelTradeRequestState.java} | 6 ++++-- core/src/main/java/bisq/core/trade/Trade.java | 16 ++++++++-------- .../cancel/BroadcastCanceledTradePayoutTx.java | 4 ++-- ...ProcessCancelTradeRequestAcceptedMessage.java | 4 ++-- ...ProcessCancelTradeRequestRejectedMessage.java | 4 ++-- .../cancel/ProcessRequestCancelTradeMessage.java | 4 ++-- .../SendCancelTradeRequestAcceptedMessage.java | 10 +++++----- .../SendCancelTradeRequestRejectedMessage.java | 10 +++++----- .../cancel/SendRequestCancelTradeMessage.java | 10 +++++----- .../SetupCanceledTradePayoutTxListener.java | 4 ++-- .../HandleCancelTradeRequestPresentation.java | 6 +++--- .../steps/RequestCancelTradePresentation.java | 6 +++--- proto/src/main/proto/pb.proto | 2 +- 13 files changed, 44 insertions(+), 42 deletions(-) rename core/src/main/java/bisq/core/trade/{CanceledTradeState.java => HandleCancelTradeRequestState.java} (93%) diff --git a/core/src/main/java/bisq/core/trade/CanceledTradeState.java b/core/src/main/java/bisq/core/trade/HandleCancelTradeRequestState.java similarity index 93% rename from core/src/main/java/bisq/core/trade/CanceledTradeState.java rename to core/src/main/java/bisq/core/trade/HandleCancelTradeRequestState.java index 89ea9afbf3b..23efbcb08d9 100644 --- a/core/src/main/java/bisq/core/trade/CanceledTradeState.java +++ b/core/src/main/java/bisq/core/trade/HandleCancelTradeRequestState.java @@ -17,7 +17,9 @@ package bisq.core.trade; -public enum CanceledTradeState { +public enum HandleCancelTradeRequestState { + + // Requester REQUEST_MSG_SENT, REQUEST_MSG_ARRIVED, REQUEST_MSG_IN_MAILBOX, @@ -46,5 +48,5 @@ public enum CanceledTradeState { REQUEST_CANCELED_MSG_SEND_FAILED, // Requester received reject msg - RECEIVED_REJECTED_MSG, + RECEIVED_REJECTED_MSG; } diff --git a/core/src/main/java/bisq/core/trade/Trade.java b/core/src/main/java/bisq/core/trade/Trade.java index 16acf8c6f26..7a4b2b7c18f 100644 --- a/core/src/main/java/bisq/core/trade/Trade.java +++ b/core/src/main/java/bisq/core/trade/Trade.java @@ -452,9 +452,9 @@ public static protobuf.Trade.TradePeriodState toProtoMessage(Trade.TradePeriodSt @Getter // Added at v1.3.9 - public CanceledTradeState canceledTradeState; + public HandleCancelTradeRequestState handleCancelTradeRequestState; @Getter - transient final private ObjectProperty canceledTradeStateProperty = new SimpleObjectProperty<>(); + transient final private ObjectProperty canceledTradeStateProperty = new SimpleObjectProperty<>(); /////////////////////////////////////////////////////////////////////////////////////////// @@ -569,7 +569,7 @@ public Message toProtoMessage() { Optional.ofNullable(delayedPayoutTxBytes).ifPresent(e -> builder.setDelayedPayoutTxBytes(ByteString.copyFrom(delayedPayoutTxBytes))); Optional.ofNullable(counterCurrencyExtraData).ifPresent(e -> builder.setCounterCurrencyExtraData(counterCurrencyExtraData)); Optional.ofNullable(assetTxProofResult).ifPresent(e -> builder.setAssetTxProofResult(assetTxProofResult.name())); - Optional.ofNullable(canceledTradeState).ifPresent(e -> builder.setCanceledTradeState(canceledTradeState.name())); + Optional.ofNullable(handleCancelTradeRequestState).ifPresent(e -> builder.setHandleCancelTradeRequestState(handleCancelTradeRequestState.name())); return builder.build(); } @@ -612,7 +612,7 @@ public static Trade fromProto(Trade trade, protobuf.Trade proto, CoreProtoResolv } trade.setAssetTxProofResult(persistedAssetTxProofResult); - trade.setCanceledTradeState(ProtoUtil.enumFromProto(CanceledTradeState.class, proto.getCanceledTradeState())); + trade.setHandleCancelTradeRequestState(ProtoUtil.enumFromProto(HandleCancelTradeRequestState.class, proto.getHandleCancelTradeRequestState())); trade.chatMessages.addAll(proto.getChatMessageList().stream() .map(ChatMessage::fromPayloadProto) @@ -902,9 +902,9 @@ public void setAssetTxProofResult(@Nullable AssetTxProofResult assetTxProofResul persist(); } - public void setCanceledTradeState(CanceledTradeState canceledTradeState) { - this.canceledTradeState = canceledTradeState; - canceledTradeStateProperty.set(canceledTradeState); + public void setHandleCancelTradeRequestState(HandleCancelTradeRequestState handleCancelTradeRequestState) { + this.handleCancelTradeRequestState = handleCancelTradeRequestState; + canceledTradeStateProperty.set(handleCancelTradeRequestState); persist(); } @@ -1244,7 +1244,7 @@ public String toString() { ",\n refundResultState=" + refundResultState + ",\n refundResultStateProperty=" + refundResultStateProperty + ",\n lastRefreshRequestDate=" + lastRefreshRequestDate + - ",\n canceledTradeState=" + canceledTradeState + + ",\n canceledTradeState=" + handleCancelTradeRequestState + "\n}"; } } diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java index c889e889132..9e160f20d96 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java @@ -17,7 +17,7 @@ package bisq.core.trade.protocol.tasks.cancel; -import bisq.core.trade.CanceledTradeState; +import bisq.core.trade.HandleCancelTradeRequestState; import bisq.core.trade.Trade; import bisq.core.trade.protocol.tasks.BroadcastPayoutTx; @@ -45,6 +45,6 @@ protected void run() { @Override protected void setState() { - trade.setCanceledTradeState(CanceledTradeState.PAYOUT_TX_PUBLISHED); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.PAYOUT_TX_PUBLISHED); } } diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java index 763e26ee9ee..aa489a0f468 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java @@ -20,7 +20,7 @@ import bisq.core.btc.model.AddressEntry; import bisq.core.btc.wallet.BtcWalletService; import bisq.core.btc.wallet.WalletService; -import bisq.core.trade.CanceledTradeState; +import bisq.core.trade.HandleCancelTradeRequestState; import bisq.core.trade.Trade; import bisq.core.trade.messages.CancelTradeRequestAcceptedMessage; import bisq.core.trade.protocol.tasks.TradeTask; @@ -60,7 +60,7 @@ protected void run() { trade.setPayoutTx(committedCanceledTradePayoutTx); BtcWalletService.printTx("CanceledTradePayoutTx received from peer", committedCanceledTradePayoutTx); - trade.setCanceledTradeState(CanceledTradeState.RECEIVED_ACCEPTED_MSG); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.RECEIVED_ACCEPTED_MSG); // We need to delay that call as we might get executed at startup after mailbox messages are // applied where we iterate over our pending trades. The closeCanceledTrade method would remove diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java index 0e1705a3a5f..1ba2183af39 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java @@ -17,7 +17,7 @@ package bisq.core.trade.protocol.tasks.cancel; -import bisq.core.trade.CanceledTradeState; +import bisq.core.trade.HandleCancelTradeRequestState; import bisq.core.trade.Trade; import bisq.core.trade.messages.CancelTradeRequestRejectedMessage; import bisq.core.trade.protocol.tasks.TradeTask; @@ -46,7 +46,7 @@ protected void run() { // update to the latest peer address of our peer if the message is correct trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress()); - trade.setCanceledTradeState(CanceledTradeState.RECEIVED_REJECTED_MSG); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.RECEIVED_REJECTED_MSG); processModel.removeMailboxMessageAfterProcessing(trade); complete(); } catch (Throwable t) { diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java index dffa4353c26..f9f30d67af7 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java @@ -17,7 +17,7 @@ package bisq.core.trade.protocol.tasks.cancel; -import bisq.core.trade.CanceledTradeState; +import bisq.core.trade.HandleCancelTradeRequestState; import bisq.core.trade.Trade; import bisq.core.trade.messages.RequestCancelTradeMessage; import bisq.core.trade.protocol.tasks.TradeTask; @@ -50,7 +50,7 @@ protected void run() { trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress()); processModel.removeMailboxMessageAfterProcessing(trade); - trade.setCanceledTradeState(CanceledTradeState.RECEIVED_CANCEL_REQUEST); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.RECEIVED_CANCEL_REQUEST); complete(); } catch (Throwable t) { diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java index 72998bbef73..b9c89000513 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java @@ -17,7 +17,7 @@ package bisq.core.trade.protocol.tasks.cancel; -import bisq.core.trade.CanceledTradeState; +import bisq.core.trade.HandleCancelTradeRequestState; import bisq.core.trade.Trade; import bisq.core.trade.messages.CancelTradeRequestAcceptedMessage; import bisq.core.trade.messages.TradeMessage; @@ -54,22 +54,22 @@ protected TradeMessage getMessage(String id) { @Override protected void setStateSent() { - trade.setCanceledTradeState(CanceledTradeState.PAYOUT_TX_PUBLISHED_MSG_SENT); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.PAYOUT_TX_PUBLISHED_MSG_SENT); } @Override protected void setStateArrived() { - trade.setCanceledTradeState(CanceledTradeState.PAYOUT_TX_PUBLISHED_MSG_ARRIVED); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.PAYOUT_TX_PUBLISHED_MSG_ARRIVED); } @Override protected void setStateStoredInMailbox() { - trade.setCanceledTradeState(CanceledTradeState.PAYOUT_TX_PUBLISHED_MSG_IN_MAILBOX); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.PAYOUT_TX_PUBLISHED_MSG_IN_MAILBOX); } @Override protected void setStateFault() { - trade.setCanceledTradeState(CanceledTradeState.PAYOUT_TX_PUBLISHED_MSG_SEND_FAILED); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.PAYOUT_TX_PUBLISHED_MSG_SEND_FAILED); } @Override diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java index a28174fe781..42594e9efa6 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java @@ -17,7 +17,7 @@ package bisq.core.trade.protocol.tasks.cancel; -import bisq.core.trade.CanceledTradeState; +import bisq.core.trade.HandleCancelTradeRequestState; import bisq.core.trade.Trade; import bisq.core.trade.messages.CancelTradeRequestRejectedMessage; import bisq.core.trade.messages.TradeMessage; @@ -48,22 +48,22 @@ protected TradeMessage getMessage(String id) { @Override protected void setStateSent() { - trade.setCanceledTradeState(CanceledTradeState.REQUEST_CANCELED_MSG_SENT); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_CANCELED_MSG_SENT); } @Override protected void setStateArrived() { - trade.setCanceledTradeState(CanceledTradeState.REQUEST_CANCELED_MSG_ARRIVED); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_CANCELED_MSG_ARRIVED); } @Override protected void setStateStoredInMailbox() { - trade.setCanceledTradeState(CanceledTradeState.REQUEST_CANCELED_MSG_IN_MAILBOX); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_CANCELED_MSG_IN_MAILBOX); } @Override protected void setStateFault() { - trade.setCanceledTradeState(CanceledTradeState.REQUEST_CANCELED_MSG_SEND_FAILED); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_CANCELED_MSG_SEND_FAILED); } @Override diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java index d47a077c421..f0ff89e4ab3 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java @@ -17,8 +17,8 @@ package bisq.core.trade.protocol.tasks.cancel; -import bisq.core.trade.CanceledTradeState; import bisq.core.trade.Contract; +import bisq.core.trade.HandleCancelTradeRequestState; import bisq.core.trade.Trade; import bisq.core.trade.messages.RequestCancelTradeMessage; import bisq.core.trade.messages.TradeMessage; @@ -61,22 +61,22 @@ protected TradeMessage getMessage(String id) { @Override protected void setStateSent() { - trade.setCanceledTradeState(CanceledTradeState.REQUEST_MSG_SENT); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_MSG_SENT); } @Override protected void setStateArrived() { - trade.setCanceledTradeState(CanceledTradeState.REQUEST_MSG_ARRIVED); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_MSG_ARRIVED); } @Override protected void setStateStoredInMailbox() { - trade.setCanceledTradeState(CanceledTradeState.REQUEST_MSG_IN_MAILBOX); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_MSG_IN_MAILBOX); } @Override protected void setStateFault() { - trade.setCanceledTradeState(CanceledTradeState.REQUEST_MSG_SEND_FAILED); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_MSG_SEND_FAILED); } @Override diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java index 71bb02fbf10..989aef55aeb 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java @@ -17,7 +17,7 @@ package bisq.core.trade.protocol.tasks.cancel; -import bisq.core.trade.CanceledTradeState; +import bisq.core.trade.HandleCancelTradeRequestState; import bisq.core.trade.Trade; import bisq.core.trade.protocol.tasks.SetupPayoutTxListener; @@ -46,7 +46,7 @@ protected void run() { @Override protected void setState() { - trade.setCanceledTradeState(CanceledTradeState.PAYOUT_TX_SEEN_IN_NETWORK); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.PAYOUT_TX_SEEN_IN_NETWORK); if (trade.getPayoutTx() != null) { processModel.getTradeManager().closeCanceledTrade(trade); } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/HandleCancelTradeRequestPresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/HandleCancelTradeRequestPresentation.java index 4fef418e7bf..724c928620a 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/HandleCancelTradeRequestPresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/HandleCancelTradeRequestPresentation.java @@ -21,7 +21,7 @@ import bisq.core.locale.Res; import bisq.core.offer.Offer; -import bisq.core.trade.CanceledTradeState; +import bisq.core.trade.HandleCancelTradeRequestState; import bisq.core.trade.Trade; import bisq.core.trade.TradeCancellationManager; import bisq.core.util.coin.CoinFormatter; @@ -43,7 +43,7 @@ public class HandleCancelTradeRequestPresentation { private final Offer offer; private final TradeCancellationManager manager; private final CoinFormatter formatter; - private ChangeListener canceledTradeStateListener; + private ChangeListener canceledTradeStateListener; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor @@ -103,7 +103,7 @@ private void rejectCancelTradeRequest() { } - private void onCanceledTradeStateChanged(CanceledTradeState newValue) { + private void onCanceledTradeStateChanged(HandleCancelTradeRequestState newValue) { log.error("onCanceledTradeStateChanged {} {}", newValue, trade.getId()); if (newValue == null) { return; diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/RequestCancelTradePresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/RequestCancelTradePresentation.java index 10767e5da3a..d9251bc6a21 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/RequestCancelTradePresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/RequestCancelTradePresentation.java @@ -22,7 +22,7 @@ import bisq.desktop.main.overlays.popups.Popup; import bisq.core.locale.Res; -import bisq.core.trade.CanceledTradeState; +import bisq.core.trade.HandleCancelTradeRequestState; import bisq.core.trade.Trade; import bisq.core.trade.TradeCancellationManager; import bisq.core.util.coin.CoinFormatter; @@ -48,7 +48,7 @@ public class RequestCancelTradePresentation { private Button cancelTradeButton; private Label msgSentStatusLabel; private BusyAnimation msgSentBusyAnimation; - private ChangeListener canceledTradeStateListener; + private ChangeListener canceledTradeStateListener; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor @@ -129,7 +129,7 @@ private void showRequestCancelTradePopup() { .show(); } - private void onCanceledTradeStateChanged(CanceledTradeState newValue) { + private void onCanceledTradeStateChanged(HandleCancelTradeRequestState newValue) { log.error("onCanceledTradeStateChanged {} {}", newValue, trade.getId()); if (newValue == null) { cancelTradeButton.setDisable(false); diff --git a/proto/src/main/proto/pb.proto b/proto/src/main/proto/pb.proto index e97a6c50cda..9d7746b66c7 100644 --- a/proto/src/main/proto/pb.proto +++ b/proto/src/main/proto/pb.proto @@ -1421,7 +1421,7 @@ message Trade { int64 last_refresh_request_date = 36; string counter_currency_extra_data = 37; string asset_tx_proof_result = 38; // name of AssetTxProofResult enum - string canceled_trade_state = 39; + string handle_cancel_trade_request_state = 39; } message BuyerAsMakerTrade { From 68add4193546d55efbab33597a7393597e42a284 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 9 Sep 2020 22:40:00 -0500 Subject: [PATCH 14/56] Add RequestCancelTradeState WIP - will separate in next commits states --- .../core/trade/RequestCancelTradeState.java | 53 +++++++++++++++++++ core/src/main/java/bisq/core/trade/Trade.java | 20 +++++-- .../HandleCancelTradeRequestPresentation.java | 6 +-- .../steps/RequestCancelTradePresentation.java | 6 +-- proto/src/main/proto/pb.proto | 1 + 5 files changed, 77 insertions(+), 9 deletions(-) create mode 100644 core/src/main/java/bisq/core/trade/RequestCancelTradeState.java diff --git a/core/src/main/java/bisq/core/trade/RequestCancelTradeState.java b/core/src/main/java/bisq/core/trade/RequestCancelTradeState.java new file mode 100644 index 00000000000..58eb8b4ec51 --- /dev/null +++ b/core/src/main/java/bisq/core/trade/RequestCancelTradeState.java @@ -0,0 +1,53 @@ +/* + * This file is part of Bisq. + * + * Bisq 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. + * + * Bisq 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 Bisq. If not, see . + */ + +package bisq.core.trade; + +public enum RequestCancelTradeState { + + + // Requester + REQUEST_MSG_SENT, + REQUEST_MSG_ARRIVED, + REQUEST_MSG_IN_MAILBOX, + REQUEST_MSG_SEND_FAILED, + + // Peer received request + RECEIVED_CANCEL_REQUEST, + + // Requester received reject msg + RECEIVED_ACCEPTED_MSG, + + // Peer accepted + PAYOUT_TX_PUBLISHED, + PAYOUT_TX_PUBLISHED_MSG_SENT, + PAYOUT_TX_PUBLISHED_MSG_ARRIVED, + PAYOUT_TX_PUBLISHED_MSG_IN_MAILBOX, + PAYOUT_TX_PUBLISHED_MSG_SEND_FAILED, + + // Request sees tx + PAYOUT_TX_SEEN_IN_NETWORK, + + // Peer rejected + REQUEST_CANCELED_MSG_SENT, + REQUEST_CANCELED_MSG_ARRIVED, + REQUEST_CANCELED_MSG_IN_MAILBOX, + REQUEST_CANCELED_MSG_SEND_FAILED, + + // Requester received reject msg + RECEIVED_REJECTED_MSG; +} diff --git a/core/src/main/java/bisq/core/trade/Trade.java b/core/src/main/java/bisq/core/trade/Trade.java index 7a4b2b7c18f..5916aaabb2a 100644 --- a/core/src/main/java/bisq/core/trade/Trade.java +++ b/core/src/main/java/bisq/core/trade/Trade.java @@ -454,7 +454,12 @@ public static protobuf.Trade.TradePeriodState toProtoMessage(Trade.TradePeriodSt // Added at v1.3.9 public HandleCancelTradeRequestState handleCancelTradeRequestState; @Getter - transient final private ObjectProperty canceledTradeStateProperty = new SimpleObjectProperty<>(); + transient final private ObjectProperty handleCancelTradeRequestStateProperty = new SimpleObjectProperty<>(); + + @Getter + public RequestCancelTradeState requestCancelTradeState; + @Getter + transient final private ObjectProperty requestCancelTradeStateProperty = new SimpleObjectProperty<>(); /////////////////////////////////////////////////////////////////////////////////////////// @@ -570,6 +575,7 @@ public Message toProtoMessage() { Optional.ofNullable(counterCurrencyExtraData).ifPresent(e -> builder.setCounterCurrencyExtraData(counterCurrencyExtraData)); Optional.ofNullable(assetTxProofResult).ifPresent(e -> builder.setAssetTxProofResult(assetTxProofResult.name())); Optional.ofNullable(handleCancelTradeRequestState).ifPresent(e -> builder.setHandleCancelTradeRequestState(handleCancelTradeRequestState.name())); + Optional.ofNullable(requestCancelTradeState).ifPresent(e -> builder.setRequestCancelTradeState(requestCancelTradeState.name())); return builder.build(); } @@ -613,6 +619,7 @@ public static Trade fromProto(Trade trade, protobuf.Trade proto, CoreProtoResolv trade.setAssetTxProofResult(persistedAssetTxProofResult); trade.setHandleCancelTradeRequestState(ProtoUtil.enumFromProto(HandleCancelTradeRequestState.class, proto.getHandleCancelTradeRequestState())); + trade.setRequestCancelTradeState(ProtoUtil.enumFromProto(RequestCancelTradeState.class, proto.getRequestCancelTradeState())); trade.chatMessages.addAll(proto.getChatMessageList().stream() .map(ChatMessage::fromPayloadProto) @@ -904,7 +911,13 @@ public void setAssetTxProofResult(@Nullable AssetTxProofResult assetTxProofResul public void setHandleCancelTradeRequestState(HandleCancelTradeRequestState handleCancelTradeRequestState) { this.handleCancelTradeRequestState = handleCancelTradeRequestState; - canceledTradeStateProperty.set(handleCancelTradeRequestState); + handleCancelTradeRequestStateProperty.set(handleCancelTradeRequestState); + persist(); + } + + public void setRequestCancelTradeState(RequestCancelTradeState requestCancelTradeState) { + this.requestCancelTradeState = requestCancelTradeState; + requestCancelTradeStateProperty.set(requestCancelTradeState); persist(); } @@ -1244,7 +1257,8 @@ public String toString() { ",\n refundResultState=" + refundResultState + ",\n refundResultStateProperty=" + refundResultStateProperty + ",\n lastRefreshRequestDate=" + lastRefreshRequestDate + - ",\n canceledTradeState=" + handleCancelTradeRequestState + + ",\n handleCancelTradeRequestState=" + handleCancelTradeRequestState + + ",\n requestCancelTradeState=" + requestCancelTradeState + "\n}"; } } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/HandleCancelTradeRequestPresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/HandleCancelTradeRequestPresentation.java index 724c928620a..d18053af9bd 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/HandleCancelTradeRequestPresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/HandleCancelTradeRequestPresentation.java @@ -68,13 +68,13 @@ public void initialize() { } public void activate() { - trade.getCanceledTradeStateProperty().addListener(canceledTradeStateListener); - onCanceledTradeStateChanged(trade.getCanceledTradeStateProperty().get()); + trade.getHandleCancelTradeRequestStateProperty().addListener(canceledTradeStateListener); + onCanceledTradeStateChanged(trade.getHandleCancelTradeRequestStateProperty().get()); } public void deactivate() { if (canceledTradeStateListener != null) { - trade.getCanceledTradeStateProperty().removeListener(canceledTradeStateListener); + trade.getHandleCancelTradeRequestStateProperty().removeListener(canceledTradeStateListener); } } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/RequestCancelTradePresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/RequestCancelTradePresentation.java index d9251bc6a21..fadf2ac1ccf 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/RequestCancelTradePresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/RequestCancelTradePresentation.java @@ -82,13 +82,13 @@ public void initialize(HBox hBox, } public void activate() { - trade.getCanceledTradeStateProperty().addListener(canceledTradeStateListener); - onCanceledTradeStateChanged(trade.getCanceledTradeStateProperty().get()); + trade.getHandleCancelTradeRequestStateProperty().addListener(canceledTradeStateListener); + onCanceledTradeStateChanged(trade.getHandleCancelTradeRequestStateProperty().get()); } public void deactivate() { if (canceledTradeStateListener != null) { - trade.getCanceledTradeStateProperty().removeListener(canceledTradeStateListener); + trade.getHandleCancelTradeRequestStateProperty().removeListener(canceledTradeStateListener); } } diff --git a/proto/src/main/proto/pb.proto b/proto/src/main/proto/pb.proto index 9d7746b66c7..5a517a1ed87 100644 --- a/proto/src/main/proto/pb.proto +++ b/proto/src/main/proto/pb.proto @@ -1422,6 +1422,7 @@ message Trade { string counter_currency_extra_data = 37; string asset_tx_proof_result = 38; // name of AssetTxProofResult enum string handle_cancel_trade_request_state = 39; + string request_cancel_trade_state = 40; } message BuyerAsMakerTrade { From b28f50751ce023b7f00c790ec86b3502a0bdcb5b Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 9 Sep 2020 23:14:35 -0500 Subject: [PATCH 15/56] Separate states completed --- .../trade/HandleCancelTradeRequestState.java | 43 +++------- .../core/trade/RequestCancelTradeState.java | 26 +----- .../core/trade/TradeCancellationManager.java | 12 +-- .../java/bisq/core/trade/TradeManager.java | 2 + .../core/trade/protocol/TradeProtocol.java | 6 ++ .../BroadcastCanceledTradePayoutTx.java | 2 +- ...cessCancelTradeRequestAcceptedMessage.java | 7 +- ...cessCancelTradeRequestRejectedMessage.java | 4 +- .../ProcessRequestCancelTradeMessage.java | 2 +- ...SendCancelTradeRequestAcceptedMessage.java | 8 +- ...SendCancelTradeRequestRejectedMessage.java | 8 +- .../cancel/SendRequestCancelTradeMessage.java | 10 +-- .../SetupCanceledTradePayoutTxListener.java | 11 ++- .../resources/i18n/displayStrings.properties | 15 ++-- .../HandleCancelTradeRequestPresentation.java | 75 +++++++---------- .../steps/RequestCancelTradePresentation.java | 84 ++++++++----------- 16 files changed, 130 insertions(+), 185 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/HandleCancelTradeRequestState.java b/core/src/main/java/bisq/core/trade/HandleCancelTradeRequestState.java index 23efbcb08d9..9fd5bae679b 100644 --- a/core/src/main/java/bisq/core/trade/HandleCancelTradeRequestState.java +++ b/core/src/main/java/bisq/core/trade/HandleCancelTradeRequestState.java @@ -18,35 +18,16 @@ package bisq.core.trade; public enum HandleCancelTradeRequestState { - - // Requester - REQUEST_MSG_SENT, - REQUEST_MSG_ARRIVED, - REQUEST_MSG_IN_MAILBOX, - REQUEST_MSG_SEND_FAILED, - - // Peer received request - RECEIVED_CANCEL_REQUEST, - - // Requester received reject msg - RECEIVED_ACCEPTED_MSG, - - // Peer accepted - PAYOUT_TX_PUBLISHED, - PAYOUT_TX_PUBLISHED_MSG_SENT, - PAYOUT_TX_PUBLISHED_MSG_ARRIVED, - PAYOUT_TX_PUBLISHED_MSG_IN_MAILBOX, - PAYOUT_TX_PUBLISHED_MSG_SEND_FAILED, - - // Request sees tx - PAYOUT_TX_SEEN_IN_NETWORK, - - // Peer rejected - REQUEST_CANCELED_MSG_SENT, - REQUEST_CANCELED_MSG_ARRIVED, - REQUEST_CANCELED_MSG_IN_MAILBOX, - REQUEST_CANCELED_MSG_SEND_FAILED, - - // Requester received reject msg - RECEIVED_REJECTED_MSG; + RECEIVED_REQUEST, + + REQUEST_ACCEPTED_PAYOUT_TX_PUBLISHED, + REQUEST_ACCEPTED_MSG_SENT, + REQUEST_ACCEPTED_MSG_ARRIVED, + REQUEST_ACCEPTED_MSG_IN_MAILBOX, + REQUEST_ACCEPTED_MSG_SEND_FAILED, + + REQUEST_REJECTED_MSG_SENT, + REQUEST_REJECTED_MSG_ARRIVED, + REQUEST_REJECTED_MSG_IN_MAILBOX, + REQUEST_REJECTED_MSG_SEND_FAILED } diff --git a/core/src/main/java/bisq/core/trade/RequestCancelTradeState.java b/core/src/main/java/bisq/core/trade/RequestCancelTradeState.java index 58eb8b4ec51..b054aef1f21 100644 --- a/core/src/main/java/bisq/core/trade/RequestCancelTradeState.java +++ b/core/src/main/java/bisq/core/trade/RequestCancelTradeState.java @@ -18,36 +18,12 @@ package bisq.core.trade; public enum RequestCancelTradeState { - - - // Requester REQUEST_MSG_SENT, REQUEST_MSG_ARRIVED, REQUEST_MSG_IN_MAILBOX, REQUEST_MSG_SEND_FAILED, - // Peer received request - RECEIVED_CANCEL_REQUEST, - - // Requester received reject msg RECEIVED_ACCEPTED_MSG, - - // Peer accepted - PAYOUT_TX_PUBLISHED, - PAYOUT_TX_PUBLISHED_MSG_SENT, - PAYOUT_TX_PUBLISHED_MSG_ARRIVED, - PAYOUT_TX_PUBLISHED_MSG_IN_MAILBOX, - PAYOUT_TX_PUBLISHED_MSG_SEND_FAILED, - - // Request sees tx PAYOUT_TX_SEEN_IN_NETWORK, - - // Peer rejected - REQUEST_CANCELED_MSG_SENT, - REQUEST_CANCELED_MSG_ARRIVED, - REQUEST_CANCELED_MSG_IN_MAILBOX, - REQUEST_CANCELED_MSG_SEND_FAILED, - - // Requester received reject msg - RECEIVED_REJECTED_MSG; + RECEIVED_REJECTED_MSG } diff --git a/core/src/main/java/bisq/core/trade/TradeCancellationManager.java b/core/src/main/java/bisq/core/trade/TradeCancellationManager.java index 4b63a5ea419..65749af58cc 100644 --- a/core/src/main/java/bisq/core/trade/TradeCancellationManager.java +++ b/core/src/main/java/bisq/core/trade/TradeCancellationManager.java @@ -90,9 +90,9 @@ public Coin getLostSecDepositOfRequestingTrader(Trade trade) { return getTotalSecDepositForAcceptingTrader(offer).subtract(getDefaultSecDepositOfAcceptingTrader(trade)); } - public void acceptCancelTradeRequest(Trade trade, - ResultHandler resultHandler, - ErrorMessageHandler errorMessageHandler) { + public void acceptRequest(Trade trade, + ResultHandler resultHandler, + ErrorMessageHandler errorMessageHandler) { ProcessModel processModel = trade.getProcessModel(); Offer offer = checkNotNull(trade.getOffer()); Coin secDepositOfRequester = getSecurityDepositForRequester(); @@ -109,9 +109,9 @@ public void acceptCancelTradeRequest(Trade trade, trade.getTradeProtocol().onAcceptCancelTradeRequest(resultHandler, errorMessageHandler); } - public void rejectCancelTradeRequest(Trade trade, - ResultHandler resultHandler, - ErrorMessageHandler errorMessageHandler) { + public void rejectRequest(Trade trade, + ResultHandler resultHandler, + ErrorMessageHandler errorMessageHandler) { trade.getTradeProtocol().onRejectCancelTradeRequest(resultHandler, errorMessageHandler); } } diff --git a/core/src/main/java/bisq/core/trade/TradeManager.java b/core/src/main/java/bisq/core/trade/TradeManager.java index 3cc270a6b86..2c2a872cbbd 100644 --- a/core/src/main/java/bisq/core/trade/TradeManager.java +++ b/core/src/main/java/bisq/core/trade/TradeManager.java @@ -679,6 +679,8 @@ private void removeTrade(Trade trade) { public void closeCanceledTrade(Trade trade) { addTradeToClosedTrades(trade); + + btcWalletService.swapTradeEntryToAvailableEntry(trade.getId(), AddressEntry.Context.MULTI_SIG); btcWalletService.swapTradeEntryToAvailableEntry(trade.getId(), AddressEntry.Context.TRADE_PAYOUT); } diff --git a/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java b/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java index 9b340dbb994..b7606aa1f10 100644 --- a/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java @@ -442,6 +442,12 @@ protected void doApplyMailboxTradeMessage(TradeMessage tradeMessage, NodeAddress handle((PeerPublishedDelayedPayoutTxMessage) tradeMessage, peerNodeAddress); } else if (tradeMessage instanceof TraderSignedWitnessMessage) { handle((TraderSignedWitnessMessage) tradeMessage); + } else if (tradeMessage instanceof RequestCancelTradeMessage) { + handle((RequestCancelTradeMessage) tradeMessage, peerNodeAddress); + } else if (tradeMessage instanceof CancelTradeRequestAcceptedMessage) { + handle((CancelTradeRequestAcceptedMessage) tradeMessage, peerNodeAddress); + } else if (tradeMessage instanceof CancelTradeRequestRejectedMessage) { + handle((CancelTradeRequestRejectedMessage) tradeMessage, peerNodeAddress); } } diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java index 9e160f20d96..fb192b1bfdd 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java @@ -45,6 +45,6 @@ protected void run() { @Override protected void setState() { - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.PAYOUT_TX_PUBLISHED); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_ACCEPTED_PAYOUT_TX_PUBLISHED); } } diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java index aa489a0f468..c6e8931ffbc 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java @@ -17,10 +17,9 @@ package bisq.core.trade.protocol.tasks.cancel; -import bisq.core.btc.model.AddressEntry; import bisq.core.btc.wallet.BtcWalletService; import bisq.core.btc.wallet.WalletService; -import bisq.core.trade.HandleCancelTradeRequestState; +import bisq.core.trade.RequestCancelTradeState; import bisq.core.trade.Trade; import bisq.core.trade.messages.CancelTradeRequestAcceptedMessage; import bisq.core.trade.protocol.tasks.TradeTask; @@ -60,15 +59,13 @@ protected void run() { trade.setPayoutTx(committedCanceledTradePayoutTx); BtcWalletService.printTx("CanceledTradePayoutTx received from peer", committedCanceledTradePayoutTx); - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.RECEIVED_ACCEPTED_MSG); + trade.setRequestCancelTradeState(RequestCancelTradeState.RECEIVED_ACCEPTED_MSG); // We need to delay that call as we might get executed at startup after mailbox messages are // applied where we iterate over our pending trades. The closeCanceledTrade method would remove // that trade from the list causing a ConcurrentModificationException. // To avoid that we delay for one render frame. UserThread.execute(() -> processModel.getTradeManager().closeCanceledTrade(trade)); - - processModel.getBtcWalletService().swapTradeEntryToAvailableEntry(trade.getId(), AddressEntry.Context.MULTI_SIG); } else { log.info("We got the payout tx already set from SetupCanceledTradePayoutTxListener and do nothing here. trade ID={}", trade.getId()); } diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java index 1ba2183af39..69e5966f003 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java @@ -17,7 +17,7 @@ package bisq.core.trade.protocol.tasks.cancel; -import bisq.core.trade.HandleCancelTradeRequestState; +import bisq.core.trade.RequestCancelTradeState; import bisq.core.trade.Trade; import bisq.core.trade.messages.CancelTradeRequestRejectedMessage; import bisq.core.trade.protocol.tasks.TradeTask; @@ -46,7 +46,7 @@ protected void run() { // update to the latest peer address of our peer if the message is correct trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress()); - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.RECEIVED_REJECTED_MSG); + trade.setRequestCancelTradeState(RequestCancelTradeState.RECEIVED_REJECTED_MSG); processModel.removeMailboxMessageAfterProcessing(trade); complete(); } catch (Throwable t) { diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java index f9f30d67af7..6dc25514205 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java @@ -50,7 +50,7 @@ protected void run() { trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress()); processModel.removeMailboxMessageAfterProcessing(trade); - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.RECEIVED_CANCEL_REQUEST); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.RECEIVED_REQUEST); complete(); } catch (Throwable t) { diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java index b9c89000513..dcc8f339ed4 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java @@ -54,22 +54,22 @@ protected TradeMessage getMessage(String id) { @Override protected void setStateSent() { - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.PAYOUT_TX_PUBLISHED_MSG_SENT); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_ACCEPTED_MSG_SENT); } @Override protected void setStateArrived() { - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.PAYOUT_TX_PUBLISHED_MSG_ARRIVED); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_ACCEPTED_MSG_ARRIVED); } @Override protected void setStateStoredInMailbox() { - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.PAYOUT_TX_PUBLISHED_MSG_IN_MAILBOX); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_ACCEPTED_MSG_IN_MAILBOX); } @Override protected void setStateFault() { - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.PAYOUT_TX_PUBLISHED_MSG_SEND_FAILED); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_ACCEPTED_MSG_SEND_FAILED); } @Override diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java index 42594e9efa6..6b75875f231 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java @@ -48,22 +48,22 @@ protected TradeMessage getMessage(String id) { @Override protected void setStateSent() { - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_CANCELED_MSG_SENT); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_REJECTED_MSG_SENT); } @Override protected void setStateArrived() { - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_CANCELED_MSG_ARRIVED); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_REJECTED_MSG_ARRIVED); } @Override protected void setStateStoredInMailbox() { - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_CANCELED_MSG_IN_MAILBOX); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_REJECTED_MSG_IN_MAILBOX); } @Override protected void setStateFault() { - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_CANCELED_MSG_SEND_FAILED); + trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_REJECTED_MSG_SEND_FAILED); } @Override diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java index f0ff89e4ab3..bb7e8ac0218 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java @@ -18,7 +18,7 @@ package bisq.core.trade.protocol.tasks.cancel; import bisq.core.trade.Contract; -import bisq.core.trade.HandleCancelTradeRequestState; +import bisq.core.trade.RequestCancelTradeState; import bisq.core.trade.Trade; import bisq.core.trade.messages.RequestCancelTradeMessage; import bisq.core.trade.messages.TradeMessage; @@ -61,22 +61,22 @@ protected TradeMessage getMessage(String id) { @Override protected void setStateSent() { - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_MSG_SENT); + trade.setRequestCancelTradeState(RequestCancelTradeState.REQUEST_MSG_SENT); } @Override protected void setStateArrived() { - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_MSG_ARRIVED); + trade.setRequestCancelTradeState(RequestCancelTradeState.REQUEST_MSG_ARRIVED); } @Override protected void setStateStoredInMailbox() { - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_MSG_IN_MAILBOX); + trade.setRequestCancelTradeState(RequestCancelTradeState.REQUEST_MSG_IN_MAILBOX); } @Override protected void setStateFault() { - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_MSG_SEND_FAILED); + trade.setRequestCancelTradeState(RequestCancelTradeState.REQUEST_MSG_SEND_FAILED); } @Override diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java index 989aef55aeb..f20a87d4288 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java @@ -17,10 +17,11 @@ package bisq.core.trade.protocol.tasks.cancel; -import bisq.core.trade.HandleCancelTradeRequestState; +import bisq.core.trade.RequestCancelTradeState; import bisq.core.trade.Trade; import bisq.core.trade.protocol.tasks.SetupPayoutTxListener; +import bisq.common.UserThread; import bisq.common.taskrunner.TaskRunner; import lombok.extern.slf4j.Slf4j; @@ -46,9 +47,13 @@ protected void run() { @Override protected void setState() { - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.PAYOUT_TX_SEEN_IN_NETWORK); + trade.setRequestCancelTradeState(RequestCancelTradeState.PAYOUT_TX_SEEN_IN_NETWORK); if (trade.getPayoutTx() != null) { - processModel.getTradeManager().closeCanceledTrade(trade); + // We need to delay that call as we might get executed at startup after mailbox messages are + // applied where we iterate over our pending trades. The closeCanceledTrade method would remove + // that trade from the list causing a ConcurrentModificationException. + // To avoid that we delay for one render frame. + UserThread.execute(() -> processModel.getTradeManager().closeCanceledTrade(trade)); } } } diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index c4e0c0186da..7b6f21a8192 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -911,11 +911,12 @@ portfolio.failed.depositTxNull=The trade cannot be completed. Deposit transactio portfolio.failed.delayedPayoutTxNull=The trade cannot be completed. Delayed payout transaction is null portfolio.pending.cancelTrade=Cancel trade -portfolio.pending.requestSent=Cancel trade request message sent... -portfolio.pending.requestArrived=Cancel trade request message arrived -portfolio.pending.requestInMailbox=Cancel trade request message stored in mailbox -portfolio.pending.requestFailed=Sending cancel trade request message failed -portfolio.pending.requestGotRejected=Your cancel trade request was rejected by the peer +portfolio.pending.requestSent=Cancel trade request message sent. +portfolio.pending.requestArrived=Request message arrived. Awaiting peer's response. +portfolio.pending.requestInMailbox=Request message stored in mailbox. Awaiting peer's response. +portfolio.pending.requestFailed=Sending request message failed. +portfolio.pending.requestGotAccepted=Your cancel trade request was accepted by the peer. The trade is closed and the payout completed. +portfolio.pending.requestGotRejected=Your cancel trade request was rejected by the peer. portfolio.pending.doNotDecideYet=Don't decide yet portfolio.pending.requestCancelTradePopup=You can send a request to your trading peer for canceling the trade.\n\n\ If the peer accepts your request you will get back a part of your security deposit. The other part will be given to \ @@ -931,8 +932,8 @@ portfolio.pending.receivedCancelTradeRequestPopup=Your trading peer requested ca - Part of the peer''s security deposit: {2}\n\n\ If you prefer to continue the trade, reject the peer''s cancel request. If the peer does not complete the trade \ can open a dispute once the trade period is over.\n\n\ - You can also communicate with the peer via the trader chat to find out about the reason why he want to cancel \ - the trade.\n\n\ + You can also communicate with the peer via the trader chat to find out about the reason for the cancellation \ + request.\n\n\ Do you want to accept the request for cancellation? #################################################################### diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/HandleCancelTradeRequestPresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/HandleCancelTradeRequestPresentation.java index d18053af9bd..73d45b427b2 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/HandleCancelTradeRequestPresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/HandleCancelTradeRequestPresentation.java @@ -20,7 +20,6 @@ import bisq.desktop.main.overlays.popups.Popup; import bisq.core.locale.Res; -import bisq.core.offer.Offer; import bisq.core.trade.HandleCancelTradeRequestState; import bisq.core.trade.Trade; import bisq.core.trade.TradeCancellationManager; @@ -30,8 +29,6 @@ import lombok.extern.slf4j.Slf4j; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Handles the UI aspects of cancelling a trade * @@ -40,10 +37,9 @@ @Slf4j public class HandleCancelTradeRequestPresentation { private final Trade trade; - private final Offer offer; private final TradeCancellationManager manager; private final CoinFormatter formatter; - private ChangeListener canceledTradeStateListener; + private ChangeListener listener; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor @@ -53,7 +49,6 @@ public HandleCancelTradeRequestPresentation(Trade trade, TradeCancellationManager manager, CoinFormatter formatter) { this.trade = trade; - offer = checkNotNull(trade.getOffer()); this.manager = manager; this.formatter = formatter; } @@ -64,17 +59,17 @@ public HandleCancelTradeRequestPresentation(Trade trade, /////////////////////////////////////////////////////////////////////////////////////////// public void initialize() { - canceledTradeStateListener = (observable, oldValue, newValue) -> onCanceledTradeStateChanged(newValue); + listener = (observable, oldValue, newValue) -> onStateChanged(newValue); } public void activate() { - trade.getHandleCancelTradeRequestStateProperty().addListener(canceledTradeStateListener); - onCanceledTradeStateChanged(trade.getHandleCancelTradeRequestStateProperty().get()); + trade.getHandleCancelTradeRequestStateProperty().addListener(listener); + onStateChanged(trade.getHandleCancelTradeRequestStateProperty().get()); } public void deactivate() { - if (canceledTradeStateListener != null) { - trade.getHandleCancelTradeRequestStateProperty().removeListener(canceledTradeStateListener); + if (listener != null) { + trade.getHandleCancelTradeRequestStateProperty().removeListener(listener); } } @@ -85,74 +80,66 @@ public void deactivate() { /////////////////////////////////////////////////////////////////////////////////////////// - // Private + // UI handler /////////////////////////////////////////////////////////////////////////////////////////// - private void acceptCancelTradeRequest() { - manager.acceptCancelTradeRequest(trade, + private void onAcceptRequest() { + manager.acceptRequest(trade, () -> { }, errorMessage -> { }); } - private void rejectCancelTradeRequest() { - manager.rejectCancelTradeRequest(trade, + private void onRejectRequest() { + manager.rejectRequest(trade, () -> { }, errorMessage -> { }); } - private void onCanceledTradeStateChanged(HandleCancelTradeRequestState newValue) { - log.error("onCanceledTradeStateChanged {} {}", newValue, trade.getId()); + /////////////////////////////////////////////////////////////////////////////////////////// + // Private + /////////////////////////////////////////////////////////////////////////////////////////// + + private void onStateChanged(HandleCancelTradeRequestState newValue) { + log.error("onRequestCancelTradeStateChanged {} {}", newValue, trade.getId()); if (newValue == null) { return; } switch (newValue) { - case REQUEST_MSG_SENT: - break; - case REQUEST_MSG_ARRIVED: - break; - case REQUEST_MSG_IN_MAILBOX: - break; - case REQUEST_MSG_SEND_FAILED: - break; - case RECEIVED_CANCEL_REQUEST: + case RECEIVED_REQUEST: new Popup().width(850) .attention(Res.get("portfolio.pending.receivedCancelTradeRequestPopup", formatter.formatCoinWithCode(trade.getTradeAmount()), formatter.formatCoinWithCode(manager.getDefaultSecDepositOfAcceptingTrader(trade)), formatter.formatCoinWithCode(manager.getLostSecDepositOfRequestingTrader(trade)))) .actionButtonText(Res.get("shared.accept")) - .onAction(this::acceptCancelTradeRequest) + .onAction(this::onAcceptRequest) .secondaryActionButtonText(Res.get("shared.reject")) - .onSecondaryAction(this::rejectCancelTradeRequest) + .onSecondaryAction(this::onRejectRequest) .closeButtonText(Res.get("portfolio.pending.doNotDecideYet")) .show(); break; - case RECEIVED_ACCEPTED_MSG: - break; - case PAYOUT_TX_PUBLISHED: - break; - case PAYOUT_TX_PUBLISHED_MSG_SENT: + case REQUEST_ACCEPTED_PAYOUT_TX_PUBLISHED: break; - case PAYOUT_TX_PUBLISHED_MSG_ARRIVED: - break; - case PAYOUT_TX_PUBLISHED_MSG_IN_MAILBOX: + + case REQUEST_ACCEPTED_MSG_SENT: break; - case PAYOUT_TX_PUBLISHED_MSG_SEND_FAILED: + case REQUEST_ACCEPTED_MSG_ARRIVED: break; - case PAYOUT_TX_SEEN_IN_NETWORK: + case REQUEST_ACCEPTED_MSG_IN_MAILBOX: break; - case REQUEST_CANCELED_MSG_SENT: + case REQUEST_ACCEPTED_MSG_SEND_FAILED: break; - case REQUEST_CANCELED_MSG_ARRIVED: + + case REQUEST_REJECTED_MSG_SENT: break; - case REQUEST_CANCELED_MSG_IN_MAILBOX: + case REQUEST_REJECTED_MSG_ARRIVED: break; - case REQUEST_CANCELED_MSG_SEND_FAILED: + case REQUEST_REJECTED_MSG_IN_MAILBOX: break; - case RECEIVED_REJECTED_MSG: + case REQUEST_REJECTED_MSG_SEND_FAILED: break; } } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/RequestCancelTradePresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/RequestCancelTradePresentation.java index fadf2ac1ccf..b72d686485e 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/RequestCancelTradePresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/RequestCancelTradePresentation.java @@ -22,7 +22,7 @@ import bisq.desktop.main.overlays.popups.Popup; import bisq.core.locale.Res; -import bisq.core.trade.HandleCancelTradeRequestState; +import bisq.core.trade.RequestCancelTradeState; import bisq.core.trade.Trade; import bisq.core.trade.TradeCancellationManager; import bisq.core.util.coin.CoinFormatter; @@ -48,7 +48,7 @@ public class RequestCancelTradePresentation { private Button cancelTradeButton; private Label msgSentStatusLabel; private BusyAnimation msgSentBusyAnimation; - private ChangeListener canceledTradeStateListener; + private ChangeListener listener; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor @@ -70,25 +70,25 @@ public RequestCancelTradePresentation(Trade trade, public void initialize(HBox hBox, BusyAnimation msgSentBusyAnimation, Label msgSentStatusLabel) { - canceledTradeStateListener = (observable, oldValue, newValue) -> onCanceledTradeStateChanged(newValue); + listener = (observable, oldValue, newValue) -> onStateChanged(newValue); this.msgSentBusyAnimation = msgSentBusyAnimation; this.msgSentStatusLabel = msgSentStatusLabel; cancelTradeButton = new AutoTooltipButton(Res.get("portfolio.pending.cancelTrade")); cancelTradeButton.getStyleClass().add("action-button"); - cancelTradeButton.setOnAction(e -> showRequestCancelTradePopup()); + cancelTradeButton.setOnAction(e -> onRequestCancelTrade()); hBox.getChildren().add(1, cancelTradeButton); } public void activate() { - trade.getHandleCancelTradeRequestStateProperty().addListener(canceledTradeStateListener); - onCanceledTradeStateChanged(trade.getHandleCancelTradeRequestStateProperty().get()); + trade.getRequestCancelTradeStateProperty().addListener(listener); + onStateChanged(trade.getRequestCancelTradeStateProperty().get()); } public void deactivate() { - if (canceledTradeStateListener != null) { - trade.getHandleCancelTradeRequestStateProperty().removeListener(canceledTradeStateListener); + if (listener != null) { + trade.getRequestCancelTradeStateProperty().removeListener(listener); } } @@ -107,41 +107,47 @@ public void setDisable(boolean isDisabled) { // cancelTradeButton.setDisable(isDisabled); } - /////////////////////////////////////////////////////////////////////////////////////////// - // Private + // UI handler /////////////////////////////////////////////////////////////////////////////////////////// - private void requestCancelTrade() { - manager.requestCancelTrade(trade, - () -> { - }, errorMessage -> { - }); - } - - private void showRequestCancelTradePopup() { + private void onRequestCancelTrade() { new Popup().width(850) .attention(Res.get("portfolio.pending.requestCancelTradePopup", formatter.formatCoinWithCode(manager.getSecurityDepositForRequester()))) - .onAction(this::requestCancelTrade) + .onAction(this::doRequestCancelTrade) .actionButtonText(Res.get("shared.yes")) .closeButtonText(Res.get("shared.no")) .show(); } - private void onCanceledTradeStateChanged(HandleCancelTradeRequestState newValue) { - log.error("onCanceledTradeStateChanged {} {}", newValue, trade.getId()); - if (newValue == null) { - cancelTradeButton.setDisable(false); - return; - } + /////////////////////////////////////////////////////////////////////////////////////////// + // Private + /////////////////////////////////////////////////////////////////////////////////////////// + + private void doRequestCancelTrade() { + manager.requestCancelTrade(trade, + () -> { + log.info("Request cancel trade protocol completed."); + }, errorMessage -> { + msgSentStatusLabel.setText(errorMessage); + }); + } + + private void onStateChanged(RequestCancelTradeState state) { + log.error("onCanceledTradeStateChanged {} {}", state, trade.getId()); msgSentBusyAnimation.stop(); msgSentStatusLabel.setText(""); + if (state == null) { + cancelTradeButton.setDisable(false); + return; + } + cancelTradeButton.setDisable(true); - switch (newValue) { + switch (state) { case REQUEST_MSG_SENT: msgSentBusyAnimation.play(); msgSentStatusLabel.setText(Res.get("portfolio.pending.requestSent")); @@ -155,33 +161,17 @@ private void onCanceledTradeStateChanged(HandleCancelTradeRequestState newValue) case REQUEST_MSG_SEND_FAILED: msgSentStatusLabel.setText(Res.get("portfolio.pending.requestFailed")); break; - case RECEIVED_CANCEL_REQUEST: - break; + case RECEIVED_ACCEPTED_MSG: - break; - case PAYOUT_TX_PUBLISHED: - break; - case PAYOUT_TX_PUBLISHED_MSG_SENT: - break; - case PAYOUT_TX_PUBLISHED_MSG_ARRIVED: - break; - case PAYOUT_TX_PUBLISHED_MSG_IN_MAILBOX: - break; - case PAYOUT_TX_PUBLISHED_MSG_SEND_FAILED: - break; case PAYOUT_TX_SEEN_IN_NETWORK: - break; - case REQUEST_CANCELED_MSG_SENT: - break; - case REQUEST_CANCELED_MSG_ARRIVED: - break; - case REQUEST_CANCELED_MSG_IN_MAILBOX: - break; - case REQUEST_CANCELED_MSG_SEND_FAILED: + new Popup().information(Res.get("portfolio.pending.requestGotAccepted")).show(); break; case RECEIVED_REJECTED_MSG: msgSentStatusLabel.setText(Res.get("portfolio.pending.requestGotRejected")); break; + + default: + break; } } } From 8236ce2a8970f15a818aa1f3a5edf39d6a111e28 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 08:57:18 -0500 Subject: [PATCH 16/56] Remove cancel support at step 3. Once buyer has send payment we do not allow canceling anymore --- .../steps/buyer/BuyerStep3View.java | 12 ------------ .../steps/seller/SellerStep3View.java | 18 ------------------ 2 files changed, 30 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep3View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep3View.java index 647eb69c2a1..c97f3d3d9c4 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep3View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep3View.java @@ -19,7 +19,6 @@ import bisq.desktop.components.TextFieldWithIcon; import bisq.desktop.main.portfolio.pendingtrades.PendingTradesViewModel; -import bisq.desktop.main.portfolio.pendingtrades.steps.HandleCancelTradeRequestPresentation; import bisq.desktop.main.portfolio.pendingtrades.steps.TradeStepView; import bisq.desktop.util.Layout; @@ -38,7 +37,6 @@ public class BuyerStep3View extends TradeStepView { private final ChangeListener messageStateChangeListener; - private final HandleCancelTradeRequestPresentation handleCancelTradeRequestPresentation; private TextFieldWithIcon textFieldWithIcon; @@ -52,10 +50,6 @@ public BuyerStep3View(PendingTradesViewModel model) { messageStateChangeListener = (observable, oldValue, newValue) -> { updateMessageStateInfo(); }; - - handleCancelTradeRequestPresentation = new HandleCancelTradeRequestPresentation(trade, - model.dataModel.getTradeCancellationManager(), - model.getBtcFormatter()); } /////////////////////////////////////////////////////////////////////////////////////////// @@ -65,8 +59,6 @@ public BuyerStep3View(PendingTradesViewModel model) { @Override public void initialize() { super.initialize(); - - handleCancelTradeRequestPresentation.initialize(); } @Override @@ -76,16 +68,12 @@ public void activate() { model.getMessageStateProperty().addListener(messageStateChangeListener); updateMessageStateInfo(); - - handleCancelTradeRequestPresentation.activate(); } public void deactivate() { super.deactivate(); model.getMessageStateProperty().removeListener(messageStateChangeListener); - - handleCancelTradeRequestPresentation.deactivate(); } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java index 3c8f5c03808..f296b2e98ac 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java @@ -24,7 +24,6 @@ import bisq.desktop.components.indicator.TxConfidenceIndicator; import bisq.desktop.main.overlays.popups.Popup; import bisq.desktop.main.portfolio.pendingtrades.PendingTradesViewModel; -import bisq.desktop.main.portfolio.pendingtrades.steps.RequestCancelTradePresentation; import bisq.desktop.main.portfolio.pendingtrades.steps.TradeStepView; import bisq.desktop.util.DisplayUtils; import bisq.desktop.util.GUIUtil; @@ -91,7 +90,6 @@ public class SellerStep3View extends TradeStepView { private TxConfidenceIndicator assetTxConfidenceIndicator; @Nullable private ChangeListener proofResultListener; - private RequestCancelTradePresentation requestCancelTradePresentation; /////////////////////////////////////////////////////////////////////////////////////////// @@ -100,10 +98,6 @@ public class SellerStep3View extends TradeStepView { public SellerStep3View(PendingTradesViewModel model) { super(model); - - requestCancelTradePresentation = new RequestCancelTradePresentation(trade, - model.dataModel.getTradeCancellationManager(), - model.getBtcFormatter()); } /////////////////////////////////////////////////////////////////////////////////////////// @@ -224,9 +218,6 @@ public void initialize() { confirmButton.setOnAction(e -> onPaymentReceived()); busyAnimation = tuple.second; statusLabel = tuple.third; - HBox hBox = tuple.fourth; - - requestCancelTradePresentation.initialize(hBox, busyAnimation, statusLabel); } @Override @@ -295,8 +286,6 @@ public void activate() { applyAssetTxProofResult(trade.getAssetTxProofResult()); } - - requestCancelTradePresentation.activate(); } @Override @@ -317,8 +306,6 @@ public void deactivate() { if (isXmrTrade()) { trade.getAssetTxProofResultUpdateProperty().removeListener(proofResultListener); } - - requestCancelTradePresentation.deactivate(); } @@ -329,9 +316,6 @@ public void deactivate() { @Override protected void updateConfirmButtonDisableState(boolean isDisabled) { confirmButton.setDisable(isDisabled); - - //TODO - requestCancelTradePresentation.setDisable(isDisabled); } @@ -475,8 +459,6 @@ else if (paymentAccountPayload instanceof F2FAccountPayload) } private void confirmPaymentReceived() { - requestCancelTradePresentation.hideCancelButton(); - log.info("User pressed the [Confirm payment receipt] button for Trade {}", trade.getShortId()); busyAnimation.play(); statusLabel.setText(Res.get("shared.sendingConfirmation")); From 6f5e386a6c3fa11fee8caf923c010070f174f06a Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 08:59:11 -0500 Subject: [PATCH 17/56] Rename RequestCancelTradePresentation and HandleCancelTradeRequestPresentation to make more explicit which one is for buyer and which for seller --- ... => BuyerRequestCancelTradePresentation.java} | 8 ++++---- ...lerHandleCancelTradeRequestPresentation.java} | 8 ++++---- .../steps/buyer/BuyerStep2View.java | 16 ++++++++-------- .../steps/seller/SellerStep2View.java | 12 ++++++------ 4 files changed, 22 insertions(+), 22 deletions(-) rename desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/{RequestCancelTradePresentation.java => BuyerRequestCancelTradePresentation.java} (95%) rename desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/{HandleCancelTradeRequestPresentation.java => SellerHandleCancelTradeRequestPresentation.java} (94%) diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/RequestCancelTradePresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/BuyerRequestCancelTradePresentation.java similarity index 95% rename from desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/RequestCancelTradePresentation.java rename to desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/BuyerRequestCancelTradePresentation.java index b72d686485e..42feeaca7da 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/RequestCancelTradePresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/BuyerRequestCancelTradePresentation.java @@ -41,7 +41,7 @@ * todo: handle dispute */ @Slf4j -public class RequestCancelTradePresentation { +public class BuyerRequestCancelTradePresentation { private final Trade trade; private final TradeCancellationManager manager; private final CoinFormatter formatter; @@ -54,9 +54,9 @@ public class RequestCancelTradePresentation { // Constructor /////////////////////////////////////////////////////////////////////////////////////////// - public RequestCancelTradePresentation(Trade trade, - TradeCancellationManager manager, - CoinFormatter formatter) { + public BuyerRequestCancelTradePresentation(Trade trade, + TradeCancellationManager manager, + CoinFormatter formatter) { this.trade = trade; this.manager = manager; this.formatter = formatter; diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/HandleCancelTradeRequestPresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/SellerHandleCancelTradeRequestPresentation.java similarity index 94% rename from desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/HandleCancelTradeRequestPresentation.java rename to desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/SellerHandleCancelTradeRequestPresentation.java index 73d45b427b2..90e792ce214 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/HandleCancelTradeRequestPresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/SellerHandleCancelTradeRequestPresentation.java @@ -35,7 +35,7 @@ * todo: handle dispute */ @Slf4j -public class HandleCancelTradeRequestPresentation { +public class SellerHandleCancelTradeRequestPresentation { private final Trade trade; private final TradeCancellationManager manager; private final CoinFormatter formatter; @@ -45,9 +45,9 @@ public class HandleCancelTradeRequestPresentation { // Constructor /////////////////////////////////////////////////////////////////////////////////////////// - public HandleCancelTradeRequestPresentation(Trade trade, - TradeCancellationManager manager, - CoinFormatter formatter) { + public SellerHandleCancelTradeRequestPresentation(Trade trade, + TradeCancellationManager manager, + CoinFormatter formatter) { this.trade = trade; this.manager = manager; this.formatter = formatter; diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java index 48460cd4fea..d4184f6c8fa 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java @@ -50,7 +50,7 @@ import bisq.desktop.main.overlays.popups.Popup; import bisq.desktop.main.overlays.windows.SetXmrTxKeyWindow; import bisq.desktop.main.portfolio.pendingtrades.PendingTradesViewModel; -import bisq.desktop.main.portfolio.pendingtrades.steps.RequestCancelTradePresentation; +import bisq.desktop.main.portfolio.pendingtrades.steps.BuyerRequestCancelTradePresentation; import bisq.desktop.main.portfolio.pendingtrades.steps.TradeStepView; import bisq.desktop.util.DisplayUtils; import bisq.desktop.util.Layout; @@ -105,7 +105,7 @@ public class BuyerStep2View extends TradeStepView { private BusyAnimation busyAnimation; private Subscription tradeStatePropertySubscription; private Timer timeoutTimer; - private RequestCancelTradePresentation requestCancelTradePresentation; + private BuyerRequestCancelTradePresentation buyerRequestCancelTradePresentation; /////////////////////////////////////////////////////////////////////////////////////////// @@ -115,7 +115,7 @@ public class BuyerStep2View extends TradeStepView { public BuyerStep2View(PendingTradesViewModel model) { super(model); - requestCancelTradePresentation = new RequestCancelTradePresentation(trade, + buyerRequestCancelTradePresentation = new BuyerRequestCancelTradePresentation(trade, model.dataModel.getTradeCancellationManager(), model.getBtcFormatter()); } @@ -267,7 +267,7 @@ public void initialize() { statusLabel = tuple3.third; HBox hBox = tuple3.fourth; - requestCancelTradePresentation.initialize(hBox, busyAnimation, statusLabel); + buyerRequestCancelTradePresentation.initialize(hBox, busyAnimation, statusLabel); } @Override @@ -352,7 +352,7 @@ public void activate() { confirmButton.setDisable(isDisputed()); - requestCancelTradePresentation.activate(); + buyerRequestCancelTradePresentation.activate(); } @Override @@ -369,7 +369,7 @@ public void deactivate() { tradeStatePropertySubscription = null; } - requestCancelTradePresentation.deactivate(); + buyerRequestCancelTradePresentation.deactivate(); } @@ -530,7 +530,7 @@ private void showConfirmPaymentStartedPopup() { } private void confirmPaymentStarted() { - requestCancelTradePresentation.hideCancelButton(); + buyerRequestCancelTradePresentation.hideCancelButton(); // confirmButton.setDisable(true); busyAnimation.play(); @@ -654,6 +654,6 @@ protected void updateConfirmButtonDisableState(boolean isDisabled) { confirmButton.setDisable(isDisabled); //TODO - requestCancelTradePresentation.setDisable(isDisabled); + buyerRequestCancelTradePresentation.setDisable(isDisabled); } } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java index 2479633197d..10b6521b774 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java @@ -19,7 +19,7 @@ import bisq.desktop.components.paymentmethods.F2FForm; import bisq.desktop.main.portfolio.pendingtrades.PendingTradesViewModel; -import bisq.desktop.main.portfolio.pendingtrades.steps.HandleCancelTradeRequestPresentation; +import bisq.desktop.main.portfolio.pendingtrades.steps.SellerHandleCancelTradeRequestPresentation; import bisq.desktop.main.portfolio.pendingtrades.steps.TradeStepView; import bisq.desktop.util.Layout; @@ -45,7 +45,7 @@ public class SellerStep2View extends TradeStepView { private GridPane refreshButtonPane; private Timer timer; - private HandleCancelTradeRequestPresentation handleCancelTradeRequestPresentation; + private SellerHandleCancelTradeRequestPresentation sellerHandleCancelTradeRequestPresentation; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor @@ -54,7 +54,7 @@ public class SellerStep2View extends TradeStepView { public SellerStep2View(PendingTradesViewModel model) { super(model); - handleCancelTradeRequestPresentation = new HandleCancelTradeRequestPresentation(trade, + sellerHandleCancelTradeRequestPresentation = new SellerHandleCancelTradeRequestPresentation(trade, model.dataModel.getTradeCancellationManager(), model.getBtcFormatter()); } @@ -79,7 +79,7 @@ public void initialize() { addRefreshBlock(); - handleCancelTradeRequestPresentation.initialize(); + sellerHandleCancelTradeRequestPresentation.initialize(); } @Override @@ -88,7 +88,7 @@ public void activate() { activateRefreshButton(); - handleCancelTradeRequestPresentation.activate(); + sellerHandleCancelTradeRequestPresentation.activate(); } @Override @@ -97,7 +97,7 @@ public void deactivate() { deActivateRefreshButtonTimer(); - handleCancelTradeRequestPresentation.deactivate(); + sellerHandleCancelTradeRequestPresentation.deactivate(); } From 79a9ac994690e78adb4d4de9be267ff114a97d7b Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 08:59:35 -0500 Subject: [PATCH 18/56] Refactor: Move classes --- .../steps/{ => buyer}/BuyerRequestCancelTradePresentation.java | 2 +- .../portfolio/pendingtrades/steps/buyer/BuyerStep2View.java | 1 - .../SellerHandleCancelTradeRequestPresentation.java | 2 +- .../portfolio/pendingtrades/steps/seller/SellerStep2View.java | 1 - 4 files changed, 2 insertions(+), 4 deletions(-) rename desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/{ => buyer}/BuyerRequestCancelTradePresentation.java (99%) rename desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/{ => seller}/SellerHandleCancelTradeRequestPresentation.java (98%) diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/BuyerRequestCancelTradePresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java similarity index 99% rename from desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/BuyerRequestCancelTradePresentation.java rename to desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java index 42feeaca7da..b34d802ab92 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/BuyerRequestCancelTradePresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.desktop.main.portfolio.pendingtrades.steps; +package bisq.desktop.main.portfolio.pendingtrades.steps.buyer; import bisq.desktop.components.AutoTooltipButton; import bisq.desktop.components.BusyAnimation; diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java index d4184f6c8fa..0e7792f4f11 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java @@ -50,7 +50,6 @@ import bisq.desktop.main.overlays.popups.Popup; import bisq.desktop.main.overlays.windows.SetXmrTxKeyWindow; import bisq.desktop.main.portfolio.pendingtrades.PendingTradesViewModel; -import bisq.desktop.main.portfolio.pendingtrades.steps.BuyerRequestCancelTradePresentation; import bisq.desktop.main.portfolio.pendingtrades.steps.TradeStepView; import bisq.desktop.util.DisplayUtils; import bisq.desktop.util.Layout; diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/SellerHandleCancelTradeRequestPresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java similarity index 98% rename from desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/SellerHandleCancelTradeRequestPresentation.java rename to desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java index 90e792ce214..4e2d5793b90 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/SellerHandleCancelTradeRequestPresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.desktop.main.portfolio.pendingtrades.steps; +package bisq.desktop.main.portfolio.pendingtrades.steps.seller; import bisq.desktop.main.overlays.popups.Popup; diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java index 10b6521b774..232032e5fcc 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java @@ -19,7 +19,6 @@ import bisq.desktop.components.paymentmethods.F2FForm; import bisq.desktop.main.portfolio.pendingtrades.PendingTradesViewModel; -import bisq.desktop.main.portfolio.pendingtrades.steps.SellerHandleCancelTradeRequestPresentation; import bisq.desktop.main.portfolio.pendingtrades.steps.TradeStepView; import bisq.desktop.util.Layout; From 731345887d2fe45b20f6df979fae0331eaff6ee7 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 09:00:54 -0500 Subject: [PATCH 19/56] Refactor: Rename enums --- ...State.java => BuyersCancelTradeState.java} | 2 +- ...tate.java => SellersCancelTradeState.java} | 2 +- core/src/main/java/bisq/core/trade/Trade.java | 32 +++++++++---------- .../BroadcastCanceledTradePayoutTx.java | 4 +-- ...cessCancelTradeRequestAcceptedMessage.java | 4 +-- ...cessCancelTradeRequestRejectedMessage.java | 4 +-- .../ProcessRequestCancelTradeMessage.java | 4 +-- ...SendCancelTradeRequestAcceptedMessage.java | 10 +++--- ...SendCancelTradeRequestRejectedMessage.java | 10 +++--- .../cancel/SendRequestCancelTradeMessage.java | 10 +++--- .../SetupCanceledTradePayoutTxListener.java | 4 +-- .../BuyerRequestCancelTradePresentation.java | 6 ++-- ...rHandleCancelTradeRequestPresentation.java | 6 ++-- 13 files changed, 49 insertions(+), 49 deletions(-) rename core/src/main/java/bisq/core/trade/{RequestCancelTradeState.java => BuyersCancelTradeState.java} (95%) rename core/src/main/java/bisq/core/trade/{HandleCancelTradeRequestState.java => SellersCancelTradeState.java} (95%) diff --git a/core/src/main/java/bisq/core/trade/RequestCancelTradeState.java b/core/src/main/java/bisq/core/trade/BuyersCancelTradeState.java similarity index 95% rename from core/src/main/java/bisq/core/trade/RequestCancelTradeState.java rename to core/src/main/java/bisq/core/trade/BuyersCancelTradeState.java index b054aef1f21..62018150e9d 100644 --- a/core/src/main/java/bisq/core/trade/RequestCancelTradeState.java +++ b/core/src/main/java/bisq/core/trade/BuyersCancelTradeState.java @@ -17,7 +17,7 @@ package bisq.core.trade; -public enum RequestCancelTradeState { +public enum BuyersCancelTradeState { REQUEST_MSG_SENT, REQUEST_MSG_ARRIVED, REQUEST_MSG_IN_MAILBOX, diff --git a/core/src/main/java/bisq/core/trade/HandleCancelTradeRequestState.java b/core/src/main/java/bisq/core/trade/SellersCancelTradeState.java similarity index 95% rename from core/src/main/java/bisq/core/trade/HandleCancelTradeRequestState.java rename to core/src/main/java/bisq/core/trade/SellersCancelTradeState.java index 9fd5bae679b..9fd9cf92758 100644 --- a/core/src/main/java/bisq/core/trade/HandleCancelTradeRequestState.java +++ b/core/src/main/java/bisq/core/trade/SellersCancelTradeState.java @@ -17,7 +17,7 @@ package bisq.core.trade; -public enum HandleCancelTradeRequestState { +public enum SellersCancelTradeState { RECEIVED_REQUEST, REQUEST_ACCEPTED_PAYOUT_TX_PUBLISHED, diff --git a/core/src/main/java/bisq/core/trade/Trade.java b/core/src/main/java/bisq/core/trade/Trade.java index 5916aaabb2a..ac15b90cbd6 100644 --- a/core/src/main/java/bisq/core/trade/Trade.java +++ b/core/src/main/java/bisq/core/trade/Trade.java @@ -452,14 +452,14 @@ public static protobuf.Trade.TradePeriodState toProtoMessage(Trade.TradePeriodSt @Getter // Added at v1.3.9 - public HandleCancelTradeRequestState handleCancelTradeRequestState; + public SellersCancelTradeState sellersCancelTradeState; @Getter - transient final private ObjectProperty handleCancelTradeRequestStateProperty = new SimpleObjectProperty<>(); + transient final private ObjectProperty handleCancelTradeRequestStateProperty = new SimpleObjectProperty<>(); @Getter - public RequestCancelTradeState requestCancelTradeState; + public BuyersCancelTradeState buyersCancelTradeState; @Getter - transient final private ObjectProperty requestCancelTradeStateProperty = new SimpleObjectProperty<>(); + transient final private ObjectProperty requestCancelTradeStateProperty = new SimpleObjectProperty<>(); /////////////////////////////////////////////////////////////////////////////////////////// @@ -574,8 +574,8 @@ public Message toProtoMessage() { Optional.ofNullable(delayedPayoutTxBytes).ifPresent(e -> builder.setDelayedPayoutTxBytes(ByteString.copyFrom(delayedPayoutTxBytes))); Optional.ofNullable(counterCurrencyExtraData).ifPresent(e -> builder.setCounterCurrencyExtraData(counterCurrencyExtraData)); Optional.ofNullable(assetTxProofResult).ifPresent(e -> builder.setAssetTxProofResult(assetTxProofResult.name())); - Optional.ofNullable(handleCancelTradeRequestState).ifPresent(e -> builder.setHandleCancelTradeRequestState(handleCancelTradeRequestState.name())); - Optional.ofNullable(requestCancelTradeState).ifPresent(e -> builder.setRequestCancelTradeState(requestCancelTradeState.name())); + Optional.ofNullable(sellersCancelTradeState).ifPresent(e -> builder.setHandleCancelTradeRequestState(sellersCancelTradeState.name())); + Optional.ofNullable(buyersCancelTradeState).ifPresent(e -> builder.setRequestCancelTradeState(buyersCancelTradeState.name())); return builder.build(); } @@ -618,8 +618,8 @@ public static Trade fromProto(Trade trade, protobuf.Trade proto, CoreProtoResolv } trade.setAssetTxProofResult(persistedAssetTxProofResult); - trade.setHandleCancelTradeRequestState(ProtoUtil.enumFromProto(HandleCancelTradeRequestState.class, proto.getHandleCancelTradeRequestState())); - trade.setRequestCancelTradeState(ProtoUtil.enumFromProto(RequestCancelTradeState.class, proto.getRequestCancelTradeState())); + trade.setSellersCancelTradeState(ProtoUtil.enumFromProto(SellersCancelTradeState.class, proto.getHandleCancelTradeRequestState())); + trade.setBuyersCancelTradeState(ProtoUtil.enumFromProto(BuyersCancelTradeState.class, proto.getRequestCancelTradeState())); trade.chatMessages.addAll(proto.getChatMessageList().stream() .map(ChatMessage::fromPayloadProto) @@ -909,15 +909,15 @@ public void setAssetTxProofResult(@Nullable AssetTxProofResult assetTxProofResul persist(); } - public void setHandleCancelTradeRequestState(HandleCancelTradeRequestState handleCancelTradeRequestState) { - this.handleCancelTradeRequestState = handleCancelTradeRequestState; - handleCancelTradeRequestStateProperty.set(handleCancelTradeRequestState); + public void setSellersCancelTradeState(SellersCancelTradeState sellersCancelTradeState) { + this.sellersCancelTradeState = sellersCancelTradeState; + handleCancelTradeRequestStateProperty.set(sellersCancelTradeState); persist(); } - public void setRequestCancelTradeState(RequestCancelTradeState requestCancelTradeState) { - this.requestCancelTradeState = requestCancelTradeState; - requestCancelTradeStateProperty.set(requestCancelTradeState); + public void setBuyersCancelTradeState(BuyersCancelTradeState buyersCancelTradeState) { + this.buyersCancelTradeState = buyersCancelTradeState; + requestCancelTradeStateProperty.set(buyersCancelTradeState); persist(); } @@ -1257,8 +1257,8 @@ public String toString() { ",\n refundResultState=" + refundResultState + ",\n refundResultStateProperty=" + refundResultStateProperty + ",\n lastRefreshRequestDate=" + lastRefreshRequestDate + - ",\n handleCancelTradeRequestState=" + handleCancelTradeRequestState + - ",\n requestCancelTradeState=" + requestCancelTradeState + + ",\n handleCancelTradeRequestState=" + sellersCancelTradeState + + ",\n requestCancelTradeState=" + buyersCancelTradeState + "\n}"; } } diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java index fb192b1bfdd..55e5694f082 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java @@ -17,7 +17,7 @@ package bisq.core.trade.protocol.tasks.cancel; -import bisq.core.trade.HandleCancelTradeRequestState; +import bisq.core.trade.SellersCancelTradeState; import bisq.core.trade.Trade; import bisq.core.trade.protocol.tasks.BroadcastPayoutTx; @@ -45,6 +45,6 @@ protected void run() { @Override protected void setState() { - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_ACCEPTED_PAYOUT_TX_PUBLISHED); + trade.setSellersCancelTradeState(SellersCancelTradeState.REQUEST_ACCEPTED_PAYOUT_TX_PUBLISHED); } } diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java index c6e8931ffbc..8cb0de06dd1 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java @@ -19,7 +19,7 @@ import bisq.core.btc.wallet.BtcWalletService; import bisq.core.btc.wallet.WalletService; -import bisq.core.trade.RequestCancelTradeState; +import bisq.core.trade.BuyersCancelTradeState; import bisq.core.trade.Trade; import bisq.core.trade.messages.CancelTradeRequestAcceptedMessage; import bisq.core.trade.protocol.tasks.TradeTask; @@ -59,7 +59,7 @@ protected void run() { trade.setPayoutTx(committedCanceledTradePayoutTx); BtcWalletService.printTx("CanceledTradePayoutTx received from peer", committedCanceledTradePayoutTx); - trade.setRequestCancelTradeState(RequestCancelTradeState.RECEIVED_ACCEPTED_MSG); + trade.setBuyersCancelTradeState(BuyersCancelTradeState.RECEIVED_ACCEPTED_MSG); // We need to delay that call as we might get executed at startup after mailbox messages are // applied where we iterate over our pending trades. The closeCanceledTrade method would remove diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java index 69e5966f003..c8caa2cd318 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java @@ -17,7 +17,7 @@ package bisq.core.trade.protocol.tasks.cancel; -import bisq.core.trade.RequestCancelTradeState; +import bisq.core.trade.BuyersCancelTradeState; import bisq.core.trade.Trade; import bisq.core.trade.messages.CancelTradeRequestRejectedMessage; import bisq.core.trade.protocol.tasks.TradeTask; @@ -46,7 +46,7 @@ protected void run() { // update to the latest peer address of our peer if the message is correct trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress()); - trade.setRequestCancelTradeState(RequestCancelTradeState.RECEIVED_REJECTED_MSG); + trade.setBuyersCancelTradeState(BuyersCancelTradeState.RECEIVED_REJECTED_MSG); processModel.removeMailboxMessageAfterProcessing(trade); complete(); } catch (Throwable t) { diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java index 6dc25514205..6b8a9664260 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java @@ -17,7 +17,7 @@ package bisq.core.trade.protocol.tasks.cancel; -import bisq.core.trade.HandleCancelTradeRequestState; +import bisq.core.trade.SellersCancelTradeState; import bisq.core.trade.Trade; import bisq.core.trade.messages.RequestCancelTradeMessage; import bisq.core.trade.protocol.tasks.TradeTask; @@ -50,7 +50,7 @@ protected void run() { trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress()); processModel.removeMailboxMessageAfterProcessing(trade); - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.RECEIVED_REQUEST); + trade.setSellersCancelTradeState(SellersCancelTradeState.RECEIVED_REQUEST); complete(); } catch (Throwable t) { diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java index dcc8f339ed4..2fd3d9bdd22 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java @@ -17,7 +17,7 @@ package bisq.core.trade.protocol.tasks.cancel; -import bisq.core.trade.HandleCancelTradeRequestState; +import bisq.core.trade.SellersCancelTradeState; import bisq.core.trade.Trade; import bisq.core.trade.messages.CancelTradeRequestAcceptedMessage; import bisq.core.trade.messages.TradeMessage; @@ -54,22 +54,22 @@ protected TradeMessage getMessage(String id) { @Override protected void setStateSent() { - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_ACCEPTED_MSG_SENT); + trade.setSellersCancelTradeState(SellersCancelTradeState.REQUEST_ACCEPTED_MSG_SENT); } @Override protected void setStateArrived() { - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_ACCEPTED_MSG_ARRIVED); + trade.setSellersCancelTradeState(SellersCancelTradeState.REQUEST_ACCEPTED_MSG_ARRIVED); } @Override protected void setStateStoredInMailbox() { - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_ACCEPTED_MSG_IN_MAILBOX); + trade.setSellersCancelTradeState(SellersCancelTradeState.REQUEST_ACCEPTED_MSG_IN_MAILBOX); } @Override protected void setStateFault() { - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_ACCEPTED_MSG_SEND_FAILED); + trade.setSellersCancelTradeState(SellersCancelTradeState.REQUEST_ACCEPTED_MSG_SEND_FAILED); } @Override diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java index 6b75875f231..05a64f7e731 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java @@ -17,7 +17,7 @@ package bisq.core.trade.protocol.tasks.cancel; -import bisq.core.trade.HandleCancelTradeRequestState; +import bisq.core.trade.SellersCancelTradeState; import bisq.core.trade.Trade; import bisq.core.trade.messages.CancelTradeRequestRejectedMessage; import bisq.core.trade.messages.TradeMessage; @@ -48,22 +48,22 @@ protected TradeMessage getMessage(String id) { @Override protected void setStateSent() { - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_REJECTED_MSG_SENT); + trade.setSellersCancelTradeState(SellersCancelTradeState.REQUEST_REJECTED_MSG_SENT); } @Override protected void setStateArrived() { - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_REJECTED_MSG_ARRIVED); + trade.setSellersCancelTradeState(SellersCancelTradeState.REQUEST_REJECTED_MSG_ARRIVED); } @Override protected void setStateStoredInMailbox() { - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_REJECTED_MSG_IN_MAILBOX); + trade.setSellersCancelTradeState(SellersCancelTradeState.REQUEST_REJECTED_MSG_IN_MAILBOX); } @Override protected void setStateFault() { - trade.setHandleCancelTradeRequestState(HandleCancelTradeRequestState.REQUEST_REJECTED_MSG_SEND_FAILED); + trade.setSellersCancelTradeState(SellersCancelTradeState.REQUEST_REJECTED_MSG_SEND_FAILED); } @Override diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java index bb7e8ac0218..0793f53cbd7 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java @@ -17,8 +17,8 @@ package bisq.core.trade.protocol.tasks.cancel; +import bisq.core.trade.BuyersCancelTradeState; import bisq.core.trade.Contract; -import bisq.core.trade.RequestCancelTradeState; import bisq.core.trade.Trade; import bisq.core.trade.messages.RequestCancelTradeMessage; import bisq.core.trade.messages.TradeMessage; @@ -61,22 +61,22 @@ protected TradeMessage getMessage(String id) { @Override protected void setStateSent() { - trade.setRequestCancelTradeState(RequestCancelTradeState.REQUEST_MSG_SENT); + trade.setBuyersCancelTradeState(BuyersCancelTradeState.REQUEST_MSG_SENT); } @Override protected void setStateArrived() { - trade.setRequestCancelTradeState(RequestCancelTradeState.REQUEST_MSG_ARRIVED); + trade.setBuyersCancelTradeState(BuyersCancelTradeState.REQUEST_MSG_ARRIVED); } @Override protected void setStateStoredInMailbox() { - trade.setRequestCancelTradeState(RequestCancelTradeState.REQUEST_MSG_IN_MAILBOX); + trade.setBuyersCancelTradeState(BuyersCancelTradeState.REQUEST_MSG_IN_MAILBOX); } @Override protected void setStateFault() { - trade.setRequestCancelTradeState(RequestCancelTradeState.REQUEST_MSG_SEND_FAILED); + trade.setBuyersCancelTradeState(BuyersCancelTradeState.REQUEST_MSG_SEND_FAILED); } @Override diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java index f20a87d4288..bfb5508b5da 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java @@ -17,7 +17,7 @@ package bisq.core.trade.protocol.tasks.cancel; -import bisq.core.trade.RequestCancelTradeState; +import bisq.core.trade.BuyersCancelTradeState; import bisq.core.trade.Trade; import bisq.core.trade.protocol.tasks.SetupPayoutTxListener; @@ -47,7 +47,7 @@ protected void run() { @Override protected void setState() { - trade.setRequestCancelTradeState(RequestCancelTradeState.PAYOUT_TX_SEEN_IN_NETWORK); + trade.setBuyersCancelTradeState(BuyersCancelTradeState.PAYOUT_TX_SEEN_IN_NETWORK); if (trade.getPayoutTx() != null) { // We need to delay that call as we might get executed at startup after mailbox messages are // applied where we iterate over our pending trades. The closeCanceledTrade method would remove diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java index b34d802ab92..44a3f25311e 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java @@ -22,7 +22,7 @@ import bisq.desktop.main.overlays.popups.Popup; import bisq.core.locale.Res; -import bisq.core.trade.RequestCancelTradeState; +import bisq.core.trade.BuyersCancelTradeState; import bisq.core.trade.Trade; import bisq.core.trade.TradeCancellationManager; import bisq.core.util.coin.CoinFormatter; @@ -48,7 +48,7 @@ public class BuyerRequestCancelTradePresentation { private Button cancelTradeButton; private Label msgSentStatusLabel; private BusyAnimation msgSentBusyAnimation; - private ChangeListener listener; + private ChangeListener listener; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor @@ -136,7 +136,7 @@ private void doRequestCancelTrade() { } - private void onStateChanged(RequestCancelTradeState state) { + private void onStateChanged(BuyersCancelTradeState state) { log.error("onCanceledTradeStateChanged {} {}", state, trade.getId()); msgSentBusyAnimation.stop(); msgSentStatusLabel.setText(""); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java index 4e2d5793b90..07bc0763ebd 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java @@ -20,7 +20,7 @@ import bisq.desktop.main.overlays.popups.Popup; import bisq.core.locale.Res; -import bisq.core.trade.HandleCancelTradeRequestState; +import bisq.core.trade.SellersCancelTradeState; import bisq.core.trade.Trade; import bisq.core.trade.TradeCancellationManager; import bisq.core.util.coin.CoinFormatter; @@ -39,7 +39,7 @@ public class SellerHandleCancelTradeRequestPresentation { private final Trade trade; private final TradeCancellationManager manager; private final CoinFormatter formatter; - private ChangeListener listener; + private ChangeListener listener; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor @@ -102,7 +102,7 @@ private void onRejectRequest() { // Private /////////////////////////////////////////////////////////////////////////////////////////// - private void onStateChanged(HandleCancelTradeRequestState newValue) { + private void onStateChanged(SellersCancelTradeState newValue) { log.error("onRequestCancelTradeStateChanged {} {}", newValue, trade.getId()); if (newValue == null) { return; From e483efdfaa202b7f8694fe576df1104463489981 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 09:02:50 -0500 Subject: [PATCH 20/56] Refactor: Move enums to seller and buyer trade --- .../main/java/bisq/core/trade/BuyerTrade.java | 13 +++++++- .../core/trade/BuyersCancelTradeState.java | 29 ---------------- .../java/bisq/core/trade/SellerTrade.java | 16 +++++++++ .../core/trade/SellersCancelTradeState.java | 33 ------------------- core/src/main/java/bisq/core/trade/Trade.java | 16 ++++----- .../BroadcastCanceledTradePayoutTx.java | 4 +-- ...cessCancelTradeRequestAcceptedMessage.java | 4 +-- ...cessCancelTradeRequestRejectedMessage.java | 4 +-- .../ProcessRequestCancelTradeMessage.java | 4 +-- ...SendCancelTradeRequestAcceptedMessage.java | 10 +++--- ...SendCancelTradeRequestRejectedMessage.java | 10 +++--- .../cancel/SendRequestCancelTradeMessage.java | 10 +++--- .../SetupCanceledTradePayoutTxListener.java | 4 +-- .../BuyerRequestCancelTradePresentation.java | 6 ++-- ...rHandleCancelTradeRequestPresentation.java | 6 ++-- 15 files changed, 67 insertions(+), 102 deletions(-) delete mode 100644 core/src/main/java/bisq/core/trade/BuyersCancelTradeState.java delete mode 100644 core/src/main/java/bisq/core/trade/SellersCancelTradeState.java diff --git a/core/src/main/java/bisq/core/trade/BuyerTrade.java b/core/src/main/java/bisq/core/trade/BuyerTrade.java index 4112252e6d6..557b9e48d3e 100644 --- a/core/src/main/java/bisq/core/trade/BuyerTrade.java +++ b/core/src/main/java/bisq/core/trade/BuyerTrade.java @@ -38,6 +38,18 @@ @Slf4j public abstract class BuyerTrade extends Trade { + + public enum BuyersCancelTradeState { + REQUEST_MSG_SENT, + REQUEST_MSG_ARRIVED, + REQUEST_MSG_IN_MAILBOX, + REQUEST_MSG_SEND_FAILED, + + RECEIVED_ACCEPTED_MSG, + PAYOUT_TX_SEEN_IN_NETWORK, + RECEIVED_REJECTED_MSG + } + BuyerTrade(Offer offer, Coin tradeAmount, Coin txFee, @@ -95,5 +107,4 @@ public Coin getPayoutAmount() { return getOffer().getBuyerSecurityDeposit().add(getTradeAmount()); } - } diff --git a/core/src/main/java/bisq/core/trade/BuyersCancelTradeState.java b/core/src/main/java/bisq/core/trade/BuyersCancelTradeState.java deleted file mode 100644 index 62018150e9d..00000000000 --- a/core/src/main/java/bisq/core/trade/BuyersCancelTradeState.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq 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. - * - * Bisq 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 Bisq. If not, see . - */ - -package bisq.core.trade; - -public enum BuyersCancelTradeState { - REQUEST_MSG_SENT, - REQUEST_MSG_ARRIVED, - REQUEST_MSG_IN_MAILBOX, - REQUEST_MSG_SEND_FAILED, - - RECEIVED_ACCEPTED_MSG, - PAYOUT_TX_SEEN_IN_NETWORK, - RECEIVED_REJECTED_MSG -} diff --git a/core/src/main/java/bisq/core/trade/SellerTrade.java b/core/src/main/java/bisq/core/trade/SellerTrade.java index 68eed3a1e08..c7e7ec9ec17 100644 --- a/core/src/main/java/bisq/core/trade/SellerTrade.java +++ b/core/src/main/java/bisq/core/trade/SellerTrade.java @@ -37,6 +37,22 @@ @Slf4j public abstract class SellerTrade extends Trade { + + public enum SellersCancelTradeState { + RECEIVED_REQUEST, + + REQUEST_ACCEPTED_PAYOUT_TX_PUBLISHED, + REQUEST_ACCEPTED_MSG_SENT, + REQUEST_ACCEPTED_MSG_ARRIVED, + REQUEST_ACCEPTED_MSG_IN_MAILBOX, + REQUEST_ACCEPTED_MSG_SEND_FAILED, + + REQUEST_REJECTED_MSG_SENT, + REQUEST_REJECTED_MSG_ARRIVED, + REQUEST_REJECTED_MSG_IN_MAILBOX, + REQUEST_REJECTED_MSG_SEND_FAILED + } + SellerTrade(Offer offer, Coin tradeAmount, Coin txFee, diff --git a/core/src/main/java/bisq/core/trade/SellersCancelTradeState.java b/core/src/main/java/bisq/core/trade/SellersCancelTradeState.java deleted file mode 100644 index 9fd9cf92758..00000000000 --- a/core/src/main/java/bisq/core/trade/SellersCancelTradeState.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq 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. - * - * Bisq 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 Bisq. If not, see . - */ - -package bisq.core.trade; - -public enum SellersCancelTradeState { - RECEIVED_REQUEST, - - REQUEST_ACCEPTED_PAYOUT_TX_PUBLISHED, - REQUEST_ACCEPTED_MSG_SENT, - REQUEST_ACCEPTED_MSG_ARRIVED, - REQUEST_ACCEPTED_MSG_IN_MAILBOX, - REQUEST_ACCEPTED_MSG_SEND_FAILED, - - REQUEST_REJECTED_MSG_SENT, - REQUEST_REJECTED_MSG_ARRIVED, - REQUEST_REJECTED_MSG_IN_MAILBOX, - REQUEST_REJECTED_MSG_SEND_FAILED -} diff --git a/core/src/main/java/bisq/core/trade/Trade.java b/core/src/main/java/bisq/core/trade/Trade.java index ac15b90cbd6..b658d85d03e 100644 --- a/core/src/main/java/bisq/core/trade/Trade.java +++ b/core/src/main/java/bisq/core/trade/Trade.java @@ -452,14 +452,14 @@ public static protobuf.Trade.TradePeriodState toProtoMessage(Trade.TradePeriodSt @Getter // Added at v1.3.9 - public SellersCancelTradeState sellersCancelTradeState; + public SellerTrade.SellersCancelTradeState sellersCancelTradeState; @Getter - transient final private ObjectProperty handleCancelTradeRequestStateProperty = new SimpleObjectProperty<>(); + transient final private ObjectProperty handleCancelTradeRequestStateProperty = new SimpleObjectProperty<>(); @Getter - public BuyersCancelTradeState buyersCancelTradeState; + public BuyerTrade.BuyersCancelTradeState buyersCancelTradeState; @Getter - transient final private ObjectProperty requestCancelTradeStateProperty = new SimpleObjectProperty<>(); + transient final private ObjectProperty requestCancelTradeStateProperty = new SimpleObjectProperty<>(); /////////////////////////////////////////////////////////////////////////////////////////// @@ -618,8 +618,8 @@ public static Trade fromProto(Trade trade, protobuf.Trade proto, CoreProtoResolv } trade.setAssetTxProofResult(persistedAssetTxProofResult); - trade.setSellersCancelTradeState(ProtoUtil.enumFromProto(SellersCancelTradeState.class, proto.getHandleCancelTradeRequestState())); - trade.setBuyersCancelTradeState(ProtoUtil.enumFromProto(BuyersCancelTradeState.class, proto.getRequestCancelTradeState())); + trade.setSellersCancelTradeState(ProtoUtil.enumFromProto(SellerTrade.SellersCancelTradeState.class, proto.getHandleCancelTradeRequestState())); + trade.setBuyersCancelTradeState(ProtoUtil.enumFromProto(BuyerTrade.BuyersCancelTradeState.class, proto.getRequestCancelTradeState())); trade.chatMessages.addAll(proto.getChatMessageList().stream() .map(ChatMessage::fromPayloadProto) @@ -909,13 +909,13 @@ public void setAssetTxProofResult(@Nullable AssetTxProofResult assetTxProofResul persist(); } - public void setSellersCancelTradeState(SellersCancelTradeState sellersCancelTradeState) { + public void setSellersCancelTradeState(SellerTrade.SellersCancelTradeState sellersCancelTradeState) { this.sellersCancelTradeState = sellersCancelTradeState; handleCancelTradeRequestStateProperty.set(sellersCancelTradeState); persist(); } - public void setBuyersCancelTradeState(BuyersCancelTradeState buyersCancelTradeState) { + public void setBuyersCancelTradeState(BuyerTrade.BuyersCancelTradeState buyersCancelTradeState) { this.buyersCancelTradeState = buyersCancelTradeState; requestCancelTradeStateProperty.set(buyersCancelTradeState); persist(); diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java index 55e5694f082..480d7d930ed 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java @@ -17,7 +17,7 @@ package bisq.core.trade.protocol.tasks.cancel; -import bisq.core.trade.SellersCancelTradeState; +import bisq.core.trade.SellerTrade; import bisq.core.trade.Trade; import bisq.core.trade.protocol.tasks.BroadcastPayoutTx; @@ -45,6 +45,6 @@ protected void run() { @Override protected void setState() { - trade.setSellersCancelTradeState(SellersCancelTradeState.REQUEST_ACCEPTED_PAYOUT_TX_PUBLISHED); + trade.setSellersCancelTradeState(SellerTrade.SellersCancelTradeState.REQUEST_ACCEPTED_PAYOUT_TX_PUBLISHED); } } diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java index 8cb0de06dd1..8a2fe04e463 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java @@ -19,7 +19,7 @@ import bisq.core.btc.wallet.BtcWalletService; import bisq.core.btc.wallet.WalletService; -import bisq.core.trade.BuyersCancelTradeState; +import bisq.core.trade.BuyerTrade; import bisq.core.trade.Trade; import bisq.core.trade.messages.CancelTradeRequestAcceptedMessage; import bisq.core.trade.protocol.tasks.TradeTask; @@ -59,7 +59,7 @@ protected void run() { trade.setPayoutTx(committedCanceledTradePayoutTx); BtcWalletService.printTx("CanceledTradePayoutTx received from peer", committedCanceledTradePayoutTx); - trade.setBuyersCancelTradeState(BuyersCancelTradeState.RECEIVED_ACCEPTED_MSG); + trade.setBuyersCancelTradeState(BuyerTrade.BuyersCancelTradeState.RECEIVED_ACCEPTED_MSG); // We need to delay that call as we might get executed at startup after mailbox messages are // applied where we iterate over our pending trades. The closeCanceledTrade method would remove diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java index c8caa2cd318..d04b288ba65 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java @@ -17,7 +17,7 @@ package bisq.core.trade.protocol.tasks.cancel; -import bisq.core.trade.BuyersCancelTradeState; +import bisq.core.trade.BuyerTrade; import bisq.core.trade.Trade; import bisq.core.trade.messages.CancelTradeRequestRejectedMessage; import bisq.core.trade.protocol.tasks.TradeTask; @@ -46,7 +46,7 @@ protected void run() { // update to the latest peer address of our peer if the message is correct trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress()); - trade.setBuyersCancelTradeState(BuyersCancelTradeState.RECEIVED_REJECTED_MSG); + trade.setBuyersCancelTradeState(BuyerTrade.BuyersCancelTradeState.RECEIVED_REJECTED_MSG); processModel.removeMailboxMessageAfterProcessing(trade); complete(); } catch (Throwable t) { diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java index 6b8a9664260..e87f5e1dd60 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java @@ -17,7 +17,7 @@ package bisq.core.trade.protocol.tasks.cancel; -import bisq.core.trade.SellersCancelTradeState; +import bisq.core.trade.SellerTrade; import bisq.core.trade.Trade; import bisq.core.trade.messages.RequestCancelTradeMessage; import bisq.core.trade.protocol.tasks.TradeTask; @@ -50,7 +50,7 @@ protected void run() { trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress()); processModel.removeMailboxMessageAfterProcessing(trade); - trade.setSellersCancelTradeState(SellersCancelTradeState.RECEIVED_REQUEST); + trade.setSellersCancelTradeState(SellerTrade.SellersCancelTradeState.RECEIVED_REQUEST); complete(); } catch (Throwable t) { diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java index 2fd3d9bdd22..7c5cc3e1b6c 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java @@ -17,7 +17,7 @@ package bisq.core.trade.protocol.tasks.cancel; -import bisq.core.trade.SellersCancelTradeState; +import bisq.core.trade.SellerTrade; import bisq.core.trade.Trade; import bisq.core.trade.messages.CancelTradeRequestAcceptedMessage; import bisq.core.trade.messages.TradeMessage; @@ -54,22 +54,22 @@ protected TradeMessage getMessage(String id) { @Override protected void setStateSent() { - trade.setSellersCancelTradeState(SellersCancelTradeState.REQUEST_ACCEPTED_MSG_SENT); + trade.setSellersCancelTradeState(SellerTrade.SellersCancelTradeState.REQUEST_ACCEPTED_MSG_SENT); } @Override protected void setStateArrived() { - trade.setSellersCancelTradeState(SellersCancelTradeState.REQUEST_ACCEPTED_MSG_ARRIVED); + trade.setSellersCancelTradeState(SellerTrade.SellersCancelTradeState.REQUEST_ACCEPTED_MSG_ARRIVED); } @Override protected void setStateStoredInMailbox() { - trade.setSellersCancelTradeState(SellersCancelTradeState.REQUEST_ACCEPTED_MSG_IN_MAILBOX); + trade.setSellersCancelTradeState(SellerTrade.SellersCancelTradeState.REQUEST_ACCEPTED_MSG_IN_MAILBOX); } @Override protected void setStateFault() { - trade.setSellersCancelTradeState(SellersCancelTradeState.REQUEST_ACCEPTED_MSG_SEND_FAILED); + trade.setSellersCancelTradeState(SellerTrade.SellersCancelTradeState.REQUEST_ACCEPTED_MSG_SEND_FAILED); } @Override diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java index 05a64f7e731..44f5940967d 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java @@ -17,7 +17,7 @@ package bisq.core.trade.protocol.tasks.cancel; -import bisq.core.trade.SellersCancelTradeState; +import bisq.core.trade.SellerTrade; import bisq.core.trade.Trade; import bisq.core.trade.messages.CancelTradeRequestRejectedMessage; import bisq.core.trade.messages.TradeMessage; @@ -48,22 +48,22 @@ protected TradeMessage getMessage(String id) { @Override protected void setStateSent() { - trade.setSellersCancelTradeState(SellersCancelTradeState.REQUEST_REJECTED_MSG_SENT); + trade.setSellersCancelTradeState(SellerTrade.SellersCancelTradeState.REQUEST_REJECTED_MSG_SENT); } @Override protected void setStateArrived() { - trade.setSellersCancelTradeState(SellersCancelTradeState.REQUEST_REJECTED_MSG_ARRIVED); + trade.setSellersCancelTradeState(SellerTrade.SellersCancelTradeState.REQUEST_REJECTED_MSG_ARRIVED); } @Override protected void setStateStoredInMailbox() { - trade.setSellersCancelTradeState(SellersCancelTradeState.REQUEST_REJECTED_MSG_IN_MAILBOX); + trade.setSellersCancelTradeState(SellerTrade.SellersCancelTradeState.REQUEST_REJECTED_MSG_IN_MAILBOX); } @Override protected void setStateFault() { - trade.setSellersCancelTradeState(SellersCancelTradeState.REQUEST_REJECTED_MSG_SEND_FAILED); + trade.setSellersCancelTradeState(SellerTrade.SellersCancelTradeState.REQUEST_REJECTED_MSG_SEND_FAILED); } @Override diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java index 0793f53cbd7..f43205cc2fe 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java @@ -17,7 +17,7 @@ package bisq.core.trade.protocol.tasks.cancel; -import bisq.core.trade.BuyersCancelTradeState; +import bisq.core.trade.BuyerTrade; import bisq.core.trade.Contract; import bisq.core.trade.Trade; import bisq.core.trade.messages.RequestCancelTradeMessage; @@ -61,22 +61,22 @@ protected TradeMessage getMessage(String id) { @Override protected void setStateSent() { - trade.setBuyersCancelTradeState(BuyersCancelTradeState.REQUEST_MSG_SENT); + trade.setBuyersCancelTradeState(BuyerTrade.BuyersCancelTradeState.REQUEST_MSG_SENT); } @Override protected void setStateArrived() { - trade.setBuyersCancelTradeState(BuyersCancelTradeState.REQUEST_MSG_ARRIVED); + trade.setBuyersCancelTradeState(BuyerTrade.BuyersCancelTradeState.REQUEST_MSG_ARRIVED); } @Override protected void setStateStoredInMailbox() { - trade.setBuyersCancelTradeState(BuyersCancelTradeState.REQUEST_MSG_IN_MAILBOX); + trade.setBuyersCancelTradeState(BuyerTrade.BuyersCancelTradeState.REQUEST_MSG_IN_MAILBOX); } @Override protected void setStateFault() { - trade.setBuyersCancelTradeState(BuyersCancelTradeState.REQUEST_MSG_SEND_FAILED); + trade.setBuyersCancelTradeState(BuyerTrade.BuyersCancelTradeState.REQUEST_MSG_SEND_FAILED); } @Override diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java index bfb5508b5da..34eac5a2ad7 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java @@ -17,7 +17,7 @@ package bisq.core.trade.protocol.tasks.cancel; -import bisq.core.trade.BuyersCancelTradeState; +import bisq.core.trade.BuyerTrade; import bisq.core.trade.Trade; import bisq.core.trade.protocol.tasks.SetupPayoutTxListener; @@ -47,7 +47,7 @@ protected void run() { @Override protected void setState() { - trade.setBuyersCancelTradeState(BuyersCancelTradeState.PAYOUT_TX_SEEN_IN_NETWORK); + trade.setBuyersCancelTradeState(BuyerTrade.BuyersCancelTradeState.PAYOUT_TX_SEEN_IN_NETWORK); if (trade.getPayoutTx() != null) { // We need to delay that call as we might get executed at startup after mailbox messages are // applied where we iterate over our pending trades. The closeCanceledTrade method would remove diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java index 44a3f25311e..8f833b531ee 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java @@ -22,7 +22,7 @@ import bisq.desktop.main.overlays.popups.Popup; import bisq.core.locale.Res; -import bisq.core.trade.BuyersCancelTradeState; +import bisq.core.trade.BuyerTrade; import bisq.core.trade.Trade; import bisq.core.trade.TradeCancellationManager; import bisq.core.util.coin.CoinFormatter; @@ -48,7 +48,7 @@ public class BuyerRequestCancelTradePresentation { private Button cancelTradeButton; private Label msgSentStatusLabel; private BusyAnimation msgSentBusyAnimation; - private ChangeListener listener; + private ChangeListener listener; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor @@ -136,7 +136,7 @@ private void doRequestCancelTrade() { } - private void onStateChanged(BuyersCancelTradeState state) { + private void onStateChanged(BuyerTrade.BuyersCancelTradeState state) { log.error("onCanceledTradeStateChanged {} {}", state, trade.getId()); msgSentBusyAnimation.stop(); msgSentStatusLabel.setText(""); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java index 07bc0763ebd..896083b20a3 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java @@ -20,7 +20,7 @@ import bisq.desktop.main.overlays.popups.Popup; import bisq.core.locale.Res; -import bisq.core.trade.SellersCancelTradeState; +import bisq.core.trade.SellerTrade; import bisq.core.trade.Trade; import bisq.core.trade.TradeCancellationManager; import bisq.core.util.coin.CoinFormatter; @@ -39,7 +39,7 @@ public class SellerHandleCancelTradeRequestPresentation { private final Trade trade; private final TradeCancellationManager manager; private final CoinFormatter formatter; - private ChangeListener listener; + private ChangeListener listener; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor @@ -102,7 +102,7 @@ private void onRejectRequest() { // Private /////////////////////////////////////////////////////////////////////////////////////////// - private void onStateChanged(SellersCancelTradeState newValue) { + private void onStateChanged(SellerTrade.SellersCancelTradeState newValue) { log.error("onRequestCancelTradeStateChanged {} {}", newValue, trade.getId()); if (newValue == null) { return; From 3e85ff6e9b4b0ab451d2eb8840cdc591ea2fff40 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 09:09:58 -0500 Subject: [PATCH 21/56] Refactor: Rename enums --- .../main/java/bisq/core/trade/BuyerTrade.java | 2 +- .../java/bisq/core/trade/SellerTrade.java | 2 +- core/src/main/java/bisq/core/trade/Trade.java | 32 +++++++++---------- .../BroadcastCanceledTradePayoutTx.java | 2 +- ...cessCancelTradeRequestAcceptedMessage.java | 2 +- ...cessCancelTradeRequestRejectedMessage.java | 2 +- .../ProcessRequestCancelTradeMessage.java | 2 +- ...SendCancelTradeRequestAcceptedMessage.java | 8 ++--- ...SendCancelTradeRequestRejectedMessage.java | 8 ++--- .../cancel/SendRequestCancelTradeMessage.java | 8 ++--- .../SetupCanceledTradePayoutTxListener.java | 2 +- .../BuyerRequestCancelTradePresentation.java | 10 +++--- ...rHandleCancelTradeRequestPresentation.java | 10 +++--- proto/src/main/proto/pb.proto | 4 +-- 14 files changed, 47 insertions(+), 47 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/BuyerTrade.java b/core/src/main/java/bisq/core/trade/BuyerTrade.java index 557b9e48d3e..2a7d7a7403e 100644 --- a/core/src/main/java/bisq/core/trade/BuyerTrade.java +++ b/core/src/main/java/bisq/core/trade/BuyerTrade.java @@ -39,7 +39,7 @@ @Slf4j public abstract class BuyerTrade extends Trade { - public enum BuyersCancelTradeState { + public enum CancelTradeState { REQUEST_MSG_SENT, REQUEST_MSG_ARRIVED, REQUEST_MSG_IN_MAILBOX, diff --git a/core/src/main/java/bisq/core/trade/SellerTrade.java b/core/src/main/java/bisq/core/trade/SellerTrade.java index c7e7ec9ec17..cc65898ddad 100644 --- a/core/src/main/java/bisq/core/trade/SellerTrade.java +++ b/core/src/main/java/bisq/core/trade/SellerTrade.java @@ -38,7 +38,7 @@ @Slf4j public abstract class SellerTrade extends Trade { - public enum SellersCancelTradeState { + public enum CancelTradeState { RECEIVED_REQUEST, REQUEST_ACCEPTED_PAYOUT_TX_PUBLISHED, diff --git a/core/src/main/java/bisq/core/trade/Trade.java b/core/src/main/java/bisq/core/trade/Trade.java index b658d85d03e..58b97fc51cf 100644 --- a/core/src/main/java/bisq/core/trade/Trade.java +++ b/core/src/main/java/bisq/core/trade/Trade.java @@ -452,14 +452,14 @@ public static protobuf.Trade.TradePeriodState toProtoMessage(Trade.TradePeriodSt @Getter // Added at v1.3.9 - public SellerTrade.SellersCancelTradeState sellersCancelTradeState; + public SellerTrade.CancelTradeState sellersCancelTradeState; @Getter - transient final private ObjectProperty handleCancelTradeRequestStateProperty = new SimpleObjectProperty<>(); + transient final private ObjectProperty sellersCancelTradeStateProperty = new SimpleObjectProperty<>(); @Getter - public BuyerTrade.BuyersCancelTradeState buyersCancelTradeState; + public BuyerTrade.CancelTradeState buyersCancelTradeState; @Getter - transient final private ObjectProperty requestCancelTradeStateProperty = new SimpleObjectProperty<>(); + transient final private ObjectProperty buyersCancelTradeStateProperty = new SimpleObjectProperty<>(); /////////////////////////////////////////////////////////////////////////////////////////// @@ -574,8 +574,8 @@ public Message toProtoMessage() { Optional.ofNullable(delayedPayoutTxBytes).ifPresent(e -> builder.setDelayedPayoutTxBytes(ByteString.copyFrom(delayedPayoutTxBytes))); Optional.ofNullable(counterCurrencyExtraData).ifPresent(e -> builder.setCounterCurrencyExtraData(counterCurrencyExtraData)); Optional.ofNullable(assetTxProofResult).ifPresent(e -> builder.setAssetTxProofResult(assetTxProofResult.name())); - Optional.ofNullable(sellersCancelTradeState).ifPresent(e -> builder.setHandleCancelTradeRequestState(sellersCancelTradeState.name())); - Optional.ofNullable(buyersCancelTradeState).ifPresent(e -> builder.setRequestCancelTradeState(buyersCancelTradeState.name())); + Optional.ofNullable(sellersCancelTradeState).ifPresent(e -> builder.setSellersCancelTradeState(sellersCancelTradeState.name())); + Optional.ofNullable(buyersCancelTradeState).ifPresent(e -> builder.setBuyersCancelTradeState(buyersCancelTradeState.name())); return builder.build(); } @@ -618,8 +618,8 @@ public static Trade fromProto(Trade trade, protobuf.Trade proto, CoreProtoResolv } trade.setAssetTxProofResult(persistedAssetTxProofResult); - trade.setSellersCancelTradeState(ProtoUtil.enumFromProto(SellerTrade.SellersCancelTradeState.class, proto.getHandleCancelTradeRequestState())); - trade.setBuyersCancelTradeState(ProtoUtil.enumFromProto(BuyerTrade.BuyersCancelTradeState.class, proto.getRequestCancelTradeState())); + trade.setSellersCancelTradeState(ProtoUtil.enumFromProto(SellerTrade.CancelTradeState.class, proto.getSellersCancelTradeState())); + trade.setBuyersCancelTradeState(ProtoUtil.enumFromProto(BuyerTrade.CancelTradeState.class, proto.getBuyersCancelTradeState())); trade.chatMessages.addAll(proto.getChatMessageList().stream() .map(ChatMessage::fromPayloadProto) @@ -909,15 +909,15 @@ public void setAssetTxProofResult(@Nullable AssetTxProofResult assetTxProofResul persist(); } - public void setSellersCancelTradeState(SellerTrade.SellersCancelTradeState sellersCancelTradeState) { - this.sellersCancelTradeState = sellersCancelTradeState; - handleCancelTradeRequestStateProperty.set(sellersCancelTradeState); + public void setSellersCancelTradeState(SellerTrade.CancelTradeState cancelTradeState) { + this.sellersCancelTradeState = cancelTradeState; + sellersCancelTradeStateProperty.set(cancelTradeState); persist(); } - public void setBuyersCancelTradeState(BuyerTrade.BuyersCancelTradeState buyersCancelTradeState) { - this.buyersCancelTradeState = buyersCancelTradeState; - requestCancelTradeStateProperty.set(buyersCancelTradeState); + public void setBuyersCancelTradeState(BuyerTrade.CancelTradeState cancelTradeState) { + this.buyersCancelTradeState = cancelTradeState; + buyersCancelTradeStateProperty.set(cancelTradeState); persist(); } @@ -1257,8 +1257,8 @@ public String toString() { ",\n refundResultState=" + refundResultState + ",\n refundResultStateProperty=" + refundResultStateProperty + ",\n lastRefreshRequestDate=" + lastRefreshRequestDate + - ",\n handleCancelTradeRequestState=" + sellersCancelTradeState + - ",\n requestCancelTradeState=" + buyersCancelTradeState + + ",\n sellersCancelTradeState=" + sellersCancelTradeState + + ",\n buyersCancelTradeState=" + buyersCancelTradeState + "\n}"; } } diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java index 480d7d930ed..1612de4b128 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java @@ -45,6 +45,6 @@ protected void run() { @Override protected void setState() { - trade.setSellersCancelTradeState(SellerTrade.SellersCancelTradeState.REQUEST_ACCEPTED_PAYOUT_TX_PUBLISHED); + trade.setSellersCancelTradeState(SellerTrade.CancelTradeState.REQUEST_ACCEPTED_PAYOUT_TX_PUBLISHED); } } diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java index 8a2fe04e463..951bf2f63db 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java @@ -59,7 +59,7 @@ protected void run() { trade.setPayoutTx(committedCanceledTradePayoutTx); BtcWalletService.printTx("CanceledTradePayoutTx received from peer", committedCanceledTradePayoutTx); - trade.setBuyersCancelTradeState(BuyerTrade.BuyersCancelTradeState.RECEIVED_ACCEPTED_MSG); + trade.setBuyersCancelTradeState(BuyerTrade.CancelTradeState.RECEIVED_ACCEPTED_MSG); // We need to delay that call as we might get executed at startup after mailbox messages are // applied where we iterate over our pending trades. The closeCanceledTrade method would remove diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java index d04b288ba65..a8bedf7c3e1 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java @@ -46,7 +46,7 @@ protected void run() { // update to the latest peer address of our peer if the message is correct trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress()); - trade.setBuyersCancelTradeState(BuyerTrade.BuyersCancelTradeState.RECEIVED_REJECTED_MSG); + trade.setBuyersCancelTradeState(BuyerTrade.CancelTradeState.RECEIVED_REJECTED_MSG); processModel.removeMailboxMessageAfterProcessing(trade); complete(); } catch (Throwable t) { diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java index e87f5e1dd60..54e44588ea0 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java @@ -50,7 +50,7 @@ protected void run() { trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress()); processModel.removeMailboxMessageAfterProcessing(trade); - trade.setSellersCancelTradeState(SellerTrade.SellersCancelTradeState.RECEIVED_REQUEST); + trade.setSellersCancelTradeState(SellerTrade.CancelTradeState.RECEIVED_REQUEST); complete(); } catch (Throwable t) { diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java index 7c5cc3e1b6c..7a2ab0c70f5 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java @@ -54,22 +54,22 @@ protected TradeMessage getMessage(String id) { @Override protected void setStateSent() { - trade.setSellersCancelTradeState(SellerTrade.SellersCancelTradeState.REQUEST_ACCEPTED_MSG_SENT); + trade.setSellersCancelTradeState(SellerTrade.CancelTradeState.REQUEST_ACCEPTED_MSG_SENT); } @Override protected void setStateArrived() { - trade.setSellersCancelTradeState(SellerTrade.SellersCancelTradeState.REQUEST_ACCEPTED_MSG_ARRIVED); + trade.setSellersCancelTradeState(SellerTrade.CancelTradeState.REQUEST_ACCEPTED_MSG_ARRIVED); } @Override protected void setStateStoredInMailbox() { - trade.setSellersCancelTradeState(SellerTrade.SellersCancelTradeState.REQUEST_ACCEPTED_MSG_IN_MAILBOX); + trade.setSellersCancelTradeState(SellerTrade.CancelTradeState.REQUEST_ACCEPTED_MSG_IN_MAILBOX); } @Override protected void setStateFault() { - trade.setSellersCancelTradeState(SellerTrade.SellersCancelTradeState.REQUEST_ACCEPTED_MSG_SEND_FAILED); + trade.setSellersCancelTradeState(SellerTrade.CancelTradeState.REQUEST_ACCEPTED_MSG_SEND_FAILED); } @Override diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java index 44f5940967d..c43f0baece1 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java @@ -48,22 +48,22 @@ protected TradeMessage getMessage(String id) { @Override protected void setStateSent() { - trade.setSellersCancelTradeState(SellerTrade.SellersCancelTradeState.REQUEST_REJECTED_MSG_SENT); + trade.setSellersCancelTradeState(SellerTrade.CancelTradeState.REQUEST_REJECTED_MSG_SENT); } @Override protected void setStateArrived() { - trade.setSellersCancelTradeState(SellerTrade.SellersCancelTradeState.REQUEST_REJECTED_MSG_ARRIVED); + trade.setSellersCancelTradeState(SellerTrade.CancelTradeState.REQUEST_REJECTED_MSG_ARRIVED); } @Override protected void setStateStoredInMailbox() { - trade.setSellersCancelTradeState(SellerTrade.SellersCancelTradeState.REQUEST_REJECTED_MSG_IN_MAILBOX); + trade.setSellersCancelTradeState(SellerTrade.CancelTradeState.REQUEST_REJECTED_MSG_IN_MAILBOX); } @Override protected void setStateFault() { - trade.setSellersCancelTradeState(SellerTrade.SellersCancelTradeState.REQUEST_REJECTED_MSG_SEND_FAILED); + trade.setSellersCancelTradeState(SellerTrade.CancelTradeState.REQUEST_REJECTED_MSG_SEND_FAILED); } @Override diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java index f43205cc2fe..1a0604d2223 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java @@ -61,22 +61,22 @@ protected TradeMessage getMessage(String id) { @Override protected void setStateSent() { - trade.setBuyersCancelTradeState(BuyerTrade.BuyersCancelTradeState.REQUEST_MSG_SENT); + trade.setBuyersCancelTradeState(BuyerTrade.CancelTradeState.REQUEST_MSG_SENT); } @Override protected void setStateArrived() { - trade.setBuyersCancelTradeState(BuyerTrade.BuyersCancelTradeState.REQUEST_MSG_ARRIVED); + trade.setBuyersCancelTradeState(BuyerTrade.CancelTradeState.REQUEST_MSG_ARRIVED); } @Override protected void setStateStoredInMailbox() { - trade.setBuyersCancelTradeState(BuyerTrade.BuyersCancelTradeState.REQUEST_MSG_IN_MAILBOX); + trade.setBuyersCancelTradeState(BuyerTrade.CancelTradeState.REQUEST_MSG_IN_MAILBOX); } @Override protected void setStateFault() { - trade.setBuyersCancelTradeState(BuyerTrade.BuyersCancelTradeState.REQUEST_MSG_SEND_FAILED); + trade.setBuyersCancelTradeState(BuyerTrade.CancelTradeState.REQUEST_MSG_SEND_FAILED); } @Override diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java index 34eac5a2ad7..d8cae22d382 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java @@ -47,7 +47,7 @@ protected void run() { @Override protected void setState() { - trade.setBuyersCancelTradeState(BuyerTrade.BuyersCancelTradeState.PAYOUT_TX_SEEN_IN_NETWORK); + trade.setBuyersCancelTradeState(BuyerTrade.CancelTradeState.PAYOUT_TX_SEEN_IN_NETWORK); if (trade.getPayoutTx() != null) { // We need to delay that call as we might get executed at startup after mailbox messages are // applied where we iterate over our pending trades. The closeCanceledTrade method would remove diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java index 8f833b531ee..f7934b9aad2 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java @@ -48,7 +48,7 @@ public class BuyerRequestCancelTradePresentation { private Button cancelTradeButton; private Label msgSentStatusLabel; private BusyAnimation msgSentBusyAnimation; - private ChangeListener listener; + private ChangeListener listener; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor @@ -82,13 +82,13 @@ public void initialize(HBox hBox, } public void activate() { - trade.getRequestCancelTradeStateProperty().addListener(listener); - onStateChanged(trade.getRequestCancelTradeStateProperty().get()); + trade.getBuyersCancelTradeStateProperty().addListener(listener); + onStateChanged(trade.getBuyersCancelTradeStateProperty().get()); } public void deactivate() { if (listener != null) { - trade.getRequestCancelTradeStateProperty().removeListener(listener); + trade.getBuyersCancelTradeStateProperty().removeListener(listener); } } @@ -136,7 +136,7 @@ private void doRequestCancelTrade() { } - private void onStateChanged(BuyerTrade.BuyersCancelTradeState state) { + private void onStateChanged(BuyerTrade.CancelTradeState state) { log.error("onCanceledTradeStateChanged {} {}", state, trade.getId()); msgSentBusyAnimation.stop(); msgSentStatusLabel.setText(""); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java index 896083b20a3..cbe021a677d 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java @@ -39,7 +39,7 @@ public class SellerHandleCancelTradeRequestPresentation { private final Trade trade; private final TradeCancellationManager manager; private final CoinFormatter formatter; - private ChangeListener listener; + private ChangeListener listener; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor @@ -63,13 +63,13 @@ public void initialize() { } public void activate() { - trade.getHandleCancelTradeRequestStateProperty().addListener(listener); - onStateChanged(trade.getHandleCancelTradeRequestStateProperty().get()); + trade.getSellersCancelTradeStateProperty().addListener(listener); + onStateChanged(trade.getSellersCancelTradeStateProperty().get()); } public void deactivate() { if (listener != null) { - trade.getHandleCancelTradeRequestStateProperty().removeListener(listener); + trade.getSellersCancelTradeStateProperty().removeListener(listener); } } @@ -102,7 +102,7 @@ private void onRejectRequest() { // Private /////////////////////////////////////////////////////////////////////////////////////////// - private void onStateChanged(SellerTrade.SellersCancelTradeState newValue) { + private void onStateChanged(SellerTrade.CancelTradeState newValue) { log.error("onRequestCancelTradeStateChanged {} {}", newValue, trade.getId()); if (newValue == null) { return; diff --git a/proto/src/main/proto/pb.proto b/proto/src/main/proto/pb.proto index 5a517a1ed87..f4ec5a5654f 100644 --- a/proto/src/main/proto/pb.proto +++ b/proto/src/main/proto/pb.proto @@ -1421,8 +1421,8 @@ message Trade { int64 last_refresh_request_date = 36; string counter_currency_extra_data = 37; string asset_tx_proof_result = 38; // name of AssetTxProofResult enum - string handle_cancel_trade_request_state = 39; - string request_cancel_trade_state = 40; + string sellers_cancel_trade_state = 39; + string buyers_cancel_trade_state = 40; } message BuyerAsMakerTrade { From a134c74366d15ac7dd5630a369b8a58259ec3ba5 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 10:05:35 -0500 Subject: [PATCH 22/56] Split buyer seller protocol classes. Add delegate protocol for cancel trade --- .../core/trade/TradeCancellationManager.java | 73 ++++---- .../trade/protocol/BuyerAsMakerProtocol.java | 5 + .../trade/protocol/BuyerAsTakerProtocol.java | 4 + .../protocol/BuyersCancelTradeProtocol.java | 122 +++++++++++++ .../trade/protocol/CancelTradeProtocol.java | 57 ++++++ .../trade/protocol/SellerAsMakerProtocol.java | 5 + .../trade/protocol/SellerAsTakerProtocol.java | 5 + .../protocol/SellersCancelTradeProtocol.java | 131 ++++++++++++++ .../core/trade/protocol/TradeProtocol.java | 166 ++---------------- ...cessCancelTradeRequestAcceptedMessage.java | 2 +- ...cessCancelTradeRequestRejectedMessage.java | 2 +- .../cancel/SendRequestCancelTradeMessage.java | 2 +- .../SetupCanceledTradePayoutTxListener.java | 2 +- .../BroadcastCanceledTradePayoutTx.java | 2 +- .../cancel/FinalizeCanceledTradePayoutTx.java | 2 +- .../ProcessRequestCancelTradeMessage.java | 2 +- ...SendCancelTradeRequestAcceptedMessage.java | 2 +- ...SendCancelTradeRequestRejectedMessage.java | 2 +- .../BuyerRequestCancelTradePresentation.java | 2 +- ...rHandleCancelTradeRequestPresentation.java | 4 +- 20 files changed, 399 insertions(+), 193 deletions(-) create mode 100644 core/src/main/java/bisq/core/trade/protocol/BuyersCancelTradeProtocol.java create mode 100644 core/src/main/java/bisq/core/trade/protocol/CancelTradeProtocol.java create mode 100644 core/src/main/java/bisq/core/trade/protocol/SellersCancelTradeProtocol.java rename core/src/main/java/bisq/core/trade/protocol/tasks/{ => buyer}/cancel/ProcessCancelTradeRequestAcceptedMessage.java (98%) rename core/src/main/java/bisq/core/trade/protocol/tasks/{ => buyer}/cancel/ProcessCancelTradeRequestRejectedMessage.java (97%) rename core/src/main/java/bisq/core/trade/protocol/tasks/{ => buyer}/cancel/SendRequestCancelTradeMessage.java (98%) rename core/src/main/java/bisq/core/trade/protocol/tasks/{ => buyer}/cancel/SetupCanceledTradePayoutTxListener.java (97%) rename core/src/main/java/bisq/core/trade/protocol/tasks/{ => seller}/cancel/BroadcastCanceledTradePayoutTx.java (96%) rename core/src/main/java/bisq/core/trade/protocol/tasks/{ => seller}/cancel/FinalizeCanceledTradePayoutTx.java (99%) rename core/src/main/java/bisq/core/trade/protocol/tasks/{ => seller}/cancel/ProcessRequestCancelTradeMessage.java (97%) rename core/src/main/java/bisq/core/trade/protocol/tasks/{ => seller}/cancel/SendCancelTradeRequestAcceptedMessage.java (98%) rename core/src/main/java/bisq/core/trade/protocol/tasks/{ => seller}/cancel/SendCancelTradeRequestRejectedMessage.java (97%) diff --git a/core/src/main/java/bisq/core/trade/TradeCancellationManager.java b/core/src/main/java/bisq/core/trade/TradeCancellationManager.java index 65749af58cc..335c0d6254a 100644 --- a/core/src/main/java/bisq/core/trade/TradeCancellationManager.java +++ b/core/src/main/java/bisq/core/trade/TradeCancellationManager.java @@ -19,7 +19,9 @@ import bisq.core.btc.wallet.Restrictions; import bisq.core.offer.Offer; +import bisq.core.trade.protocol.BuyersCancelTradeProtocol; import bisq.core.trade.protocol.ProcessModel; +import bisq.core.trade.protocol.SellersCancelTradeProtocol; import bisq.common.handlers.ErrorMessageHandler; import bisq.common.handlers.ResultHandler; @@ -47,12 +49,13 @@ public TradeCancellationManager() { /////////////////////////////////////////////////////////////////////////////////////////// - // API + // UI handlers /////////////////////////////////////////////////////////////////////////////////////////// - public void requestCancelTrade(Trade trade, - ResultHandler resultHandler, - ErrorMessageHandler errorMessageHandler) { + // Buyer + public void onRequestCancelTrade(Trade trade, + ResultHandler resultHandler, + ErrorMessageHandler errorMessageHandler) { ProcessModel processModel = trade.getProcessModel(); Offer offer = checkNotNull(trade.getOffer()); Coin secDepositOfRequester = getSecurityDepositForRequester(); @@ -66,9 +69,44 @@ public void requestCancelTrade(Trade trade, processModel.setBuyerPayoutAmountFromCanceledTrade(secDepositForForPeer.value); processModel.setSellerPayoutAmountFromCanceledTrade(tradeAmount.add(secDepositOfRequester).value); } - trade.getTradeProtocol().onRequestCancelTrade(resultHandler, errorMessageHandler); + BuyersCancelTradeProtocol buyersCancelTradeProtocol = (BuyersCancelTradeProtocol) (trade.getTradeProtocol().getCancelTradeProtocol()); + buyersCancelTradeProtocol.onRequestCancelTrade(resultHandler, errorMessageHandler); } + + // Seller + public void onAcceptRequest(Trade trade, + ResultHandler resultHandler, + ErrorMessageHandler errorMessageHandler) { + ProcessModel processModel = trade.getProcessModel(); + Offer offer = checkNotNull(trade.getOffer()); + Coin secDepositOfRequester = getSecurityDepositForRequester(); + Coin totalSecDeposit = offer.getSellerSecurityDeposit().add(offer.getBuyerSecurityDeposit()); + Coin secDepositOfAcceptingTrader = totalSecDeposit.subtract(secDepositOfRequester); + Coin tradeAmount = checkNotNull(trade.getTradeAmount(), "tradeAmount must not be null"); + if (trade instanceof BuyerTrade) { + processModel.setBuyerPayoutAmountFromCanceledTrade(secDepositOfAcceptingTrader.value); + processModel.setSellerPayoutAmountFromCanceledTrade(tradeAmount.add(secDepositOfRequester).value); + } else { + processModel.setBuyerPayoutAmountFromCanceledTrade(secDepositOfRequester.value); + processModel.setSellerPayoutAmountFromCanceledTrade(tradeAmount.add(secDepositOfAcceptingTrader).value); + } + SellersCancelTradeProtocol sellersCancelTradeProtocol = (SellersCancelTradeProtocol) (trade.getTradeProtocol().getCancelTradeProtocol()); + sellersCancelTradeProtocol.onAcceptRequest(resultHandler, errorMessageHandler); + } + + public void onRejectRequest(Trade trade, + ResultHandler resultHandler, + ErrorMessageHandler errorMessageHandler) { + SellersCancelTradeProtocol sellersCancelTradeProtocol = (SellersCancelTradeProtocol) (trade.getTradeProtocol().getCancelTradeProtocol()); + sellersCancelTradeProtocol.onRejectRequest(resultHandler, errorMessageHandler); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Utils + /////////////////////////////////////////////////////////////////////////////////////////// + public Coin getSecurityDepositForRequester() { return Restrictions.getMinRefundAtMediatedDispute(); } @@ -89,29 +127,4 @@ public Coin getLostSecDepositOfRequestingTrader(Trade trade) { Offer offer = checkNotNull(trade.getOffer()); return getTotalSecDepositForAcceptingTrader(offer).subtract(getDefaultSecDepositOfAcceptingTrader(trade)); } - - public void acceptRequest(Trade trade, - ResultHandler resultHandler, - ErrorMessageHandler errorMessageHandler) { - ProcessModel processModel = trade.getProcessModel(); - Offer offer = checkNotNull(trade.getOffer()); - Coin secDepositOfRequester = getSecurityDepositForRequester(); - Coin totalSecDeposit = offer.getSellerSecurityDeposit().add(offer.getBuyerSecurityDeposit()); - Coin secDepositOfAcceptingTrader = totalSecDeposit.subtract(secDepositOfRequester); - Coin tradeAmount = checkNotNull(trade.getTradeAmount(), "tradeAmount must not be null"); - if (trade instanceof BuyerTrade) { - processModel.setBuyerPayoutAmountFromCanceledTrade(secDepositOfAcceptingTrader.value); - processModel.setSellerPayoutAmountFromCanceledTrade(tradeAmount.add(secDepositOfRequester).value); - } else { - processModel.setBuyerPayoutAmountFromCanceledTrade(secDepositOfRequester.value); - processModel.setSellerPayoutAmountFromCanceledTrade(tradeAmount.add(secDepositOfAcceptingTrader).value); - } - trade.getTradeProtocol().onAcceptCancelTradeRequest(resultHandler, errorMessageHandler); - } - - public void rejectRequest(Trade trade, - ResultHandler resultHandler, - ErrorMessageHandler errorMessageHandler) { - trade.getTradeProtocol().onRejectCancelTradeRequest(resultHandler, errorMessageHandler); - } } diff --git a/core/src/main/java/bisq/core/trade/protocol/BuyerAsMakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/BuyerAsMakerProtocol.java index 6f475f6734e..dde9e2420b4 100644 --- a/core/src/main/java/bisq/core/trade/protocol/BuyerAsMakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/BuyerAsMakerProtocol.java @@ -89,6 +89,11 @@ public BuyerAsMakerProtocol(BuyerAsMakerTrade trade) { } } + @Override + protected BuyersCancelTradeProtocol createCancelTradeProtocol() { + return new BuyersCancelTradeProtocol(trade); + } + /////////////////////////////////////////////////////////////////////////////////////////// // Mailbox diff --git a/core/src/main/java/bisq/core/trade/protocol/BuyerAsTakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/BuyerAsTakerProtocol.java index 4d17d4c47fa..c200de343f5 100644 --- a/core/src/main/java/bisq/core/trade/protocol/BuyerAsTakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/BuyerAsTakerProtocol.java @@ -97,6 +97,10 @@ public BuyerAsTakerProtocol(BuyerAsTakerTrade trade) { } } + @Override + protected BuyersCancelTradeProtocol createCancelTradeProtocol() { + return new BuyersCancelTradeProtocol(trade); + } /////////////////////////////////////////////////////////////////////////////////////////// // Mailbox diff --git a/core/src/main/java/bisq/core/trade/protocol/BuyersCancelTradeProtocol.java b/core/src/main/java/bisq/core/trade/protocol/BuyersCancelTradeProtocol.java new file mode 100644 index 00000000000..658349f81ab --- /dev/null +++ b/core/src/main/java/bisq/core/trade/protocol/BuyersCancelTradeProtocol.java @@ -0,0 +1,122 @@ +/* + * This file is part of Bisq. + * + * Bisq 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. + * + * Bisq 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 Bisq. If not, see . + */ + +package bisq.core.trade.protocol; + +import bisq.core.trade.Trade; +import bisq.core.trade.messages.CancelTradeRequestAcceptedMessage; +import bisq.core.trade.messages.CancelTradeRequestRejectedMessage; +import bisq.core.trade.messages.TradeMessage; +import bisq.core.trade.protocol.tasks.ApplyFilter; +import bisq.core.trade.protocol.tasks.buyer.cancel.ProcessCancelTradeRequestAcceptedMessage; +import bisq.core.trade.protocol.tasks.buyer.cancel.ProcessCancelTradeRequestRejectedMessage; +import bisq.core.trade.protocol.tasks.buyer.cancel.SendRequestCancelTradeMessage; +import bisq.core.trade.protocol.tasks.buyer.cancel.SetupCanceledTradePayoutTxListener; +import bisq.core.trade.protocol.tasks.cancel.SignCanceledTradePayoutTx; + +import bisq.network.p2p.NodeAddress; + +import bisq.common.handlers.ErrorMessageHandler; +import bisq.common.handlers.ResultHandler; + +public class BuyersCancelTradeProtocol extends CancelTradeProtocol { + + BuyersCancelTradeProtocol(Trade trade) { + super(trade); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // User intent + /////////////////////////////////////////////////////////////////////////////////////////// + + public void onRequestCancelTrade(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { + TradeTaskRunner taskRunner = new TradeTaskRunner(trade, + () -> { + resultHandler.handleResult(); + handleTaskRunnerSuccess("onRequestCancelTrade"); + }, + (errorMessage) -> { + errorMessageHandler.handleErrorMessage(errorMessage); + handleTaskRunnerFault(errorMessage); + }); + taskRunner.addTasks( + ApplyFilter.class, + SignCanceledTradePayoutTx.class, + SendRequestCancelTradeMessage.class, + SetupCanceledTradePayoutTxListener.class + ); + taskRunner.run(); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Incoming message handling + /////////////////////////////////////////////////////////////////////////////////////////// + + protected void handle(CancelTradeRequestAcceptedMessage tradeMessage, NodeAddress sender) { + trade.getProcessModel().setTradeMessage(tradeMessage); + trade.getProcessModel().setTempTradingPeerNodeAddress(sender); + + TradeTaskRunner taskRunner = new TradeTaskRunner(trade, + () -> handleTaskRunnerSuccess(tradeMessage, "handle CancelTradeRequestAcceptedMessage"), + errorMessage -> handleTaskRunnerFault(tradeMessage, errorMessage)); + + taskRunner.addTasks( + ProcessCancelTradeRequestAcceptedMessage.class + ); + taskRunner.run(); + } + + + protected void handle(CancelTradeRequestRejectedMessage tradeMessage, NodeAddress sender) { + trade.getProcessModel().setTradeMessage(tradeMessage); + trade.getProcessModel().setTempTradingPeerNodeAddress(sender); + + TradeTaskRunner taskRunner = new TradeTaskRunner(trade, + () -> handleTaskRunnerSuccess(tradeMessage, "handle CancelTradeRequestRejectedMessage"), + errorMessage -> handleTaskRunnerFault(tradeMessage, errorMessage)); + + taskRunner.addTasks( + ProcessCancelTradeRequestRejectedMessage.class + ); + taskRunner.run(); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Dispatcher + /////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public void doHandleDecryptedMessage(TradeMessage tradeMessage, NodeAddress sender) { + if (tradeMessage instanceof CancelTradeRequestAcceptedMessage) { + handle((CancelTradeRequestAcceptedMessage) tradeMessage, sender); + } else if (tradeMessage instanceof CancelTradeRequestRejectedMessage) { + handle((CancelTradeRequestRejectedMessage) tradeMessage, sender); + } + } + + @Override + public void doApplyMailboxTradeMessage(TradeMessage tradeMessage, NodeAddress peerNodeAddress) { + if (tradeMessage instanceof CancelTradeRequestAcceptedMessage) { + handle((CancelTradeRequestAcceptedMessage) tradeMessage, peerNodeAddress); + } else if (tradeMessage instanceof CancelTradeRequestRejectedMessage) { + handle((CancelTradeRequestRejectedMessage) tradeMessage, peerNodeAddress); + } + } +} diff --git a/core/src/main/java/bisq/core/trade/protocol/CancelTradeProtocol.java b/core/src/main/java/bisq/core/trade/protocol/CancelTradeProtocol.java new file mode 100644 index 00000000000..638461e9639 --- /dev/null +++ b/core/src/main/java/bisq/core/trade/protocol/CancelTradeProtocol.java @@ -0,0 +1,57 @@ +/* + * This file is part of Bisq. + * + * Bisq 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. + * + * Bisq 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 Bisq. If not, see . + */ + +package bisq.core.trade.protocol; + +import bisq.core.trade.Trade; +import bisq.core.trade.messages.TradeMessage; + +import bisq.network.p2p.NodeAddress; + +public abstract class CancelTradeProtocol { + protected final Trade trade; + + protected CancelTradeProtocol(Trade trade) { + this.trade = trade; + } + + abstract void doHandleDecryptedMessage(TradeMessage tradeMessage, NodeAddress sender); + + abstract void doApplyMailboxTradeMessage(TradeMessage tradeMessage, NodeAddress peerNodeAddress); + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Delegates + /////////////////////////////////////////////////////////////////////////////////////////// + + protected void handleTaskRunnerSuccess(TradeMessage tradeMessage, + String info) { + trade.getTradeProtocol().handleTaskRunnerSuccess(tradeMessage, info); + } + + protected void handleTaskRunnerSuccess(String info) { + trade.getTradeProtocol().handleTaskRunnerSuccess(info); + } + + protected void handleTaskRunnerFault(TradeMessage tradeMessage, String errorMessage) { + trade.getTradeProtocol().handleTaskRunnerFault(tradeMessage, errorMessage); + } + + protected void handleTaskRunnerFault(String errorMessage) { + trade.getTradeProtocol().handleTaskRunnerFault(errorMessage); + } +} diff --git a/core/src/main/java/bisq/core/trade/protocol/SellerAsMakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/SellerAsMakerProtocol.java index 29ecde1c005..1859adce905 100644 --- a/core/src/main/java/bisq/core/trade/protocol/SellerAsMakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/SellerAsMakerProtocol.java @@ -83,6 +83,11 @@ public SellerAsMakerProtocol(SellerAsMakerTrade trade) { } } + @Override + protected SellersCancelTradeProtocol createCancelTradeProtocol() { + return new SellersCancelTradeProtocol(trade); + } + /////////////////////////////////////////////////////////////////////////////////////////// // Mailbox diff --git a/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java index 8979a61b28c..965486ef8d5 100644 --- a/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java @@ -77,6 +77,11 @@ public SellerAsTakerProtocol(SellerAsTakerTrade trade) { processModel.getTradingPeer().setPubKeyRing(offer.getPubKeyRing()); } + @Override + protected SellersCancelTradeProtocol createCancelTradeProtocol() { + return new SellersCancelTradeProtocol(trade); + } + /////////////////////////////////////////////////////////////////////////////////////////// // Mailbox diff --git a/core/src/main/java/bisq/core/trade/protocol/SellersCancelTradeProtocol.java b/core/src/main/java/bisq/core/trade/protocol/SellersCancelTradeProtocol.java new file mode 100644 index 00000000000..470fe081332 --- /dev/null +++ b/core/src/main/java/bisq/core/trade/protocol/SellersCancelTradeProtocol.java @@ -0,0 +1,131 @@ +/* + * This file is part of Bisq. + * + * Bisq 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. + * + * Bisq 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 Bisq. If not, see . + */ + +package bisq.core.trade.protocol; + +import bisq.core.trade.Trade; +import bisq.core.trade.messages.RequestCancelTradeMessage; +import bisq.core.trade.messages.TradeMessage; +import bisq.core.trade.protocol.tasks.ApplyFilter; +import bisq.core.trade.protocol.tasks.cancel.SignCanceledTradePayoutTx; +import bisq.core.trade.protocol.tasks.seller.cancel.BroadcastCanceledTradePayoutTx; +import bisq.core.trade.protocol.tasks.seller.cancel.FinalizeCanceledTradePayoutTx; +import bisq.core.trade.protocol.tasks.seller.cancel.ProcessRequestCancelTradeMessage; +import bisq.core.trade.protocol.tasks.seller.cancel.SendCancelTradeRequestAcceptedMessage; +import bisq.core.trade.protocol.tasks.seller.cancel.SendCancelTradeRequestRejectedMessage; + +import bisq.network.p2p.NodeAddress; + +import bisq.common.handlers.ErrorMessageHandler; +import bisq.common.handlers.ResultHandler; + +public class SellersCancelTradeProtocol extends CancelTradeProtocol { + + SellersCancelTradeProtocol(Trade trade) { + super(trade); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // User intent + /////////////////////////////////////////////////////////////////////////////////////////// + + public void onAcceptRequest(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { + if (trade.getPayoutTx() != null) { + errorMessageHandler.handleErrorMessage("Payout tx is already published."); + return; + } + + TradeTaskRunner taskRunner = new TradeTaskRunner(trade, + () -> { + resultHandler.handleResult(); + handleTaskRunnerSuccess("onAcceptCancelTradeRequest"); + }, + (errorMessage) -> { + errorMessageHandler.handleErrorMessage(errorMessage); + handleTaskRunnerFault(errorMessage); + }); + taskRunner.addTasks( + ApplyFilter.class, + SignCanceledTradePayoutTx.class, + FinalizeCanceledTradePayoutTx.class, + BroadcastCanceledTradePayoutTx.class, + SendCancelTradeRequestAcceptedMessage.class + ); + taskRunner.run(); + } + + public void onRejectRequest(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { + if (trade.getPayoutTx() != null) { + errorMessageHandler.handleErrorMessage("Payout tx is already published."); + return; + } + + TradeTaskRunner taskRunner = new TradeTaskRunner(trade, + () -> { + resultHandler.handleResult(); + handleTaskRunnerSuccess("onRejectCancelTradeRequest"); + }, + (errorMessage) -> { + errorMessageHandler.handleErrorMessage(errorMessage); + handleTaskRunnerFault(errorMessage); + }); + taskRunner.addTasks( + ApplyFilter.class, + SendCancelTradeRequestRejectedMessage.class + ); + taskRunner.run(); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Incoming message handling + /////////////////////////////////////////////////////////////////////////////////////////// + + protected void handle(RequestCancelTradeMessage tradeMessage, NodeAddress sender) { + trade.getProcessModel().setTradeMessage(tradeMessage); + trade.getProcessModel().setTempTradingPeerNodeAddress(sender); + + TradeTaskRunner taskRunner = new TradeTaskRunner(trade, + () -> handleTaskRunnerSuccess(tradeMessage, "handle RequestCancelTradeMessage"), + errorMessage -> handleTaskRunnerFault(tradeMessage, errorMessage)); + + taskRunner.addTasks( + ProcessRequestCancelTradeMessage.class + ); + taskRunner.run(); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Dispatcher + /////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public void doHandleDecryptedMessage(TradeMessage tradeMessage, NodeAddress sender) { + if (tradeMessage instanceof RequestCancelTradeMessage) { + handle((RequestCancelTradeMessage) tradeMessage, sender); + } + } + + @Override + public void doApplyMailboxTradeMessage(TradeMessage tradeMessage, NodeAddress peerNodeAddress) { + if (tradeMessage instanceof RequestCancelTradeMessage) { + handle((RequestCancelTradeMessage) tradeMessage, peerNodeAddress); + } + } +} diff --git a/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java b/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java index b7606aa1f10..e81e727f031 100644 --- a/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java @@ -20,28 +20,15 @@ import bisq.core.trade.MakerTrade; import bisq.core.trade.Trade; import bisq.core.trade.TradeManager; -import bisq.core.trade.messages.CancelTradeRequestAcceptedMessage; -import bisq.core.trade.messages.CancelTradeRequestRejectedMessage; import bisq.core.trade.messages.CounterCurrencyTransferStartedMessage; import bisq.core.trade.messages.InputsForDepositTxRequest; import bisq.core.trade.messages.MediatedPayoutTxPublishedMessage; import bisq.core.trade.messages.MediatedPayoutTxSignatureMessage; import bisq.core.trade.messages.PeerPublishedDelayedPayoutTxMessage; -import bisq.core.trade.messages.RequestCancelTradeMessage; import bisq.core.trade.messages.TradeMessage; import bisq.core.trade.messages.TraderSignedWitnessMessage; import bisq.core.trade.protocol.tasks.ApplyFilter; import bisq.core.trade.protocol.tasks.ProcessPeerPublishedDelayedPayoutTxMessage; -import bisq.core.trade.protocol.tasks.cancel.BroadcastCanceledTradePayoutTx; -import bisq.core.trade.protocol.tasks.cancel.FinalizeCanceledTradePayoutTx; -import bisq.core.trade.protocol.tasks.cancel.ProcessCancelTradeRequestAcceptedMessage; -import bisq.core.trade.protocol.tasks.cancel.ProcessCancelTradeRequestRejectedMessage; -import bisq.core.trade.protocol.tasks.cancel.ProcessRequestCancelTradeMessage; -import bisq.core.trade.protocol.tasks.cancel.SendCancelTradeRequestAcceptedMessage; -import bisq.core.trade.protocol.tasks.cancel.SendCancelTradeRequestRejectedMessage; -import bisq.core.trade.protocol.tasks.cancel.SendRequestCancelTradeMessage; -import bisq.core.trade.protocol.tasks.cancel.SetupCanceledTradePayoutTxListener; -import bisq.core.trade.protocol.tasks.cancel.SignCanceledTradePayoutTx; import bisq.core.trade.protocol.tasks.mediation.BroadcastMediatedPayoutTx; import bisq.core.trade.protocol.tasks.mediation.FinalizeMediatedPayoutTx; import bisq.core.trade.protocol.tasks.mediation.ProcessMediatedPayoutSignatureMessage; @@ -70,6 +57,7 @@ import java.security.PublicKey; +import lombok.Getter; import lombok.extern.slf4j.Slf4j; import javax.annotation.Nullable; @@ -86,10 +74,14 @@ public abstract class TradeProtocol { private final ChangeListener stateChangeListener; protected Trade trade; private Timer timeoutTimer; + @Getter + private final CancelTradeProtocol cancelTradeProtocol; + public TradeProtocol(Trade trade) { this.trade = trade; this.processModel = trade.getProcessModel(); + cancelTradeProtocol = createCancelTradeProtocol(); decryptedDirectMessageListener = (decryptedMessageWithPubKey, peersNodeAddress) -> { // We check the sig only as soon we have stored the peers pubKeyRing. @@ -132,6 +124,8 @@ public TradeProtocol(Trade trade) { trade.stateProperty().addListener(stateChangeListener); } + protected abstract CancelTradeProtocol createCancelTradeProtocol(); + /////////////////////////////////////////////////////////////////////////////////////////// // Mediation: Called from UI if trader accepts mediation result @@ -223,128 +217,6 @@ protected void handle(MediatedPayoutTxPublishedMessage tradeMessage, NodeAddress } - /////////////////////////////////////////////////////////////////////////////////////////// - // Cancel trade: Called from UI if trader requests cancellation - /////////////////////////////////////////////////////////////////////////////////////////// - - // Trader request a cancellation and sends signature - public void onRequestCancelTrade(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { - TradeTaskRunner taskRunner = new TradeTaskRunner(trade, - () -> { - resultHandler.handleResult(); - handleTaskRunnerSuccess("onRequestCancelTrade"); - }, - (errorMessage) -> { - errorMessageHandler.handleErrorMessage(errorMessage); - handleTaskRunnerFault(errorMessage); - }); - taskRunner.addTasks( - ApplyFilter.class, - SignCanceledTradePayoutTx.class, - SendRequestCancelTradeMessage.class, - SetupCanceledTradePayoutTxListener.class - ); - taskRunner.run(); - } - - - // Peer has received a cancel request and accept the request and creates the payout tx. - public void onAcceptCancelTradeRequest(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { - if (trade.getPayoutTx() != null) { - errorMessageHandler.handleErrorMessage("Payout tx is already published."); - return; - } - - TradeTaskRunner taskRunner = new TradeTaskRunner(trade, - () -> { - resultHandler.handleResult(); - handleTaskRunnerSuccess("onAcceptCancelTradeRequest"); - }, - (errorMessage) -> { - errorMessageHandler.handleErrorMessage(errorMessage); - handleTaskRunnerFault(errorMessage); - }); - taskRunner.addTasks( - ApplyFilter.class, - SignCanceledTradePayoutTx.class, - FinalizeCanceledTradePayoutTx.class, - BroadcastCanceledTradePayoutTx.class, - SendCancelTradeRequestAcceptedMessage.class - ); - taskRunner.run(); - } - - // Trader has rejected the request. - public void onRejectCancelTradeRequest(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { - if (trade.getPayoutTx() != null) { - errorMessageHandler.handleErrorMessage("Payout tx is already published."); - return; - } - - TradeTaskRunner taskRunner = new TradeTaskRunner(trade, - () -> { - resultHandler.handleResult(); - handleTaskRunnerSuccess("onRejectCancelTradeRequest"); - }, - (errorMessage) -> { - errorMessageHandler.handleErrorMessage(errorMessage); - handleTaskRunnerFault(errorMessage); - }); - taskRunner.addTasks( - ApplyFilter.class, - SendCancelTradeRequestRejectedMessage.class - ); - taskRunner.run(); - } - - - /////////////////////////////////////////////////////////////////////////////////////////// - // Cancel trade: incoming message - /////////////////////////////////////////////////////////////////////////////////////////// - - protected void handle(RequestCancelTradeMessage tradeMessage, NodeAddress sender) { - processModel.setTradeMessage(tradeMessage); - processModel.setTempTradingPeerNodeAddress(sender); - - TradeTaskRunner taskRunner = new TradeTaskRunner(trade, - () -> handleTaskRunnerSuccess(tradeMessage, "handle RequestCancelTradeMessage"), - errorMessage -> handleTaskRunnerFault(tradeMessage, errorMessage)); - - taskRunner.addTasks( - ProcessRequestCancelTradeMessage.class - ); - taskRunner.run(); - } - - protected void handle(CancelTradeRequestAcceptedMessage tradeMessage, NodeAddress sender) { - processModel.setTradeMessage(tradeMessage); - processModel.setTempTradingPeerNodeAddress(sender); - - TradeTaskRunner taskRunner = new TradeTaskRunner(trade, - () -> handleTaskRunnerSuccess(tradeMessage, "handle CancelTradeRequestAcceptedMessage"), - errorMessage -> handleTaskRunnerFault(tradeMessage, errorMessage)); - - taskRunner.addTasks( - ProcessCancelTradeRequestAcceptedMessage.class - ); - taskRunner.run(); - } - - protected void handle(CancelTradeRequestRejectedMessage tradeMessage, NodeAddress sender) { - processModel.setTradeMessage(tradeMessage); - processModel.setTempTradingPeerNodeAddress(sender); - - TradeTaskRunner taskRunner = new TradeTaskRunner(trade, - () -> handleTaskRunnerSuccess(tradeMessage, "handle CancelTradeRequestRejectedMessage"), - errorMessage -> handleTaskRunnerFault(tradeMessage, errorMessage)); - - taskRunner.addTasks( - ProcessCancelTradeRequestRejectedMessage.class - ); - taskRunner.run(); - } - - /////////////////////////////////////////////////////////////////////////////////////////// // Peer has published the delayed payout tx /////////////////////////////////////////////////////////////////////////////////////////// @@ -383,17 +255,13 @@ protected void doHandleDecryptedMessage(TradeMessage tradeMessage, NodeAddress s handle((MediatedPayoutTxSignatureMessage) tradeMessage, sender); } else if (tradeMessage instanceof MediatedPayoutTxPublishedMessage) { handle((MediatedPayoutTxPublishedMessage) tradeMessage, sender); - } else if (tradeMessage instanceof RequestCancelTradeMessage) { - handle((RequestCancelTradeMessage) tradeMessage, sender); - } else if (tradeMessage instanceof CancelTradeRequestAcceptedMessage) { - handle((CancelTradeRequestAcceptedMessage) tradeMessage, sender); - } else if (tradeMessage instanceof CancelTradeRequestRejectedMessage) { - handle((CancelTradeRequestRejectedMessage) tradeMessage, sender); } else if (tradeMessage instanceof PeerPublishedDelayedPayoutTxMessage) { handle((PeerPublishedDelayedPayoutTxMessage) tradeMessage, sender); } else if (tradeMessage instanceof TraderSignedWitnessMessage) { handle((TraderSignedWitnessMessage) tradeMessage); } + + cancelTradeProtocol.doHandleDecryptedMessage(tradeMessage, sender); } @@ -442,13 +310,9 @@ protected void doApplyMailboxTradeMessage(TradeMessage tradeMessage, NodeAddress handle((PeerPublishedDelayedPayoutTxMessage) tradeMessage, peerNodeAddress); } else if (tradeMessage instanceof TraderSignedWitnessMessage) { handle((TraderSignedWitnessMessage) tradeMessage); - } else if (tradeMessage instanceof RequestCancelTradeMessage) { - handle((RequestCancelTradeMessage) tradeMessage, peerNodeAddress); - } else if (tradeMessage instanceof CancelTradeRequestAcceptedMessage) { - handle((CancelTradeRequestAcceptedMessage) tradeMessage, peerNodeAddress); - } else if (tradeMessage instanceof CancelTradeRequestRejectedMessage) { - handle((CancelTradeRequestRejectedMessage) tradeMessage, peerNodeAddress); } + + cancelTradeProtocol.doApplyMailboxTradeMessage(tradeMessage, peerNodeAddress); } protected void startTimeout() { @@ -469,11 +333,11 @@ protected void stopTimeout() { } } - protected void handleTaskRunnerSuccess(String info) { + void handleTaskRunnerSuccess(String info) { handleTaskRunnerSuccess(null, info); } - protected void handleTaskRunnerSuccess(@Nullable TradeMessage tradeMessage, String info) { + void handleTaskRunnerSuccess(@Nullable TradeMessage tradeMessage, String info) { log.debug("handleTaskRunnerSuccess {}", info); sendAckMessage(tradeMessage, true, null); @@ -522,7 +386,7 @@ private void sendAckMessage(@Nullable TradeMessage tradeMessage, boolean result, errorMessage); // If there was an error during offer verification, the tradingPeerNodeAddress of the trade might not be set yet. // We can find the peer's node address in the processModel's tempTradingPeerNodeAddress in that case. - final NodeAddress peersNodeAddress = trade.getTradingPeerNodeAddress() != null ? trade.getTradingPeerNodeAddress() : processModel.getTempTradingPeerNodeAddress(); + NodeAddress peersNodeAddress = trade.getTradingPeerNodeAddress() != null ? trade.getTradingPeerNodeAddress() : processModel.getTempTradingPeerNodeAddress(); log.info("Send AckMessage for {} to peer {}. tradeId={}, sourceUid={}", ackMessage.getSourceMsgClassName(), peersNodeAddress, tradeId, sourceUid); String finalSourceUid = sourceUid; @@ -553,7 +417,7 @@ public void onFault(String errorMessage) { } private void cleanupTradableOnFault() { - final Trade.State state = trade.getState(); + Trade.State state = trade.getState(); log.warn("cleanupTradableOnFault tradeState={}", state); TradeManager tradeManager = processModel.getTradeManager(); if (trade.isInPreparation()) { diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestAcceptedMessage.java similarity index 98% rename from core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java rename to core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestAcceptedMessage.java index 951bf2f63db..798ab3c5ad9 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestAcceptedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestAcceptedMessage.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.core.trade.protocol.tasks.cancel; +package bisq.core.trade.protocol.tasks.buyer.cancel; import bisq.core.btc.wallet.BtcWalletService; import bisq.core.btc.wallet.WalletService; diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestRejectedMessage.java similarity index 97% rename from core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java rename to core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestRejectedMessage.java index a8bedf7c3e1..b69f7f47eaf 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessCancelTradeRequestRejectedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestRejectedMessage.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.core.trade.protocol.tasks.cancel; +package bisq.core.trade.protocol.tasks.buyer.cancel; import bisq.core.trade.BuyerTrade; import bisq.core.trade.Trade; diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SendRequestCancelTradeMessage.java similarity index 98% rename from core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java rename to core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SendRequestCancelTradeMessage.java index 1a0604d2223..dcea291a0f9 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendRequestCancelTradeMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SendRequestCancelTradeMessage.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.core.trade.protocol.tasks.cancel; +package bisq.core.trade.protocol.tasks.buyer.cancel; import bisq.core.trade.BuyerTrade; import bisq.core.trade.Contract; diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SetupCanceledTradePayoutTxListener.java similarity index 97% rename from core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java rename to core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SetupCanceledTradePayoutTxListener.java index d8cae22d382..a3da09bbef3 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SetupCanceledTradePayoutTxListener.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SetupCanceledTradePayoutTxListener.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.core.trade.protocol.tasks.cancel; +package bisq.core.trade.protocol.tasks.buyer.cancel; import bisq.core.trade.BuyerTrade; import bisq.core.trade.Trade; diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/BroadcastCanceledTradePayoutTx.java similarity index 96% rename from core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java rename to core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/BroadcastCanceledTradePayoutTx.java index 1612de4b128..ce51819638e 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/BroadcastCanceledTradePayoutTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/BroadcastCanceledTradePayoutTx.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.core.trade.protocol.tasks.cancel; +package bisq.core.trade.protocol.tasks.seller.cancel; import bisq.core.trade.SellerTrade; import bisq.core.trade.Trade; diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/FinalizeCanceledTradePayoutTx.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/FinalizeCanceledTradePayoutTx.java similarity index 99% rename from core/src/main/java/bisq/core/trade/protocol/tasks/cancel/FinalizeCanceledTradePayoutTx.java rename to core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/FinalizeCanceledTradePayoutTx.java index 289ebdac3aa..5ad98ba4db5 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/FinalizeCanceledTradePayoutTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/FinalizeCanceledTradePayoutTx.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.core.trade.protocol.tasks.cancel; +package bisq.core.trade.protocol.tasks.seller.cancel; import bisq.core.btc.model.AddressEntry; import bisq.core.btc.wallet.BtcWalletService; diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/ProcessRequestCancelTradeMessage.java similarity index 97% rename from core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java rename to core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/ProcessRequestCancelTradeMessage.java index 54e44588ea0..fb50675e71c 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/ProcessRequestCancelTradeMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/ProcessRequestCancelTradeMessage.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.core.trade.protocol.tasks.cancel; +package bisq.core.trade.protocol.tasks.seller.cancel; import bisq.core.trade.SellerTrade; import bisq.core.trade.Trade; diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestAcceptedMessage.java similarity index 98% rename from core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java rename to core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestAcceptedMessage.java index 7a2ab0c70f5..77489ef618f 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestAcceptedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestAcceptedMessage.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.core.trade.protocol.tasks.cancel; +package bisq.core.trade.protocol.tasks.seller.cancel; import bisq.core.trade.SellerTrade; import bisq.core.trade.Trade; diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestRejectedMessage.java similarity index 97% rename from core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java rename to core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestRejectedMessage.java index c43f0baece1..5449c87eb2c 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SendCancelTradeRequestRejectedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestRejectedMessage.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.core.trade.protocol.tasks.cancel; +package bisq.core.trade.protocol.tasks.seller.cancel; import bisq.core.trade.SellerTrade; import bisq.core.trade.Trade; diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java index f7934b9aad2..26507d9d22b 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java @@ -127,7 +127,7 @@ private void onRequestCancelTrade() { /////////////////////////////////////////////////////////////////////////////////////////// private void doRequestCancelTrade() { - manager.requestCancelTrade(trade, + manager.onRequestCancelTrade(trade, () -> { log.info("Request cancel trade protocol completed."); }, errorMessage -> { diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java index cbe021a677d..3d26457d2e1 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java @@ -84,14 +84,14 @@ public void deactivate() { /////////////////////////////////////////////////////////////////////////////////////////// private void onAcceptRequest() { - manager.acceptRequest(trade, + manager.onAcceptRequest(trade, () -> { }, errorMessage -> { }); } private void onRejectRequest() { - manager.rejectRequest(trade, + manager.onRejectRequest(trade, () -> { }, errorMessage -> { }); From fa005932dbc5b517b5d4dc18f56a05c66fdb97f0 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 10:11:59 -0500 Subject: [PATCH 23/56] Refactor: Move method, improve comments --- .../core/trade/TradeCancellationManager.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/TradeCancellationManager.java b/core/src/main/java/bisq/core/trade/TradeCancellationManager.java index 335c0d6254a..37cb1c819c5 100644 --- a/core/src/main/java/bisq/core/trade/TradeCancellationManager.java +++ b/core/src/main/java/bisq/core/trade/TradeCancellationManager.java @@ -49,10 +49,9 @@ public TradeCancellationManager() { /////////////////////////////////////////////////////////////////////////////////////////// - // UI handlers + // Buyers User intent /////////////////////////////////////////////////////////////////////////////////////////// - // Buyer public void onRequestCancelTrade(Trade trade, ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { @@ -69,12 +68,18 @@ public void onRequestCancelTrade(Trade trade, processModel.setBuyerPayoutAmountFromCanceledTrade(secDepositForForPeer.value); processModel.setSellerPayoutAmountFromCanceledTrade(tradeAmount.add(secDepositOfRequester).value); } + + // We could apply generics to trade and trade protocol classes to get correct type by default, + // but we leave that for a maybe later refactoring BuyersCancelTradeProtocol buyersCancelTradeProtocol = (BuyersCancelTradeProtocol) (trade.getTradeProtocol().getCancelTradeProtocol()); buyersCancelTradeProtocol.onRequestCancelTrade(resultHandler, errorMessageHandler); } - // Seller + /////////////////////////////////////////////////////////////////////////////////////////// + // Sellers User intent + /////////////////////////////////////////////////////////////////////////////////////////// + public void onAcceptRequest(Trade trade, ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { @@ -91,6 +96,9 @@ public void onAcceptRequest(Trade trade, processModel.setBuyerPayoutAmountFromCanceledTrade(secDepositOfRequester.value); processModel.setSellerPayoutAmountFromCanceledTrade(tradeAmount.add(secDepositOfAcceptingTrader).value); } + + // We could apply generics to trade and trade protocol classes to get correct type by default, + // but we leave that for a maybe later refactoring SellersCancelTradeProtocol sellersCancelTradeProtocol = (SellersCancelTradeProtocol) (trade.getTradeProtocol().getCancelTradeProtocol()); sellersCancelTradeProtocol.onAcceptRequest(resultHandler, errorMessageHandler); } @@ -98,6 +106,9 @@ public void onAcceptRequest(Trade trade, public void onRejectRequest(Trade trade, ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { + + // We could apply generics to trade and trade protocol classes to get correct type by default, + // but we leave that for a maybe later refactoring SellersCancelTradeProtocol sellersCancelTradeProtocol = (SellersCancelTradeProtocol) (trade.getTradeProtocol().getCancelTradeProtocol()); sellersCancelTradeProtocol.onRejectRequest(resultHandler, errorMessageHandler); } @@ -111,11 +122,6 @@ public Coin getSecurityDepositForRequester() { return Restrictions.getMinRefundAtMediatedDispute(); } - private Coin getTotalSecDepositForAcceptingTrader(Offer offer) { - Coin totalSecDeposit = offer.getSellerSecurityDeposit().add(offer.getBuyerSecurityDeposit()); - return totalSecDeposit.subtract(getSecurityDepositForRequester()); - } - public Coin getDefaultSecDepositOfAcceptingTrader(Trade trade) { Offer offer = checkNotNull(trade.getOffer()); return trade instanceof BuyerTrade ? @@ -127,4 +133,9 @@ public Coin getLostSecDepositOfRequestingTrader(Trade trade) { Offer offer = checkNotNull(trade.getOffer()); return getTotalSecDepositForAcceptingTrader(offer).subtract(getDefaultSecDepositOfAcceptingTrader(trade)); } + + private Coin getTotalSecDepositForAcceptingTrader(Offer offer) { + Coin totalSecDeposit = offer.getSellerSecurityDeposit().add(offer.getBuyerSecurityDeposit()); + return totalSecDeposit.subtract(getSecurityDepositForRequester()); + } } From b4d98070a90848c54f9401c5a77865240ffc59b5 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 10:12:31 -0500 Subject: [PATCH 24/56] Refactor: Move message classes to new package --- .../bisq/core/proto/network/CoreNetworkProtoResolver.java | 6 +++--- .../{ => cancel}/CancelTradeRequestAcceptedMessage.java | 4 +++- .../{ => cancel}/CancelTradeRequestRejectedMessage.java | 4 +++- .../messages/{ => cancel}/RequestCancelTradeMessage.java | 4 +++- .../bisq/core/trade/protocol/BuyersCancelTradeProtocol.java | 4 ++-- .../core/trade/protocol/SellersCancelTradeProtocol.java | 2 +- .../cancel/ProcessCancelTradeRequestAcceptedMessage.java | 2 +- .../cancel/ProcessCancelTradeRequestRejectedMessage.java | 2 +- .../tasks/buyer/cancel/SendRequestCancelTradeMessage.java | 2 +- .../seller/cancel/ProcessRequestCancelTradeMessage.java | 2 +- .../cancel/SendCancelTradeRequestAcceptedMessage.java | 2 +- .../cancel/SendCancelTradeRequestRejectedMessage.java | 2 +- 12 files changed, 21 insertions(+), 15 deletions(-) rename core/src/main/java/bisq/core/trade/messages/{ => cancel}/CancelTradeRequestAcceptedMessage.java (97%) rename core/src/main/java/bisq/core/trade/messages/{ => cancel}/CancelTradeRequestRejectedMessage.java (97%) rename core/src/main/java/bisq/core/trade/messages/{ => cancel}/RequestCancelTradeMessage.java (97%) diff --git a/core/src/main/java/bisq/core/proto/network/CoreNetworkProtoResolver.java b/core/src/main/java/bisq/core/proto/network/CoreNetworkProtoResolver.java index ec5b0ee7f33..23f57a5ed82 100644 --- a/core/src/main/java/bisq/core/proto/network/CoreNetworkProtoResolver.java +++ b/core/src/main/java/bisq/core/proto/network/CoreNetworkProtoResolver.java @@ -46,8 +46,6 @@ import bisq.core.support.dispute.messages.PeerOpenedDisputeMessage; import bisq.core.support.dispute.refund.refundagent.RefundAgent; import bisq.core.support.messages.ChatMessage; -import bisq.core.trade.messages.CancelTradeRequestAcceptedMessage; -import bisq.core.trade.messages.CancelTradeRequestRejectedMessage; import bisq.core.trade.messages.CounterCurrencyTransferStartedMessage; import bisq.core.trade.messages.DelayedPayoutTxSignatureRequest; import bisq.core.trade.messages.DelayedPayoutTxSignatureResponse; @@ -60,8 +58,10 @@ import bisq.core.trade.messages.PayoutTxPublishedMessage; import bisq.core.trade.messages.PeerPublishedDelayedPayoutTxMessage; import bisq.core.trade.messages.RefreshTradeStateRequest; -import bisq.core.trade.messages.RequestCancelTradeMessage; import bisq.core.trade.messages.TraderSignedWitnessMessage; +import bisq.core.trade.messages.cancel.CancelTradeRequestAcceptedMessage; +import bisq.core.trade.messages.cancel.CancelTradeRequestRejectedMessage; +import bisq.core.trade.messages.cancel.RequestCancelTradeMessage; import bisq.core.trade.statistics.TradeStatistics; import bisq.network.p2p.AckMessage; diff --git a/core/src/main/java/bisq/core/trade/messages/CancelTradeRequestAcceptedMessage.java b/core/src/main/java/bisq/core/trade/messages/cancel/CancelTradeRequestAcceptedMessage.java similarity index 97% rename from core/src/main/java/bisq/core/trade/messages/CancelTradeRequestAcceptedMessage.java rename to core/src/main/java/bisq/core/trade/messages/cancel/CancelTradeRequestAcceptedMessage.java index 521d821b540..390f468a6a1 100644 --- a/core/src/main/java/bisq/core/trade/messages/CancelTradeRequestAcceptedMessage.java +++ b/core/src/main/java/bisq/core/trade/messages/cancel/CancelTradeRequestAcceptedMessage.java @@ -15,7 +15,9 @@ * along with Bisq. If not, see . */ -package bisq.core.trade.messages; +package bisq.core.trade.messages.cancel; + +import bisq.core.trade.messages.TradeMessage; import bisq.network.p2p.MailboxMessage; import bisq.network.p2p.NodeAddress; diff --git a/core/src/main/java/bisq/core/trade/messages/CancelTradeRequestRejectedMessage.java b/core/src/main/java/bisq/core/trade/messages/cancel/CancelTradeRequestRejectedMessage.java similarity index 97% rename from core/src/main/java/bisq/core/trade/messages/CancelTradeRequestRejectedMessage.java rename to core/src/main/java/bisq/core/trade/messages/cancel/CancelTradeRequestRejectedMessage.java index a6bc084eb2c..5cf737dc2e4 100644 --- a/core/src/main/java/bisq/core/trade/messages/CancelTradeRequestRejectedMessage.java +++ b/core/src/main/java/bisq/core/trade/messages/cancel/CancelTradeRequestRejectedMessage.java @@ -15,7 +15,9 @@ * along with Bisq. If not, see . */ -package bisq.core.trade.messages; +package bisq.core.trade.messages.cancel; + +import bisq.core.trade.messages.TradeMessage; import bisq.network.p2p.MailboxMessage; import bisq.network.p2p.NodeAddress; diff --git a/core/src/main/java/bisq/core/trade/messages/RequestCancelTradeMessage.java b/core/src/main/java/bisq/core/trade/messages/cancel/RequestCancelTradeMessage.java similarity index 97% rename from core/src/main/java/bisq/core/trade/messages/RequestCancelTradeMessage.java rename to core/src/main/java/bisq/core/trade/messages/cancel/RequestCancelTradeMessage.java index e8461cb4fbd..08458ff5b1e 100644 --- a/core/src/main/java/bisq/core/trade/messages/RequestCancelTradeMessage.java +++ b/core/src/main/java/bisq/core/trade/messages/cancel/RequestCancelTradeMessage.java @@ -15,7 +15,9 @@ * along with Bisq. If not, see . */ -package bisq.core.trade.messages; +package bisq.core.trade.messages.cancel; + +import bisq.core.trade.messages.TradeMessage; import bisq.network.p2p.MailboxMessage; import bisq.network.p2p.NodeAddress; diff --git a/core/src/main/java/bisq/core/trade/protocol/BuyersCancelTradeProtocol.java b/core/src/main/java/bisq/core/trade/protocol/BuyersCancelTradeProtocol.java index 658349f81ab..1b63e44b067 100644 --- a/core/src/main/java/bisq/core/trade/protocol/BuyersCancelTradeProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/BuyersCancelTradeProtocol.java @@ -18,9 +18,9 @@ package bisq.core.trade.protocol; import bisq.core.trade.Trade; -import bisq.core.trade.messages.CancelTradeRequestAcceptedMessage; -import bisq.core.trade.messages.CancelTradeRequestRejectedMessage; import bisq.core.trade.messages.TradeMessage; +import bisq.core.trade.messages.cancel.CancelTradeRequestAcceptedMessage; +import bisq.core.trade.messages.cancel.CancelTradeRequestRejectedMessage; import bisq.core.trade.protocol.tasks.ApplyFilter; import bisq.core.trade.protocol.tasks.buyer.cancel.ProcessCancelTradeRequestAcceptedMessage; import bisq.core.trade.protocol.tasks.buyer.cancel.ProcessCancelTradeRequestRejectedMessage; diff --git a/core/src/main/java/bisq/core/trade/protocol/SellersCancelTradeProtocol.java b/core/src/main/java/bisq/core/trade/protocol/SellersCancelTradeProtocol.java index 470fe081332..4ae4decc0e1 100644 --- a/core/src/main/java/bisq/core/trade/protocol/SellersCancelTradeProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/SellersCancelTradeProtocol.java @@ -18,8 +18,8 @@ package bisq.core.trade.protocol; import bisq.core.trade.Trade; -import bisq.core.trade.messages.RequestCancelTradeMessage; import bisq.core.trade.messages.TradeMessage; +import bisq.core.trade.messages.cancel.RequestCancelTradeMessage; import bisq.core.trade.protocol.tasks.ApplyFilter; import bisq.core.trade.protocol.tasks.cancel.SignCanceledTradePayoutTx; import bisq.core.trade.protocol.tasks.seller.cancel.BroadcastCanceledTradePayoutTx; diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestAcceptedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestAcceptedMessage.java index 798ab3c5ad9..a7dbcab76cb 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestAcceptedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestAcceptedMessage.java @@ -21,7 +21,7 @@ import bisq.core.btc.wallet.WalletService; import bisq.core.trade.BuyerTrade; import bisq.core.trade.Trade; -import bisq.core.trade.messages.CancelTradeRequestAcceptedMessage; +import bisq.core.trade.messages.cancel.CancelTradeRequestAcceptedMessage; import bisq.core.trade.protocol.tasks.TradeTask; import bisq.core.util.Validator; diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestRejectedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestRejectedMessage.java index b69f7f47eaf..9f21294037f 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestRejectedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestRejectedMessage.java @@ -19,7 +19,7 @@ import bisq.core.trade.BuyerTrade; import bisq.core.trade.Trade; -import bisq.core.trade.messages.CancelTradeRequestRejectedMessage; +import bisq.core.trade.messages.cancel.CancelTradeRequestRejectedMessage; import bisq.core.trade.protocol.tasks.TradeTask; import bisq.core.util.Validator; diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SendRequestCancelTradeMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SendRequestCancelTradeMessage.java index dcea291a0f9..3c183a7380b 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SendRequestCancelTradeMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SendRequestCancelTradeMessage.java @@ -20,8 +20,8 @@ import bisq.core.trade.BuyerTrade; import bisq.core.trade.Contract; import bisq.core.trade.Trade; -import bisq.core.trade.messages.RequestCancelTradeMessage; import bisq.core.trade.messages.TradeMessage; +import bisq.core.trade.messages.cancel.RequestCancelTradeMessage; import bisq.core.trade.protocol.tasks.SendMailboxMessageTask; import bisq.network.p2p.NodeAddress; diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/ProcessRequestCancelTradeMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/ProcessRequestCancelTradeMessage.java index fb50675e71c..8c9b2314326 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/ProcessRequestCancelTradeMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/ProcessRequestCancelTradeMessage.java @@ -19,7 +19,7 @@ import bisq.core.trade.SellerTrade; import bisq.core.trade.Trade; -import bisq.core.trade.messages.RequestCancelTradeMessage; +import bisq.core.trade.messages.cancel.RequestCancelTradeMessage; import bisq.core.trade.protocol.tasks.TradeTask; import bisq.core.util.Validator; diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestAcceptedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestAcceptedMessage.java index 77489ef618f..37a0d8b82bd 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestAcceptedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestAcceptedMessage.java @@ -19,8 +19,8 @@ import bisq.core.trade.SellerTrade; import bisq.core.trade.Trade; -import bisq.core.trade.messages.CancelTradeRequestAcceptedMessage; import bisq.core.trade.messages.TradeMessage; +import bisq.core.trade.messages.cancel.CancelTradeRequestAcceptedMessage; import bisq.core.trade.protocol.tasks.SendMailboxMessageTask; import bisq.common.taskrunner.TaskRunner; diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestRejectedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestRejectedMessage.java index 5449c87eb2c..76c78185a67 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestRejectedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestRejectedMessage.java @@ -19,8 +19,8 @@ import bisq.core.trade.SellerTrade; import bisq.core.trade.Trade; -import bisq.core.trade.messages.CancelTradeRequestRejectedMessage; import bisq.core.trade.messages.TradeMessage; +import bisq.core.trade.messages.cancel.CancelTradeRequestRejectedMessage; import bisq.core.trade.protocol.tasks.SendMailboxMessageTask; import bisq.common.taskrunner.TaskRunner; From 9ee586fe4e31869ac725f3e7f63fe2542393c27a Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 10:13:43 -0500 Subject: [PATCH 25/56] Refactor: Move dispute message classes to new dispute package --- .../bisq/core/proto/network/CoreNetworkProtoResolver.java | 4 ++-- .../{ => dispute}/MediatedPayoutTxPublishedMessage.java | 4 +++- .../{ => dispute}/MediatedPayoutTxSignatureMessage.java | 4 +++- .../src/main/java/bisq/core/trade/protocol/TradeProtocol.java | 4 ++-- .../mediation/ProcessMediatedPayoutSignatureMessage.java | 2 +- .../mediation/ProcessMediatedPayoutTxPublishedMessage.java | 2 +- .../tasks/mediation/SendMediatedPayoutSignatureMessage.java | 2 +- .../tasks/mediation/SendMediatedPayoutTxPublishedMessage.java | 2 +- 8 files changed, 14 insertions(+), 10 deletions(-) rename core/src/main/java/bisq/core/trade/messages/{ => dispute}/MediatedPayoutTxPublishedMessage.java (97%) rename core/src/main/java/bisq/core/trade/messages/{ => dispute}/MediatedPayoutTxSignatureMessage.java (97%) diff --git a/core/src/main/java/bisq/core/proto/network/CoreNetworkProtoResolver.java b/core/src/main/java/bisq/core/proto/network/CoreNetworkProtoResolver.java index 23f57a5ed82..3ac20bad143 100644 --- a/core/src/main/java/bisq/core/proto/network/CoreNetworkProtoResolver.java +++ b/core/src/main/java/bisq/core/proto/network/CoreNetworkProtoResolver.java @@ -53,8 +53,6 @@ import bisq.core.trade.messages.DepositTxMessage; import bisq.core.trade.messages.InputsForDepositTxRequest; import bisq.core.trade.messages.InputsForDepositTxResponse; -import bisq.core.trade.messages.MediatedPayoutTxPublishedMessage; -import bisq.core.trade.messages.MediatedPayoutTxSignatureMessage; import bisq.core.trade.messages.PayoutTxPublishedMessage; import bisq.core.trade.messages.PeerPublishedDelayedPayoutTxMessage; import bisq.core.trade.messages.RefreshTradeStateRequest; @@ -62,6 +60,8 @@ import bisq.core.trade.messages.cancel.CancelTradeRequestAcceptedMessage; import bisq.core.trade.messages.cancel.CancelTradeRequestRejectedMessage; import bisq.core.trade.messages.cancel.RequestCancelTradeMessage; +import bisq.core.trade.messages.dispute.MediatedPayoutTxPublishedMessage; +import bisq.core.trade.messages.dispute.MediatedPayoutTxSignatureMessage; import bisq.core.trade.statistics.TradeStatistics; import bisq.network.p2p.AckMessage; diff --git a/core/src/main/java/bisq/core/trade/messages/MediatedPayoutTxPublishedMessage.java b/core/src/main/java/bisq/core/trade/messages/dispute/MediatedPayoutTxPublishedMessage.java similarity index 97% rename from core/src/main/java/bisq/core/trade/messages/MediatedPayoutTxPublishedMessage.java rename to core/src/main/java/bisq/core/trade/messages/dispute/MediatedPayoutTxPublishedMessage.java index e20daba473b..14f81f5eda5 100644 --- a/core/src/main/java/bisq/core/trade/messages/MediatedPayoutTxPublishedMessage.java +++ b/core/src/main/java/bisq/core/trade/messages/dispute/MediatedPayoutTxPublishedMessage.java @@ -15,7 +15,9 @@ * along with Bisq. If not, see . */ -package bisq.core.trade.messages; +package bisq.core.trade.messages.dispute; + +import bisq.core.trade.messages.TradeMessage; import bisq.network.p2p.MailboxMessage; import bisq.network.p2p.NodeAddress; diff --git a/core/src/main/java/bisq/core/trade/messages/MediatedPayoutTxSignatureMessage.java b/core/src/main/java/bisq/core/trade/messages/dispute/MediatedPayoutTxSignatureMessage.java similarity index 97% rename from core/src/main/java/bisq/core/trade/messages/MediatedPayoutTxSignatureMessage.java rename to core/src/main/java/bisq/core/trade/messages/dispute/MediatedPayoutTxSignatureMessage.java index b476576b65e..cb2fd5ef450 100644 --- a/core/src/main/java/bisq/core/trade/messages/MediatedPayoutTxSignatureMessage.java +++ b/core/src/main/java/bisq/core/trade/messages/dispute/MediatedPayoutTxSignatureMessage.java @@ -15,7 +15,9 @@ * along with Bisq. If not, see . */ -package bisq.core.trade.messages; +package bisq.core.trade.messages.dispute; + +import bisq.core.trade.messages.TradeMessage; import bisq.network.p2p.MailboxMessage; import bisq.network.p2p.NodeAddress; diff --git a/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java b/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java index e81e727f031..c33aeeb4358 100644 --- a/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java @@ -22,11 +22,11 @@ import bisq.core.trade.TradeManager; import bisq.core.trade.messages.CounterCurrencyTransferStartedMessage; import bisq.core.trade.messages.InputsForDepositTxRequest; -import bisq.core.trade.messages.MediatedPayoutTxPublishedMessage; -import bisq.core.trade.messages.MediatedPayoutTxSignatureMessage; import bisq.core.trade.messages.PeerPublishedDelayedPayoutTxMessage; import bisq.core.trade.messages.TradeMessage; import bisq.core.trade.messages.TraderSignedWitnessMessage; +import bisq.core.trade.messages.dispute.MediatedPayoutTxPublishedMessage; +import bisq.core.trade.messages.dispute.MediatedPayoutTxSignatureMessage; import bisq.core.trade.protocol.tasks.ApplyFilter; import bisq.core.trade.protocol.tasks.ProcessPeerPublishedDelayedPayoutTxMessage; import bisq.core.trade.protocol.tasks.mediation.BroadcastMediatedPayoutTx; diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/ProcessMediatedPayoutSignatureMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/ProcessMediatedPayoutSignatureMessage.java index 0a26804bf81..28de1d5352c 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/ProcessMediatedPayoutSignatureMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/ProcessMediatedPayoutSignatureMessage.java @@ -19,7 +19,7 @@ import bisq.core.support.dispute.mediation.MediationResultState; import bisq.core.trade.Trade; -import bisq.core.trade.messages.MediatedPayoutTxSignatureMessage; +import bisq.core.trade.messages.dispute.MediatedPayoutTxSignatureMessage; import bisq.core.trade.protocol.tasks.TradeTask; import bisq.core.util.Validator; diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/ProcessMediatedPayoutTxPublishedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/ProcessMediatedPayoutTxPublishedMessage.java index e6c60eb4a10..032972efb65 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/ProcessMediatedPayoutTxPublishedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/ProcessMediatedPayoutTxPublishedMessage.java @@ -22,7 +22,7 @@ import bisq.core.btc.wallet.WalletService; import bisq.core.support.dispute.mediation.MediationResultState; import bisq.core.trade.Trade; -import bisq.core.trade.messages.MediatedPayoutTxPublishedMessage; +import bisq.core.trade.messages.dispute.MediatedPayoutTxPublishedMessage; import bisq.core.trade.protocol.tasks.TradeTask; import bisq.core.util.Validator; diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutSignatureMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutSignatureMessage.java index 88e6450da47..b7f1d1413d6 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutSignatureMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutSignatureMessage.java @@ -20,7 +20,7 @@ import bisq.core.support.dispute.mediation.MediationResultState; import bisq.core.trade.Contract; import bisq.core.trade.Trade; -import bisq.core.trade.messages.MediatedPayoutTxSignatureMessage; +import bisq.core.trade.messages.dispute.MediatedPayoutTxSignatureMessage; import bisq.core.trade.protocol.tasks.TradeTask; import bisq.network.p2p.NodeAddress; diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutTxPublishedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutTxPublishedMessage.java index 5e9bd221ee5..8fee678828d 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutTxPublishedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutTxPublishedMessage.java @@ -19,8 +19,8 @@ import bisq.core.support.dispute.mediation.MediationResultState; import bisq.core.trade.Trade; -import bisq.core.trade.messages.MediatedPayoutTxPublishedMessage; import bisq.core.trade.messages.TradeMessage; +import bisq.core.trade.messages.dispute.MediatedPayoutTxPublishedMessage; import bisq.core.trade.protocol.tasks.SendMailboxMessageTask; import bisq.common.taskrunner.TaskRunner; From 482c73a269baa3992242378e286f983248d3af68 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 10:14:31 -0500 Subject: [PATCH 26/56] Refactor: Rename package --- .../bisq/core/proto/network/CoreNetworkProtoResolver.java | 4 ++-- .../MediatedPayoutTxPublishedMessage.java | 2 +- .../MediatedPayoutTxSignatureMessage.java | 2 +- .../src/main/java/bisq/core/trade/protocol/TradeProtocol.java | 4 ++-- .../mediation/ProcessMediatedPayoutSignatureMessage.java | 2 +- .../mediation/ProcessMediatedPayoutTxPublishedMessage.java | 2 +- .../tasks/mediation/SendMediatedPayoutSignatureMessage.java | 2 +- .../tasks/mediation/SendMediatedPayoutTxPublishedMessage.java | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) rename core/src/main/java/bisq/core/trade/messages/{dispute => mediation}/MediatedPayoutTxPublishedMessage.java (98%) rename core/src/main/java/bisq/core/trade/messages/{dispute => mediation}/MediatedPayoutTxSignatureMessage.java (98%) diff --git a/core/src/main/java/bisq/core/proto/network/CoreNetworkProtoResolver.java b/core/src/main/java/bisq/core/proto/network/CoreNetworkProtoResolver.java index 3ac20bad143..a0fda1da8f3 100644 --- a/core/src/main/java/bisq/core/proto/network/CoreNetworkProtoResolver.java +++ b/core/src/main/java/bisq/core/proto/network/CoreNetworkProtoResolver.java @@ -60,8 +60,8 @@ import bisq.core.trade.messages.cancel.CancelTradeRequestAcceptedMessage; import bisq.core.trade.messages.cancel.CancelTradeRequestRejectedMessage; import bisq.core.trade.messages.cancel.RequestCancelTradeMessage; -import bisq.core.trade.messages.dispute.MediatedPayoutTxPublishedMessage; -import bisq.core.trade.messages.dispute.MediatedPayoutTxSignatureMessage; +import bisq.core.trade.messages.mediation.MediatedPayoutTxPublishedMessage; +import bisq.core.trade.messages.mediation.MediatedPayoutTxSignatureMessage; import bisq.core.trade.statistics.TradeStatistics; import bisq.network.p2p.AckMessage; diff --git a/core/src/main/java/bisq/core/trade/messages/dispute/MediatedPayoutTxPublishedMessage.java b/core/src/main/java/bisq/core/trade/messages/mediation/MediatedPayoutTxPublishedMessage.java similarity index 98% rename from core/src/main/java/bisq/core/trade/messages/dispute/MediatedPayoutTxPublishedMessage.java rename to core/src/main/java/bisq/core/trade/messages/mediation/MediatedPayoutTxPublishedMessage.java index 14f81f5eda5..b964affbf99 100644 --- a/core/src/main/java/bisq/core/trade/messages/dispute/MediatedPayoutTxPublishedMessage.java +++ b/core/src/main/java/bisq/core/trade/messages/mediation/MediatedPayoutTxPublishedMessage.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.core.trade.messages.dispute; +package bisq.core.trade.messages.mediation; import bisq.core.trade.messages.TradeMessage; diff --git a/core/src/main/java/bisq/core/trade/messages/dispute/MediatedPayoutTxSignatureMessage.java b/core/src/main/java/bisq/core/trade/messages/mediation/MediatedPayoutTxSignatureMessage.java similarity index 98% rename from core/src/main/java/bisq/core/trade/messages/dispute/MediatedPayoutTxSignatureMessage.java rename to core/src/main/java/bisq/core/trade/messages/mediation/MediatedPayoutTxSignatureMessage.java index cb2fd5ef450..0a046b2f309 100644 --- a/core/src/main/java/bisq/core/trade/messages/dispute/MediatedPayoutTxSignatureMessage.java +++ b/core/src/main/java/bisq/core/trade/messages/mediation/MediatedPayoutTxSignatureMessage.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.core.trade.messages.dispute; +package bisq.core.trade.messages.mediation; import bisq.core.trade.messages.TradeMessage; diff --git a/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java b/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java index c33aeeb4358..c49552bccba 100644 --- a/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java @@ -25,8 +25,8 @@ import bisq.core.trade.messages.PeerPublishedDelayedPayoutTxMessage; import bisq.core.trade.messages.TradeMessage; import bisq.core.trade.messages.TraderSignedWitnessMessage; -import bisq.core.trade.messages.dispute.MediatedPayoutTxPublishedMessage; -import bisq.core.trade.messages.dispute.MediatedPayoutTxSignatureMessage; +import bisq.core.trade.messages.mediation.MediatedPayoutTxPublishedMessage; +import bisq.core.trade.messages.mediation.MediatedPayoutTxSignatureMessage; import bisq.core.trade.protocol.tasks.ApplyFilter; import bisq.core.trade.protocol.tasks.ProcessPeerPublishedDelayedPayoutTxMessage; import bisq.core.trade.protocol.tasks.mediation.BroadcastMediatedPayoutTx; diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/ProcessMediatedPayoutSignatureMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/ProcessMediatedPayoutSignatureMessage.java index 28de1d5352c..9ae9aedc340 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/ProcessMediatedPayoutSignatureMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/ProcessMediatedPayoutSignatureMessage.java @@ -19,7 +19,7 @@ import bisq.core.support.dispute.mediation.MediationResultState; import bisq.core.trade.Trade; -import bisq.core.trade.messages.dispute.MediatedPayoutTxSignatureMessage; +import bisq.core.trade.messages.mediation.MediatedPayoutTxSignatureMessage; import bisq.core.trade.protocol.tasks.TradeTask; import bisq.core.util.Validator; diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/ProcessMediatedPayoutTxPublishedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/ProcessMediatedPayoutTxPublishedMessage.java index 032972efb65..247409c2ef3 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/ProcessMediatedPayoutTxPublishedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/ProcessMediatedPayoutTxPublishedMessage.java @@ -22,7 +22,7 @@ import bisq.core.btc.wallet.WalletService; import bisq.core.support.dispute.mediation.MediationResultState; import bisq.core.trade.Trade; -import bisq.core.trade.messages.dispute.MediatedPayoutTxPublishedMessage; +import bisq.core.trade.messages.mediation.MediatedPayoutTxPublishedMessage; import bisq.core.trade.protocol.tasks.TradeTask; import bisq.core.util.Validator; diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutSignatureMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutSignatureMessage.java index b7f1d1413d6..606771bfb29 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutSignatureMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutSignatureMessage.java @@ -20,7 +20,7 @@ import bisq.core.support.dispute.mediation.MediationResultState; import bisq.core.trade.Contract; import bisq.core.trade.Trade; -import bisq.core.trade.messages.dispute.MediatedPayoutTxSignatureMessage; +import bisq.core.trade.messages.mediation.MediatedPayoutTxSignatureMessage; import bisq.core.trade.protocol.tasks.TradeTask; import bisq.network.p2p.NodeAddress; diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutTxPublishedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutTxPublishedMessage.java index 8fee678828d..68f8bafdafe 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutTxPublishedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutTxPublishedMessage.java @@ -20,7 +20,7 @@ import bisq.core.support.dispute.mediation.MediationResultState; import bisq.core.trade.Trade; import bisq.core.trade.messages.TradeMessage; -import bisq.core.trade.messages.dispute.MediatedPayoutTxPublishedMessage; +import bisq.core.trade.messages.mediation.MediatedPayoutTxPublishedMessage; import bisq.core.trade.protocol.tasks.SendMailboxMessageTask; import bisq.common.taskrunner.TaskRunner; From 54e4a0853a75a6a2336b95473ad8cca332df83e7 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 11:42:41 -0500 Subject: [PATCH 27/56] Only log error at DelayedPayoutTx check if deposit tx is not null For failed trades without deposit tx it is expected that the DelayedPayoutTx is null as well. --- .../main/java/bisq/core/trade/DelayedPayoutTxValidation.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/bisq/core/trade/DelayedPayoutTxValidation.java b/core/src/main/java/bisq/core/trade/DelayedPayoutTxValidation.java index 6c835d2408b..5a718acdd98 100644 --- a/core/src/main/java/bisq/core/trade/DelayedPayoutTxValidation.java +++ b/core/src/main/java/bisq/core/trade/DelayedPayoutTxValidation.java @@ -86,7 +86,10 @@ public static void validatePayoutTx(Trade trade, String errorMsg; if (delayedPayoutTx == null) { errorMsg = "DelayedPayoutTx must not be null"; - log.error(errorMsg); + if (trade.getDepositTx() != null) { + // For failed trades without deposit tx it is expected that the DelayedPayoutTx is null as well. + log.error(errorMsg); + } throw new MissingDelayedPayoutTxException("DelayedPayoutTx must not be null"); } From eae6a46f660e03838e7827fa747ddedbdf26977a Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 11:57:32 -0500 Subject: [PATCH 28/56] Improve text, dont use action style for button --- .../resources/i18n/displayStrings.properties | 16 +++++++++------- .../BuyerRequestCancelTradePresentation.java | 1 - ...llerHandleCancelTradeRequestPresentation.java | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index 7b6f21a8192..3675c246d84 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -911,13 +911,15 @@ portfolio.failed.depositTxNull=The trade cannot be completed. Deposit transactio portfolio.failed.delayedPayoutTxNull=The trade cannot be completed. Delayed payout transaction is null portfolio.pending.cancelTrade=Cancel trade -portfolio.pending.requestSent=Cancel trade request message sent. -portfolio.pending.requestArrived=Request message arrived. Awaiting peer's response. -portfolio.pending.requestInMailbox=Request message stored in mailbox. Awaiting peer's response. -portfolio.pending.requestFailed=Sending request message failed. -portfolio.pending.requestGotAccepted=Your cancel trade request was accepted by the peer. The trade is closed and the payout completed. -portfolio.pending.requestGotRejected=Your cancel trade request was rejected by the peer. -portfolio.pending.doNotDecideYet=Don't decide yet +portfolio.pending.requestSent=Cancellation request sent. +portfolio.pending.requestArrived=Cancellation request arrived. Awaiting peer's response. +portfolio.pending.requestInMailbox=Cancellation request stored in mailbox. Awaiting peer's response. +portfolio.pending.requestFailed=Sending cancellation request failed. +portfolio.pending.requestGotAccepted=Your cancellation request was accepted by the peer. \ + The trade is closed and the payout completed.\n\n\ + You can review the details of the trade in the 'History' screen. +portfolio.pending.requestGotRejected=Your cancellation request was rejected by the peer. Please continue with the payment. +portfolio.pending.decideLater=Decide later portfolio.pending.requestCancelTradePopup=You can send a request to your trading peer for canceling the trade.\n\n\ If the peer accepts your request you will get back a part of your security deposit. The other part will be given to \ your trading peer as compensation for the lost trade fee, trade opportunity and time.\n\n\ diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java index 26507d9d22b..2bff61a79da 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java @@ -76,7 +76,6 @@ public void initialize(HBox hBox, this.msgSentStatusLabel = msgSentStatusLabel; cancelTradeButton = new AutoTooltipButton(Res.get("portfolio.pending.cancelTrade")); - cancelTradeButton.getStyleClass().add("action-button"); cancelTradeButton.setOnAction(e -> onRequestCancelTrade()); hBox.getChildren().add(1, cancelTradeButton); } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java index 3d26457d2e1..f713af2409b 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java @@ -118,7 +118,7 @@ private void onStateChanged(SellerTrade.CancelTradeState newValue) { .onAction(this::onAcceptRequest) .secondaryActionButtonText(Res.get("shared.reject")) .onSecondaryAction(this::onRejectRequest) - .closeButtonText(Res.get("portfolio.pending.doNotDecideYet")) + .closeButtonText(Res.get("portfolio.pending.decideLater")) .show(); break; case REQUEST_ACCEPTED_PAYOUT_TX_PUBLISHED: From 498543528b02be7e7682171f32f2af26bc2483c2 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 11:58:36 -0500 Subject: [PATCH 29/56] Refactor: Rename classes --- .../pendingtrades/steps/buyer/BuyerStep2View.java | 14 +++++++------- ...ion.java => BuyersCancelTradePresentation.java} | 10 +++++----- .../steps/seller/SellerStep2View.java | 10 +++++----- ...on.java => SellersCancelTradePresentation.java} | 8 ++++---- 4 files changed, 21 insertions(+), 21 deletions(-) rename desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/{BuyerRequestCancelTradePresentation.java => BuyersCancelTradePresentation.java} (95%) rename desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/{SellerHandleCancelTradeRequestPresentation.java => SellersCancelTradePresentation.java} (94%) diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java index 0e7792f4f11..fa3fe76b9e0 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java @@ -104,7 +104,7 @@ public class BuyerStep2View extends TradeStepView { private BusyAnimation busyAnimation; private Subscription tradeStatePropertySubscription; private Timer timeoutTimer; - private BuyerRequestCancelTradePresentation buyerRequestCancelTradePresentation; + private BuyersCancelTradePresentation buyersCancelTradePresentation; /////////////////////////////////////////////////////////////////////////////////////////// @@ -114,7 +114,7 @@ public class BuyerStep2View extends TradeStepView { public BuyerStep2View(PendingTradesViewModel model) { super(model); - buyerRequestCancelTradePresentation = new BuyerRequestCancelTradePresentation(trade, + buyersCancelTradePresentation = new BuyersCancelTradePresentation(trade, model.dataModel.getTradeCancellationManager(), model.getBtcFormatter()); } @@ -266,7 +266,7 @@ public void initialize() { statusLabel = tuple3.third; HBox hBox = tuple3.fourth; - buyerRequestCancelTradePresentation.initialize(hBox, busyAnimation, statusLabel); + buyersCancelTradePresentation.initialize(hBox, busyAnimation, statusLabel); } @Override @@ -351,7 +351,7 @@ public void activate() { confirmButton.setDisable(isDisputed()); - buyerRequestCancelTradePresentation.activate(); + buyersCancelTradePresentation.activate(); } @Override @@ -368,7 +368,7 @@ public void deactivate() { tradeStatePropertySubscription = null; } - buyerRequestCancelTradePresentation.deactivate(); + buyersCancelTradePresentation.deactivate(); } @@ -529,7 +529,7 @@ private void showConfirmPaymentStartedPopup() { } private void confirmPaymentStarted() { - buyerRequestCancelTradePresentation.hideCancelButton(); + buyersCancelTradePresentation.hideCancelButton(); // confirmButton.setDisable(true); busyAnimation.play(); @@ -653,6 +653,6 @@ protected void updateConfirmButtonDisableState(boolean isDisabled) { confirmButton.setDisable(isDisabled); //TODO - buyerRequestCancelTradePresentation.setDisable(isDisabled); + buyersCancelTradePresentation.setDisable(isDisabled); } } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyersCancelTradePresentation.java similarity index 95% rename from desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java rename to desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyersCancelTradePresentation.java index 2bff61a79da..4d15b2e36cd 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerRequestCancelTradePresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyersCancelTradePresentation.java @@ -41,7 +41,7 @@ * todo: handle dispute */ @Slf4j -public class BuyerRequestCancelTradePresentation { +public class BuyersCancelTradePresentation { private final Trade trade; private final TradeCancellationManager manager; private final CoinFormatter formatter; @@ -54,9 +54,9 @@ public class BuyerRequestCancelTradePresentation { // Constructor /////////////////////////////////////////////////////////////////////////////////////////// - public BuyerRequestCancelTradePresentation(Trade trade, - TradeCancellationManager manager, - CoinFormatter formatter) { + BuyersCancelTradePresentation(Trade trade, + TradeCancellationManager manager, + CoinFormatter formatter) { this.trade = trade; this.manager = manager; this.formatter = formatter; @@ -96,7 +96,7 @@ public void deactivate() { // API /////////////////////////////////////////////////////////////////////////////////////////// - public void hideCancelButton() { + void hideCancelButton() { cancelTradeButton.setVisible(false); cancelTradeButton.setManaged(false); } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java index 232032e5fcc..d7376c16501 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java @@ -44,7 +44,7 @@ public class SellerStep2View extends TradeStepView { private GridPane refreshButtonPane; private Timer timer; - private SellerHandleCancelTradeRequestPresentation sellerHandleCancelTradeRequestPresentation; + private SellersCancelTradePresentation sellersCancelTradePresentation; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor @@ -53,7 +53,7 @@ public class SellerStep2View extends TradeStepView { public SellerStep2View(PendingTradesViewModel model) { super(model); - sellerHandleCancelTradeRequestPresentation = new SellerHandleCancelTradeRequestPresentation(trade, + sellersCancelTradePresentation = new SellersCancelTradePresentation(trade, model.dataModel.getTradeCancellationManager(), model.getBtcFormatter()); } @@ -78,7 +78,7 @@ public void initialize() { addRefreshBlock(); - sellerHandleCancelTradeRequestPresentation.initialize(); + sellersCancelTradePresentation.initialize(); } @Override @@ -87,7 +87,7 @@ public void activate() { activateRefreshButton(); - sellerHandleCancelTradeRequestPresentation.activate(); + sellersCancelTradePresentation.activate(); } @Override @@ -96,7 +96,7 @@ public void deactivate() { deActivateRefreshButtonTimer(); - sellerHandleCancelTradeRequestPresentation.deactivate(); + sellersCancelTradePresentation.deactivate(); } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java similarity index 94% rename from desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java rename to desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java index f713af2409b..e7a434cacda 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerHandleCancelTradeRequestPresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java @@ -35,7 +35,7 @@ * todo: handle dispute */ @Slf4j -public class SellerHandleCancelTradeRequestPresentation { +public class SellersCancelTradePresentation { private final Trade trade; private final TradeCancellationManager manager; private final CoinFormatter formatter; @@ -45,9 +45,9 @@ public class SellerHandleCancelTradeRequestPresentation { // Constructor /////////////////////////////////////////////////////////////////////////////////////////// - public SellerHandleCancelTradeRequestPresentation(Trade trade, - TradeCancellationManager manager, - CoinFormatter formatter) { + SellersCancelTradePresentation(Trade trade, + TradeCancellationManager manager, + CoinFormatter formatter) { this.trade = trade; this.manager = manager; this.formatter = formatter; From aa6721a1a7f6b4c9b15c69e52ba953755c213935 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 15:56:16 -0500 Subject: [PATCH 30/56] Getting the feature polished... Many small changes... --- .../main/java/bisq/core/trade/BuyerTrade.java | 11 ++ .../java/bisq/core/trade/SellerTrade.java | 14 ++ core/src/main/java/bisq/core/trade/Trade.java | 20 ++- .../core/trade/TradeCancellationManager.java | 6 + ...cessCancelTradeRequestAcceptedMessage.java | 3 + ...cessCancelTradeRequestRejectedMessage.java | 3 + .../cancel/SendRequestCancelTradeMessage.java | 3 + .../SetupCanceledTradePayoutTxListener.java | 2 + .../cancel/SignCanceledTradePayoutTx.java | 2 + .../BroadcastCanceledTradePayoutTx.java | 1 + .../cancel/FinalizeCanceledTradePayoutTx.java | 4 +- .../ProcessRequestCancelTradeMessage.java | 4 + ...SendCancelTradeRequestAcceptedMessage.java | 9 ++ ...SendCancelTradeRequestRejectedMessage.java | 4 + .../resources/i18n/displayStrings.properties | 36 +++-- .../closedtrades/ClosedTradesViewModel.java | 6 +- .../pendingtrades/steps/TradeStepView.java | 9 +- .../steps/buyer/BuyerStep2View.java | 9 +- .../buyer/BuyersCancelTradePresentation.java | 89 ++++++----- .../steps/seller/SellerStep2View.java | 29 +++- .../steps/seller/SellerStep3View.java | 2 +- .../SellersCancelTradePresentation.java | 142 ++++++++++++++---- 22 files changed, 307 insertions(+), 101 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/BuyerTrade.java b/core/src/main/java/bisq/core/trade/BuyerTrade.java index 2a7d7a7403e..6e100a347ca 100644 --- a/core/src/main/java/bisq/core/trade/BuyerTrade.java +++ b/core/src/main/java/bisq/core/trade/BuyerTrade.java @@ -107,4 +107,15 @@ public Coin getPayoutAmount() { return getOffer().getBuyerSecurityDeposit().add(getTradeAmount()); } + + @Override + public boolean wasCanceledTrade() { + switch (buyersCancelTradeState) { + case RECEIVED_ACCEPTED_MSG: + case PAYOUT_TX_SEEN_IN_NETWORK: + return true; + default: + return false; + } + } } diff --git a/core/src/main/java/bisq/core/trade/SellerTrade.java b/core/src/main/java/bisq/core/trade/SellerTrade.java index cc65898ddad..15e12e2d8b4 100644 --- a/core/src/main/java/bisq/core/trade/SellerTrade.java +++ b/core/src/main/java/bisq/core/trade/SellerTrade.java @@ -108,5 +108,19 @@ public void onFiatPaymentReceived(ResultHandler resultHandler, ErrorMessageHandl public Coin getPayoutAmount() { return getOffer().getSellerSecurityDeposit(); } + + @Override + public boolean wasCanceledTrade() { + switch (sellersCancelTradeState) { + case REQUEST_ACCEPTED_PAYOUT_TX_PUBLISHED: + case REQUEST_ACCEPTED_MSG_SENT: + case REQUEST_ACCEPTED_MSG_ARRIVED: + case REQUEST_ACCEPTED_MSG_IN_MAILBOX: + case REQUEST_ACCEPTED_MSG_SEND_FAILED: + return true; + default: + return false; + } + } } diff --git a/core/src/main/java/bisq/core/trade/Trade.java b/core/src/main/java/bisq/core/trade/Trade.java index 58b97fc51cf..a2a62b428fd 100644 --- a/core/src/main/java/bisq/core/trade/Trade.java +++ b/core/src/main/java/bisq/core/trade/Trade.java @@ -165,16 +165,16 @@ public enum State { SELLER_CONFIRMED_IN_UI_FIAT_PAYMENT_RECEIPT(Phase.FIAT_RECEIVED), // #################### Phase PAYOUT_PAID - SELLER_PUBLISHED_PAYOUT_TX(Phase.PAYOUT_PUBLISHED), + SELLER_PUBLISHED_PAYOUT_TX(Phase.PAYOUT_PUBLISHED), // Also used in cancelTrade case - SELLER_SENT_PAYOUT_TX_PUBLISHED_MSG(Phase.PAYOUT_PUBLISHED), - SELLER_SAW_ARRIVED_PAYOUT_TX_PUBLISHED_MSG(Phase.PAYOUT_PUBLISHED), - SELLER_STORED_IN_MAILBOX_PAYOUT_TX_PUBLISHED_MSG(Phase.PAYOUT_PUBLISHED), - SELLER_SEND_FAILED_PAYOUT_TX_PUBLISHED_MSG(Phase.PAYOUT_PUBLISHED), + SELLER_SENT_PAYOUT_TX_PUBLISHED_MSG(Phase.PAYOUT_PUBLISHED), // Also used in cancelTrade case + SELLER_SAW_ARRIVED_PAYOUT_TX_PUBLISHED_MSG(Phase.PAYOUT_PUBLISHED), // Also used in cancelTrade case + SELLER_STORED_IN_MAILBOX_PAYOUT_TX_PUBLISHED_MSG(Phase.PAYOUT_PUBLISHED), // Also used in cancelTrade case + SELLER_SEND_FAILED_PAYOUT_TX_PUBLISHED_MSG(Phase.PAYOUT_PUBLISHED), // Also used in cancelTrade case - BUYER_RECEIVED_PAYOUT_TX_PUBLISHED_MSG(Phase.PAYOUT_PUBLISHED), + BUYER_RECEIVED_PAYOUT_TX_PUBLISHED_MSG(Phase.PAYOUT_PUBLISHED), // Also used in cancelTrade case // Alternatively the maker could have seen the payout tx earlier before he received the PAYOUT_TX_PUBLISHED_MSG - BUYER_SAW_PAYOUT_TX_IN_NETWORK(Phase.PAYOUT_PUBLISHED), + BUYER_SAW_PAYOUT_TX_IN_NETWORK(Phase.PAYOUT_PUBLISHED), // Also used in cancelTrade case // #################### Phase WITHDRAWN @@ -821,6 +821,8 @@ public void onComplete() { public abstract Coin getPayoutAmount(); + public abstract boolean wasCanceledTrade(); + /////////////////////////////////////////////////////////////////////////////////////////// // Setters @@ -1145,6 +1147,10 @@ public byte[] getArbitratorBtcPubKey() { return arbitratorBtcPubKey; } + public boolean isDisputed() { + return disputeState != Trade.DisputeState.NO_DISPUTE; + } + /////////////////////////////////////////////////////////////////////////////////////////// // Private diff --git a/core/src/main/java/bisq/core/trade/TradeCancellationManager.java b/core/src/main/java/bisq/core/trade/TradeCancellationManager.java index 37cb1c819c5..40cfd83b3f3 100644 --- a/core/src/main/java/bisq/core/trade/TradeCancellationManager.java +++ b/core/src/main/java/bisq/core/trade/TradeCancellationManager.java @@ -33,6 +33,7 @@ import lombok.extern.slf4j.Slf4j; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; @Slf4j @@ -55,6 +56,8 @@ public TradeCancellationManager() { public void onRequestCancelTrade(Trade trade, ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { + checkArgument(!trade.isDisputed(), "onRejectRequest must not be called once a dispute has started."); + ProcessModel processModel = trade.getProcessModel(); Offer offer = checkNotNull(trade.getOffer()); Coin secDepositOfRequester = getSecurityDepositForRequester(); @@ -83,6 +86,8 @@ public void onRequestCancelTrade(Trade trade, public void onAcceptRequest(Trade trade, ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { + checkArgument(!trade.isDisputed(), "onRejectRequest must not be called once a dispute has started."); + ProcessModel processModel = trade.getProcessModel(); Offer offer = checkNotNull(trade.getOffer()); Coin secDepositOfRequester = getSecurityDepositForRequester(); @@ -106,6 +111,7 @@ public void onAcceptRequest(Trade trade, public void onRejectRequest(Trade trade, ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { + checkArgument(!trade.isDisputed(), "onRejectRequest must not be called once a dispute has started."); // We could apply generics to trade and trade protocol classes to get correct type by default, // but we leave that for a maybe later refactoring diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestAcceptedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestAcceptedMessage.java index a7dbcab76cb..a84880e1ed0 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestAcceptedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestAcceptedMessage.java @@ -51,6 +51,8 @@ protected void run() { checkNotNull(message); checkArgument(message.getPayoutTx() != null); + checkArgument(!trade.isDisputed(), "onRejectRequest must not be called once a dispute has started."); + // update to the latest peer address of our peer if the message is correct trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress()); @@ -60,6 +62,7 @@ protected void run() { BtcWalletService.printTx("CanceledTradePayoutTx received from peer", committedCanceledTradePayoutTx); trade.setBuyersCancelTradeState(BuyerTrade.CancelTradeState.RECEIVED_ACCEPTED_MSG); + trade.setState(Trade.State.BUYER_RECEIVED_PAYOUT_TX_PUBLISHED_MSG); // We need to delay that call as we might get executed at startup after mailbox messages are // applied where we iterate over our pending trades. The closeCanceledTrade method would remove diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestRejectedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestRejectedMessage.java index 9f21294037f..964ddabe676 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestRejectedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestRejectedMessage.java @@ -27,6 +27,7 @@ import lombok.extern.slf4j.Slf4j; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; @Slf4j @@ -44,6 +45,8 @@ protected void run() { Validator.checkTradeId(processModel.getOfferId(), message); checkNotNull(message); + checkArgument(!trade.isDisputed(), "onRejectRequest must not be called once a dispute has started."); + // update to the latest peer address of our peer if the message is correct trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress()); trade.setBuyersCancelTradeState(BuyerTrade.CancelTradeState.RECEIVED_REJECTED_MSG); diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SendRequestCancelTradeMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SendRequestCancelTradeMessage.java index 3c183a7380b..b623a2f38ce 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SendRequestCancelTradeMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SendRequestCancelTradeMessage.java @@ -34,6 +34,7 @@ import lombok.extern.slf4j.Slf4j; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; @Slf4j @@ -84,6 +85,8 @@ protected void run() { try { runInterceptHook(); + checkArgument(!trade.isDisputed(), "onRejectRequest must not be called once a dispute has started."); + super.run(); } catch (Throwable t) { failed(t); diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SetupCanceledTradePayoutTxListener.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SetupCanceledTradePayoutTxListener.java index a3da09bbef3..64fbecbdfa6 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SetupCanceledTradePayoutTxListener.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SetupCanceledTradePayoutTxListener.java @@ -49,6 +49,8 @@ protected void run() { protected void setState() { trade.setBuyersCancelTradeState(BuyerTrade.CancelTradeState.PAYOUT_TX_SEEN_IN_NETWORK); if (trade.getPayoutTx() != null) { + trade.setState(Trade.State.BUYER_SAW_PAYOUT_TX_IN_NETWORK); + // We need to delay that call as we might get executed at startup after mailbox messages are // applied where we iterate over our pending trades. The closeCanceledTrade method would remove // that trade from the list causing a ConcurrentModificationException. diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SignCanceledTradePayoutTx.java b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SignCanceledTradePayoutTx.java index 933ab49e423..bc4be35a04d 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SignCanceledTradePayoutTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/cancel/SignCanceledTradePayoutTx.java @@ -51,6 +51,8 @@ protected void run() { try { runInterceptHook(); + checkArgument(!trade.isDisputed(), "onRejectRequest must not be called once a dispute has started."); + TradingPeer tradingPeer = processModel.getTradingPeer(); String tradeId = trade.getId(); BtcWalletService walletService = processModel.getBtcWalletService(); diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/BroadcastCanceledTradePayoutTx.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/BroadcastCanceledTradePayoutTx.java index ce51819638e..8a59c7b39b1 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/BroadcastCanceledTradePayoutTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/BroadcastCanceledTradePayoutTx.java @@ -46,5 +46,6 @@ protected void run() { @Override protected void setState() { trade.setSellersCancelTradeState(SellerTrade.CancelTradeState.REQUEST_ACCEPTED_PAYOUT_TX_PUBLISHED); + trade.setState(Trade.State.SELLER_PUBLISHED_PAYOUT_TX); } } diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/FinalizeCanceledTradePayoutTx.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/FinalizeCanceledTradePayoutTx.java index 5ad98ba4db5..a944e40293b 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/FinalizeCanceledTradePayoutTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/FinalizeCanceledTradePayoutTx.java @@ -51,6 +51,8 @@ protected void run() { try { runInterceptHook(); + checkArgument(!trade.isDisputed(), "onRejectRequest must not be called once a dispute has started."); + Transaction depositTx = checkNotNull(trade.getDepositTx()); String tradeId = trade.getId(); TradingPeer tradingPeer = processModel.getTradingPeer(); @@ -107,8 +109,6 @@ protected void run() { ); trade.setPayoutTx(transaction); - processModel.getTradeManager().closeCanceledTrade(trade); - walletService.swapTradeEntryToAvailableEntry(tradeId, AddressEntry.Context.MULTI_SIG); complete(); } catch (Throwable t) { diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/ProcessRequestCancelTradeMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/ProcessRequestCancelTradeMessage.java index 8c9b2314326..8fab42a8b5b 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/ProcessRequestCancelTradeMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/ProcessRequestCancelTradeMessage.java @@ -27,6 +27,7 @@ import lombok.extern.slf4j.Slf4j; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; @Slf4j @@ -40,10 +41,13 @@ public ProcessRequestCancelTradeMessage(TaskRunner taskHandler, Trade trade) { protected void run() { try { runInterceptHook(); + RequestCancelTradeMessage message = (RequestCancelTradeMessage) processModel.getTradeMessage(); Validator.checkTradeId(processModel.getOfferId(), message); checkNotNull(message); + checkArgument(!trade.isDisputed(), "onRejectRequest must not be called once a dispute has started."); + processModel.getTradingPeer().setCanceledTradePayoutTxSignature(checkNotNull(message.getTxSignature())); // update to the latest peer address of our peer if the message is correct diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestAcceptedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestAcceptedMessage.java index 37a0d8b82bd..3dee1b0d36c 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestAcceptedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestAcceptedMessage.java @@ -31,6 +31,7 @@ import lombok.extern.slf4j.Slf4j; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; @@ -55,21 +56,25 @@ protected TradeMessage getMessage(String id) { @Override protected void setStateSent() { trade.setSellersCancelTradeState(SellerTrade.CancelTradeState.REQUEST_ACCEPTED_MSG_SENT); + trade.setState(Trade.State.SELLER_SENT_PAYOUT_TX_PUBLISHED_MSG); } @Override protected void setStateArrived() { trade.setSellersCancelTradeState(SellerTrade.CancelTradeState.REQUEST_ACCEPTED_MSG_ARRIVED); + trade.setState(Trade.State.SELLER_SAW_ARRIVED_PAYOUT_TX_PUBLISHED_MSG); } @Override protected void setStateStoredInMailbox() { trade.setSellersCancelTradeState(SellerTrade.CancelTradeState.REQUEST_ACCEPTED_MSG_IN_MAILBOX); + trade.setState(Trade.State.SELLER_STORED_IN_MAILBOX_PAYOUT_TX_PUBLISHED_MSG); } @Override protected void setStateFault() { trade.setSellersCancelTradeState(SellerTrade.CancelTradeState.REQUEST_ACCEPTED_MSG_SEND_FAILED); + trade.setState(Trade.State.SELLER_SEND_FAILED_PAYOUT_TX_PUBLISHED_MSG); } @Override @@ -77,6 +82,8 @@ protected void run() { try { runInterceptHook(); + checkArgument(!trade.isDisputed(), "onRejectRequest must not be called once a dispute has started."); + if (trade.getPayoutTx() == null) { log.error("trade.getPayoutTx() = " + trade.getPayoutTx()); failed("PayoutTx is null"); @@ -84,6 +91,8 @@ protected void run() { } super.run(); + + processModel.getTradeManager().closeCanceledTrade(trade); } catch (Throwable t) { failed(t); } diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestRejectedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestRejectedMessage.java index 76c78185a67..fa0001fa6bf 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestRejectedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestRejectedMessage.java @@ -29,6 +29,8 @@ import lombok.extern.slf4j.Slf4j; +import static com.google.common.base.Preconditions.checkArgument; + @Slf4j public class SendCancelTradeRequestRejectedMessage extends SendMailboxMessageTask { @@ -71,6 +73,8 @@ protected void run() { try { runInterceptHook(); + checkArgument(!trade.isDisputed(), "onRejectRequest must not be called once a dispute has started."); + super.run(); } catch (Throwable t) { failed(t); diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index 3675c246d84..4cbb5970429 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -910,22 +910,31 @@ portfolio.failed.cantUnfail=This trade cannot be moved back to open trades at th portfolio.failed.depositTxNull=The trade cannot be completed. Deposit transaction is null portfolio.failed.delayedPayoutTxNull=The trade cannot be completed. Delayed payout transaction is null -portfolio.pending.cancelTrade=Cancel trade -portfolio.pending.requestSent=Cancellation request sent. -portfolio.pending.requestArrived=Cancellation request arrived. Awaiting peer's response. -portfolio.pending.requestInMailbox=Cancellation request stored in mailbox. Awaiting peer's response. -portfolio.pending.requestFailed=Sending cancellation request failed. -portfolio.pending.requestGotAccepted=Your cancellation request was accepted by the peer. \ - The trade is closed and the payout completed.\n\n\ - You can review the details of the trade in the 'History' screen. -portfolio.pending.requestGotRejected=Your cancellation request was rejected by the peer. Please continue with the payment. -portfolio.pending.decideLater=Decide later -portfolio.pending.requestCancelTradePopup=You can send a request to your trading peer for canceling the trade.\n\n\ +portfolio.pending.buyer.requestCancelTrade=Cancel trade request +portfolio.pending.buyer.requestCancelTrade.msg=You can send a request to your trading peer for canceling the trade.\n\n\ If the peer accepts your request you will get back a part of your security deposit. The other part will be given to \ your trading peer as compensation for the lost trade fee, trade opportunity and time.\n\n\ If the peer accepts your cancel request you will get back {0} from your security deposit.\n\n\ Do you want to make a request for cancellation? -portfolio.pending.receivedCancelTradeRequestPopup=Your trading peer requested cancellation of the trade.\n\n\ +portfolio.pending.buyer.request.sent=Cancellation request sent. +portfolio.pending.buyer.request.arrived=Cancellation request arrived. Awaiting peer's response. +portfolio.pending.buyer.request.inMailbox=Request stored in mailbox. Awaiting peer's response. +portfolio.pending.buyer.request.failed=Sending cancellation request failed. Please continue with the payment. +portfolio.pending.buyer.response.accepted=Your cancellation request was accepted by the peer. \ + The trade is closed and the payout completed.\n\n\ + You can review the details of the trade in the 'History' screen. +portfolio.pending.buyer.response.rejected=Cancellation request got rejected. Continue with payment. + + +portfolio.pending.seller.cancelRequest.header=Peer requested for trade cancellation +portfolio.pending.seller.cancelRequest.info=Your peer requested cancellation of the trade. Click the button below for more details. +portfolio.pending.seller.cancelRequest.button=Open cancel trade request details +portfolio.pending.seller.decideLater=Decide later +portfolio.pending.seller.rejectResponse.sent=Reject response sent. +portfolio.pending.seller.rejectResponse.arrived=Reject response arrived. Awaiting that peer continues to send payment. +portfolio.pending.seller.rejectResponse.inMailbox=Reject response stored in mailbox. Awaiting that peer continues to send payment. +portfolio.pending.seller.rejectResponse.failed=Sending reject response failed. Awaiting that peer continues to send payment. +portfolio.pending.seller.receivedCancelTradeRequest.msg=Your trading peer requested cancellation of the trade.\n\n\ If you accept you will get back your trade amount, your security deposit and a part of his security deposit as \ compensation for the lost trade fee, trade opportunity and time.\n\n\ Your payout would be:\n\ @@ -937,6 +946,9 @@ portfolio.pending.receivedCancelTradeRequestPopup=Your trading peer requested ca You can also communicate with the peer via the trader chat to find out about the reason for the cancellation \ request.\n\n\ Do you want to accept the request for cancellation? +portfolio.pending.seller.accepted=You accepted the peer's cancellation request. \ + The trade is closed and the payout completed.\n\n\ + You can review the details of the trade in the 'History' screen. #################################################################### # Funds diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/closedtrades/ClosedTradesViewModel.java b/desktop/src/main/java/bisq/desktop/main/portfolio/closedtrades/ClosedTradesViewModel.java index e359e4f0ee8..bc20ef3a054 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/closedtrades/ClosedTradesViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/closedtrades/ClosedTradesViewModel.java @@ -148,7 +148,11 @@ String getState(ClosedTradableListItem item) { Trade trade = (Trade) item.getTradable(); if (trade.isWithdrawn() || trade.isPayoutPublished()) { - return Res.get("portfolio.closed.completed"); + if (trade.wasCanceledTrade()) { + return Res.get("portfolio.closed.canceled"); + } else { + return Res.get("portfolio.closed.completed"); + } } else if (trade.getDisputeState() == Trade.DisputeState.DISPUTE_CLOSED) { return Res.get("portfolio.closed.ticketClosed"); } else if (trade.getDisputeState() == Trade.DisputeState.MEDIATION_CLOSED) { diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java index d4516bf1525..ca9fd158b04 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/TradeStepView.java @@ -98,6 +98,7 @@ public abstract class TradeStepView extends AnchorPane { private Popup acceptMediationResultPopup; private BootstrapListener bootstrapListener; private TradeSubView.ChatCallback chatCallback; + protected TitledGroupBg titledGroupBg; /////////////////////////////////////////////////////////////////////////////////////////// @@ -326,7 +327,7 @@ protected void addTradeInfoBlock() { } protected void addInfoBlock() { - final TitledGroupBg titledGroupBg = addTitledGroupBg(gridPane, ++gridRow, 1, getInfoBlockTitle(), + titledGroupBg = addTitledGroupBg(gridPane, ++gridRow, 1, getInfoBlockTitle(), Layout.COMPACT_GROUP_DISTANCE); titledGroupBg.getStyleClass().add("last"); GridPane.setColumnSpan(titledGroupBg, 2); @@ -470,7 +471,7 @@ private void updateDisputeState(Trade.DisputeState disputeState) { break; } - updateConfirmButtonDisableState(isDisputed()); + updateConfirmButtonDisableState(trade.isDisputed()); } private void updateMediationResultState(boolean blockOpeningOfResultAcceptedPopup) { @@ -663,10 +664,6 @@ private void updateTradePeriodState(Trade.TradePeriodState tradePeriodState) { // Util /////////////////////////////////////////////////////////////////////////////////////////// - protected boolean isDisputed() { - return trade.getDisputeState() != Trade.DisputeState.NO_DISPUTE; - } - protected Offer getOffer() { return checkNotNull(trade.getOffer()); } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java index fa3fe76b9e0..d8bb9237c76 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyerStep2View.java @@ -349,7 +349,7 @@ public void activate() { }); } - confirmButton.setDisable(isDisputed()); + confirmButton.setDisable(trade.isDisputed()); buyersCancelTradePresentation.activate(); } @@ -401,7 +401,7 @@ protected void applyOnDisputeOpened() { /////////////////////////////////////////////////////////////////////////////////////////// private void onPaymentStarted() { - if (isDisputed()) { + if (trade.isDisputed()) { return; } @@ -529,8 +529,6 @@ private void showConfirmPaymentStartedPopup() { } private void confirmPaymentStarted() { - buyersCancelTradePresentation.hideCancelButton(); - // confirmButton.setDisable(true); busyAnimation.play(); statusLabel.setText(Res.get("shared.sendingConfirmation")); @@ -651,8 +649,5 @@ private void showPopup() { @Override protected void updateConfirmButtonDisableState(boolean isDisabled) { confirmButton.setDisable(isDisabled); - - //TODO - buyersCancelTradePresentation.setDisable(isDisabled); } } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyersCancelTradePresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyersCancelTradePresentation.java index 4d15b2e36cd..80d43880fda 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyersCancelTradePresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyersCancelTradePresentation.java @@ -48,7 +48,8 @@ public class BuyersCancelTradePresentation { private Button cancelTradeButton; private Label msgSentStatusLabel; private BusyAnimation msgSentBusyAnimation; - private ChangeListener listener; + private ChangeListener cancelTradeStateListener; + private ChangeListener disputeStateListener; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor @@ -70,49 +71,47 @@ public class BuyersCancelTradePresentation { public void initialize(HBox hBox, BusyAnimation msgSentBusyAnimation, Label msgSentStatusLabel) { - listener = (observable, oldValue, newValue) -> onStateChanged(newValue); + cancelTradeStateListener = (observable, oldValue, newValue) -> onStateChanged(newValue); this.msgSentBusyAnimation = msgSentBusyAnimation; this.msgSentStatusLabel = msgSentStatusLabel; - cancelTradeButton = new AutoTooltipButton(Res.get("portfolio.pending.cancelTrade")); + cancelTradeButton = new AutoTooltipButton(Res.get("portfolio.pending.buyer.requestCancelTrade")); cancelTradeButton.setOnAction(e -> onRequestCancelTrade()); hBox.getChildren().add(1, cancelTradeButton); + + disputeStateListener = (observable, oldValue, newValue) -> { + onDisputeStateChanged(); + }; } + public void activate() { - trade.getBuyersCancelTradeStateProperty().addListener(listener); + trade.getBuyersCancelTradeStateProperty().addListener(cancelTradeStateListener); onStateChanged(trade.getBuyersCancelTradeStateProperty().get()); + + trade.disputeStateProperty().addListener(disputeStateListener); + onDisputeStateChanged(); } public void deactivate() { - if (listener != null) { - trade.getBuyersCancelTradeStateProperty().removeListener(listener); + if (cancelTradeStateListener != null) { + trade.getBuyersCancelTradeStateProperty().removeListener(cancelTradeStateListener); + } + if (disputeStateListener != null) { + trade.disputeStateProperty().removeListener(disputeStateListener); } } - /////////////////////////////////////////////////////////////////////////////////////////// - // API - /////////////////////////////////////////////////////////////////////////////////////////// - - void hideCancelButton() { - cancelTradeButton.setVisible(false); - cancelTradeButton.setManaged(false); - } - - public void setDisable(boolean isDisabled) { - //todo - // cancelTradeButton.setDisable(isDisabled); - } - /////////////////////////////////////////////////////////////////////////////////////////// // UI handler /////////////////////////////////////////////////////////////////////////////////////////// private void onRequestCancelTrade() { new Popup().width(850) - .attention(Res.get("portfolio.pending.requestCancelTradePopup", + .headLine(Res.get("portfolio.pending.buyer.requestCancelTrade")) + .attention(Res.get("portfolio.pending.buyer.requestCancelTrade.msg", formatter.formatCoinWithCode(manager.getSecurityDepositForRequester()))) .onAction(this::doRequestCancelTrade) .actionButtonText(Res.get("shared.yes")) @@ -120,11 +119,6 @@ private void onRequestCancelTrade() { .show(); } - - /////////////////////////////////////////////////////////////////////////////////////////// - // Private - /////////////////////////////////////////////////////////////////////////////////////////// - private void doRequestCancelTrade() { manager.onRequestCancelTrade(trade, () -> { @@ -135,42 +129,67 @@ private void doRequestCancelTrade() { } + /////////////////////////////////////////////////////////////////////////////////////////// + // State change handler + /////////////////////////////////////////////////////////////////////////////////////////// + + private void onDisputeStateChanged() { + if (trade.isDisputed()) { + disableButton(); + } + } + private void onStateChanged(BuyerTrade.CancelTradeState state) { - log.error("onCanceledTradeStateChanged {} {}", state, trade.getId()); + log.error("onStateChanged {} for trade {}", state, trade.getShortId()); msgSentBusyAnimation.stop(); msgSentStatusLabel.setText(""); if (state == null) { - cancelTradeButton.setDisable(false); + enableButton(); return; } - cancelTradeButton.setDisable(true); + disableButton(); switch (state) { case REQUEST_MSG_SENT: msgSentBusyAnimation.play(); - msgSentStatusLabel.setText(Res.get("portfolio.pending.requestSent")); + msgSentStatusLabel.setText(Res.get("portfolio.pending.buyer.request.sent")); break; case REQUEST_MSG_ARRIVED: - msgSentStatusLabel.setText(Res.get("portfolio.pending.requestArrived")); + msgSentStatusLabel.setText(Res.get("portfolio.pending.buyer.request.arrived")); break; case REQUEST_MSG_IN_MAILBOX: - msgSentStatusLabel.setText(Res.get("portfolio.pending.requestInMailbox")); + msgSentStatusLabel.setText(Res.get("portfolio.pending.buyer.request.inMailbox")); break; case REQUEST_MSG_SEND_FAILED: - msgSentStatusLabel.setText(Res.get("portfolio.pending.requestFailed")); + msgSentStatusLabel.setText(Res.get("portfolio.pending.buyer.request.failed")); break; case RECEIVED_ACCEPTED_MSG: case PAYOUT_TX_SEEN_IN_NETWORK: - new Popup().information(Res.get("portfolio.pending.requestGotAccepted")).show(); + new Popup().information(Res.get("portfolio.pending.buyer.response.accepted")).show(); break; case RECEIVED_REJECTED_MSG: - msgSentStatusLabel.setText(Res.get("portfolio.pending.requestGotRejected")); + msgSentStatusLabel.setText(Res.get("portfolio.pending.buyer.response.rejected")); break; default: break; } } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Private + /////////////////////////////////////////////////////////////////////////////////////////// + + private void disableButton() { + cancelTradeButton.setDisable(true); + } + + private void enableButton() { + if (!trade.isDisputed()) { + cancelTradeButton.setDisable(false); + } + } } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java index d7376c16501..2344e63088b 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java @@ -17,6 +17,7 @@ package bisq.desktop.main.portfolio.pendingtrades.steps.seller; +import bisq.desktop.components.TitledGroupBg; import bisq.desktop.components.paymentmethods.F2FForm; import bisq.desktop.main.portfolio.pendingtrades.PendingTradesViewModel; import bisq.desktop.main.portfolio.pendingtrades.steps.TradeStepView; @@ -30,6 +31,7 @@ import bisq.common.UserThread; import javafx.scene.control.Button; +import javafx.scene.control.Label; import javafx.scene.layout.GridPane; import java.util.Date; @@ -45,6 +47,9 @@ public class SellerStep2View extends TradeStepView { private GridPane refreshButtonPane; private Timer timer; private SellersCancelTradePresentation sellersCancelTradePresentation; + private Button cancelRequestButton; + private Label cancelRequestInfoLabel; + private TitledGroupBg cancelRequestTitledGroupBg; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor @@ -76,9 +81,10 @@ public void initialize() { model.dataModel.getTrade().getOffer(), Layout.COMPACT_FIRST_ROW_AND_GROUP_DISTANCE); } + addCancelRequestBlock(); addRefreshBlock(); - sellersCancelTradePresentation.initialize(); + sellersCancelTradePresentation.initialize(cancelRequestTitledGroupBg, cancelRequestInfoLabel, cancelRequestButton); } @Override @@ -104,15 +110,30 @@ public void deactivate() { // Private /////////////////////////////////////////////////////////////////////////////////////////// + private void addCancelRequestBlock() { + cancelRequestTitledGroupBg = addTitledGroupBg(gridPane, ++gridRow, 2, + Res.get("portfolio.pending.seller.cancelRequest.header"), Layout.COMPACT_GROUP_DISTANCE); + cancelRequestInfoLabel = addMultilineLabel(gridPane, gridRow, Res.get("portfolio.pending.seller.cancelRequest.info"), + Layout.COMPACT_FIRST_ROW_AND_COMPACT_GROUP_DISTANCE); + GridPane.setColumnSpan(cancelRequestInfoLabel, 2); + cancelRequestTitledGroupBg.getStyleClass().add("last"); + titledGroupBg.getStyleClass().remove("last"); + cancelRequestButton = addButtonAfterGroup(gridPane, ++gridRow, Res.get("portfolio.pending.seller.cancelRequest.button")); + } + private void addRefreshBlock() { refreshButtonPane = new GridPane(); - addTitledGroupBg(refreshButtonPane, 0, 1, + TitledGroupBg refreshTitledGroupBg = addTitledGroupBg(refreshButtonPane, 0, 1, Res.get("portfolio.pending.step2_seller.refresh"), Layout.COMPACT_GROUP_DISTANCE); addMultilineLabel(refreshButtonPane, 1, Res.get("portfolio.pending.step2_seller.refreshInfo"), - Layout.COMPACT_FIRST_ROW_DISTANCE); + Layout.COMPACT_FIRST_ROW_AND_COMPACT_GROUP_DISTANCE); Button refreshButton = addButtonAfterGroup(refreshButtonPane, 2, Res.get("portfolio.pending.step2_seller.refresh")); refreshButton.setOnAction(event -> onRefreshButton()); + refreshTitledGroupBg.getStyleClass().add("last"); + cancelRequestTitledGroupBg.getStyleClass().remove("last"); + titledGroupBg.getStyleClass().remove("last"); + GridPane.setRowIndex(refreshButtonPane, ++gridRow); GridPane.setColumnIndex(refreshButtonPane, 0); GridPane.setColumnSpan(refreshButtonPane, 2); @@ -127,8 +148,10 @@ private void activateRefreshButton() { trade.getLastRefreshRequestDate() + trade.getRefreshInterval() - new Date().getTime(); if (timeToNextRefresh <= 0) { refreshButtonPane.setVisible(true); + refreshButtonPane.setManaged(true); } else { refreshButtonPane.setVisible(false); + refreshButtonPane.setManaged(false); timer = UserThread.runAfter(this::activateRefreshButton, timeToNextRefresh, TimeUnit.MILLISECONDS); } } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java index f296b2e98ac..9bdedb8d961 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep3View.java @@ -365,7 +365,7 @@ protected void applyOnDisputeOpened() { /////////////////////////////////////////////////////////////////////////////////////////// private void onPaymentReceived() { - if (isDisputed()) { + if (trade.isDisputed()) { return; } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java index e7a434cacda..78265873270 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java @@ -17,6 +17,7 @@ package bisq.desktop.main.portfolio.pendingtrades.steps.seller; +import bisq.desktop.components.TitledGroupBg; import bisq.desktop.main.overlays.popups.Popup; import bisq.core.locale.Res; @@ -25,6 +26,9 @@ import bisq.core.trade.TradeCancellationManager; import bisq.core.util.coin.CoinFormatter; +import javafx.scene.control.Button; +import javafx.scene.control.Label; + import javafx.beans.value.ChangeListener; import lombok.extern.slf4j.Slf4j; @@ -39,7 +43,11 @@ public class SellersCancelTradePresentation { private final Trade trade; private final TradeCancellationManager manager; private final CoinFormatter formatter; - private ChangeListener listener; + private TitledGroupBg cancelRequestTitledGroupBg; + private Label cancelRequestInfoLabel; + private Button cancelRequestButton; + private ChangeListener cancelTradeStateListener; + private ChangeListener disputeStateListener; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor @@ -58,25 +66,41 @@ public class SellersCancelTradePresentation { // Life cycle /////////////////////////////////////////////////////////////////////////////////////////// - public void initialize() { - listener = (observable, oldValue, newValue) -> onStateChanged(newValue); + public void initialize(TitledGroupBg cancelRequestTitledGroupBg, + Label cancelRequestInfoLabel, + Button cancelRequestButton) { + this.cancelRequestTitledGroupBg = cancelRequestTitledGroupBg; + this.cancelRequestInfoLabel = cancelRequestInfoLabel; + this.cancelRequestButton = cancelRequestButton; + + cancelTradeStateListener = (observable, oldValue, newValue) -> onStateChanged(newValue); + + disputeStateListener = (observable, oldValue, newValue) -> { + onDisputeStateChanged(); + }; } public void activate() { - trade.getSellersCancelTradeStateProperty().addListener(listener); + cancelRequestButton.setOnAction(e -> showPopup()); + + trade.getSellersCancelTradeStateProperty().addListener(cancelTradeStateListener); onStateChanged(trade.getSellersCancelTradeStateProperty().get()); + + trade.disputeStateProperty().addListener(disputeStateListener); + onDisputeStateChanged(); } public void deactivate() { - if (listener != null) { - trade.getSellersCancelTradeStateProperty().removeListener(listener); - } - } + cancelRequestButton.setOnAction(null); + if (cancelTradeStateListener != null) { + trade.getSellersCancelTradeStateProperty().removeListener(cancelTradeStateListener); + } - /////////////////////////////////////////////////////////////////////////////////////////// - // API - /////////////////////////////////////////////////////////////////////////////////////////// + if (disputeStateListener != null) { + trade.disputeStateProperty().removeListener(disputeStateListener); + } + } /////////////////////////////////////////////////////////////////////////////////////////// @@ -84,43 +108,53 @@ public void deactivate() { /////////////////////////////////////////////////////////////////////////////////////////// private void onAcceptRequest() { + hideButton(); manager.onAcceptRequest(trade, () -> { + new Popup().information(Res.get("portfolio.pending.seller.accepted")).show(); }, errorMessage -> { }); } private void onRejectRequest() { + hideButton(); manager.onRejectRequest(trade, () -> { }, errorMessage -> { }); } + private void onDecideLater() { + showButton(); + } + /////////////////////////////////////////////////////////////////////////////////////////// - // Private + // State change handler /////////////////////////////////////////////////////////////////////////////////////////// - private void onStateChanged(SellerTrade.CancelTradeState newValue) { - log.error("onRequestCancelTradeStateChanged {} {}", newValue, trade.getId()); - if (newValue == null) { + private void onDisputeStateChanged() { + if (trade.isDisputed()) { + hideButton(); + } + } + + private void onStateChanged(SellerTrade.CancelTradeState state) { + log.error("onStateChanged {} for trade {}", state, trade.getShortId()); + if (state == null) { + hideAll(); + hideButton(); return; } - switch (newValue) { + + showHeaderAndInfoLabel(); + hideButton(); + + switch (state) { case RECEIVED_REQUEST: - new Popup().width(850) - .attention(Res.get("portfolio.pending.receivedCancelTradeRequestPopup", - formatter.formatCoinWithCode(trade.getTradeAmount()), - formatter.formatCoinWithCode(manager.getDefaultSecDepositOfAcceptingTrader(trade)), - formatter.formatCoinWithCode(manager.getLostSecDepositOfRequestingTrader(trade)))) - .actionButtonText(Res.get("shared.accept")) - .onAction(this::onAcceptRequest) - .secondaryActionButtonText(Res.get("shared.reject")) - .onSecondaryAction(this::onRejectRequest) - .closeButtonText(Res.get("portfolio.pending.decideLater")) - .show(); + showPopup(); break; + case REQUEST_ACCEPTED_PAYOUT_TX_PUBLISHED: break; @@ -134,13 +168,67 @@ private void onStateChanged(SellerTrade.CancelTradeState newValue) { break; case REQUEST_REJECTED_MSG_SENT: + cancelRequestInfoLabel.setText(Res.get("portfolio.pending.seller.rejectResponse.sent")); break; case REQUEST_REJECTED_MSG_ARRIVED: + cancelRequestInfoLabel.setText(Res.get("portfolio.pending.seller.rejectResponse.arrived")); break; case REQUEST_REJECTED_MSG_IN_MAILBOX: + cancelRequestInfoLabel.setText(Res.get("portfolio.pending.seller.rejectResponse.inMailbox")); break; case REQUEST_REJECTED_MSG_SEND_FAILED: + cancelRequestInfoLabel.setText(Res.get("portfolio.pending.seller.rejectResponse.failed")); break; } } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Private + /////////////////////////////////////////////////////////////////////////////////////////// + + private void showPopup() { + if (!trade.isDisputed()) { + new Popup().width(850) + .attention(Res.get("portfolio.pending.seller.receivedCancelTradeRequest.msg", + formatter.formatCoinWithCode(trade.getTradeAmount()), + formatter.formatCoinWithCode(manager.getDefaultSecDepositOfAcceptingTrader(trade)), + formatter.formatCoinWithCode(manager.getLostSecDepositOfRequestingTrader(trade)))) + .actionButtonText(Res.get("shared.accept")) + .onAction(this::onAcceptRequest) + .secondaryActionButtonText(Res.get("shared.reject")) + .onSecondaryAction(this::onRejectRequest) + .closeButtonText(Res.get("portfolio.pending.seller.decideLater")) + .onClose(this::onDecideLater) + .show(); + } + } + + private void showHeaderAndInfoLabel() { + cancelRequestTitledGroupBg.setVisible(true); + cancelRequestTitledGroupBg.setManaged(true); + cancelRequestInfoLabel.setVisible(true); + cancelRequestInfoLabel.setManaged(true); + } + + private void hideAll() { + cancelRequestTitledGroupBg.setVisible(false); + cancelRequestTitledGroupBg.setManaged(false); + cancelRequestInfoLabel.setVisible(false); + cancelRequestInfoLabel.setManaged(false); + cancelRequestButton.setVisible(false); + cancelRequestButton.setManaged(false); + } + + private void hideButton() { + cancelRequestButton.setVisible(false); + cancelRequestButton.setManaged(false); + } + + private void showButton() { + if (!trade.isDisputed()) { + cancelRequestButton.setVisible(true); + cancelRequestButton.setManaged(true); + } + } } From 5148c77a9e98eb6ad819d1d090ff91bc6d7d493c Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 15:58:03 -0500 Subject: [PATCH 31/56] Mark refreshInterval transient. Move static MAX_REFRESH_INTERVAL to top --- core/src/main/java/bisq/core/trade/Trade.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/Trade.java b/core/src/main/java/bisq/core/trade/Trade.java index a2a62b428fd..768044daadf 100644 --- a/core/src/main/java/bisq/core/trade/Trade.java +++ b/core/src/main/java/bisq/core/trade/Trade.java @@ -103,6 +103,7 @@ */ @Slf4j public abstract class Trade implements Tradable, Model { + private static final long MAX_REFRESH_INTERVAL = 4 * ChronoUnit.HOURS.getDuration().toMillis(); /////////////////////////////////////////////////////////////////////////////////////////// // Enums @@ -429,8 +430,7 @@ public static protobuf.Trade.TradePeriodState toProtoMessage(Trade.TradePeriodSt @Setter private long lastRefreshRequestDate; @Getter - private long refreshInterval; - private static final long MAX_REFRESH_INTERVAL = 4 * ChronoUnit.HOURS.getDuration().toMillis(); + transient private long refreshInterval; // Added at v1.3.8 // We use that for the XMR txKey but want to keep it generic to be flexible for other payment methods or assets. From 9e917d5f9255449341771ebbd8887dcd100593f7 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 15:58:52 -0500 Subject: [PATCH 32/56] Use more convenient TimeUnit.HOURS.toMillis API --- core/src/main/java/bisq/core/trade/Trade.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/Trade.java b/core/src/main/java/bisq/core/trade/Trade.java index 768044daadf..d32c2ad3301 100644 --- a/core/src/main/java/bisq/core/trade/Trade.java +++ b/core/src/main/java/bisq/core/trade/Trade.java @@ -79,12 +79,11 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; -import java.time.temporal.ChronoUnit; - import java.util.Date; import java.util.HashSet; import java.util.Optional; import java.util.Set; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import lombok.Getter; @@ -103,7 +102,7 @@ */ @Slf4j public abstract class Trade implements Tradable, Model { - private static final long MAX_REFRESH_INTERVAL = 4 * ChronoUnit.HOURS.getDuration().toMillis(); + private static final long MAX_REFRESH_INTERVAL = TimeUnit.HOURS.toMillis(4); /////////////////////////////////////////////////////////////////////////////////////////// // Enums From 5c62454dd73a91f279b0440385b7420eacb952be Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 16:31:25 -0500 Subject: [PATCH 33/56] Add comments about wrong usage of trade protocol --- .../trade/protocol/BuyerAsMakerProtocol.java | 18 ++++++++++++------ .../trade/protocol/BuyerAsTakerProtocol.java | 18 ++++++++++++------ .../core/trade/protocol/TradeProtocol.java | 3 +++ 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/protocol/BuyerAsMakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/BuyerAsMakerProtocol.java index dde9e2420b4..0b9c9ccd2f1 100644 --- a/core/src/main/java/bisq/core/trade/protocol/BuyerAsMakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/BuyerAsMakerProtocol.java @@ -108,7 +108,7 @@ public void doApplyMailboxTradeMessage(TradeMessage tradeMessage, NodeAddress pe } else if (tradeMessage instanceof PayoutTxPublishedMessage) { handle((PayoutTxPublishedMessage) tradeMessage, peerNodeAddress); } else if (tradeMessage instanceof RefreshTradeStateRequest) { - handle(); + handle((RefreshTradeStateRequest) tradeMessage, peerNodeAddress); } } @@ -199,15 +199,21 @@ private void handle(PayoutTxPublishedMessage tradeMessage, NodeAddress peerNodeA taskRunner.run(); } - private void handle() { - log.debug("handle RefreshTradeStateRequest called"); + // TODO we do not remove the RefreshTradeStateRequest! + // A better approach IMO would be to automatically resend from the buyer side, so the seller does not need to do + // anything. The msg must be the same otherwise we end up with multiple msg and only one get removed once the + // peer processes it. + private void handle(RefreshTradeStateRequest tradeMessage, NodeAddress peerNodeAddress) { + log.debug("handle RefreshTradeStateRequest called with {} from {}", tradeMessage, peerNodeAddress); // Resend CounterCurrencyTransferStartedMessage if it hasn't been acked yet and counterparty asked for a refresh if (trade.getState().getPhase() == Trade.Phase.FIAT_SENT && trade.getState().ordinal() >= Trade.State.BUYER_SENT_FIAT_PAYMENT_INITIATED_MSG.ordinal()) { TradeTaskRunner taskRunner = new TradeTaskRunner(buyerAsMakerTrade, - () -> handleTaskRunnerSuccess("onFiatPaymentStarted"), + () -> handleTaskRunnerSuccess("onRefreshTradeStateRequest"), this::handleTaskRunnerFault); - taskRunner.addTasks(BuyerSendCounterCurrencyTransferStartedMessage.class); + taskRunner.addTasks( + BuyerSendCounterCurrencyTransferStartedMessage.class + ); taskRunner.run(); } } @@ -266,7 +272,7 @@ protected void doHandleDecryptedMessage(TradeMessage tradeMessage, NodeAddress s } else if (tradeMessage instanceof PayoutTxPublishedMessage) { handle((PayoutTxPublishedMessage) tradeMessage, sender); } else if (tradeMessage instanceof RefreshTradeStateRequest) { - handle(); + handle((RefreshTradeStateRequest) tradeMessage, sender); } } } diff --git a/core/src/main/java/bisq/core/trade/protocol/BuyerAsTakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/BuyerAsTakerProtocol.java index c200de343f5..bca0efd4a6c 100644 --- a/core/src/main/java/bisq/core/trade/protocol/BuyerAsTakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/BuyerAsTakerProtocol.java @@ -115,7 +115,7 @@ public void doApplyMailboxTradeMessage(TradeMessage tradeMessage, NodeAddress pe } else if (tradeMessage instanceof PayoutTxPublishedMessage) { handle((PayoutTxPublishedMessage) tradeMessage, peerNodeAddress); } else if (tradeMessage instanceof RefreshTradeStateRequest) { - handle(); + handle((RefreshTradeStateRequest) tradeMessage, peerNodeAddress); } } @@ -222,15 +222,21 @@ private void handle(PayoutTxPublishedMessage tradeMessage, NodeAddress peerNodeA taskRunner.run(); } - private void handle() { - log.debug("handle RefreshTradeStateRequest called"); + // TODO we do not remove the RefreshTradeStateRequest! + // A better approach IMO would be to automatically resend from the buyer side, so the seller does not need to do + // anything. The msg must be the same otherwise we end up with multiple msg and only one get removed once the + // peer processes it. + private void handle(RefreshTradeStateRequest tradeMessage, NodeAddress peerNodeAddress) { + log.debug("handle RefreshTradeStateRequest called with {} from {}", tradeMessage, peerNodeAddress); // Resend CounterCurrencyTransferStartedMessage if it hasn't been acked yet and counterparty asked for a refresh if (trade.getState().getPhase() == Trade.Phase.FIAT_SENT && trade.getState().ordinal() >= Trade.State.BUYER_SENT_FIAT_PAYMENT_INITIATED_MSG.ordinal()) { TradeTaskRunner taskRunner = new TradeTaskRunner(buyerAsTakerTrade, - () -> handleTaskRunnerSuccess("onFiatPaymentStarted"), + () -> handleTaskRunnerSuccess("onRefreshTradeStateRequest"), this::handleTaskRunnerFault); - taskRunner.addTasks(BuyerSendCounterCurrencyTransferStartedMessage.class); + taskRunner.addTasks( + BuyerSendCounterCurrencyTransferStartedMessage.class + ); taskRunner.run(); } } @@ -290,7 +296,7 @@ protected void doHandleDecryptedMessage(TradeMessage tradeMessage, NodeAddress s } else if (tradeMessage instanceof PayoutTxPublishedMessage) { handle((PayoutTxPublishedMessage) tradeMessage, sender); } else if (tradeMessage instanceof RefreshTradeStateRequest) { - handle(); + handle((RefreshTradeStateRequest) tradeMessage, sender); } } } diff --git a/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java b/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java index c49552bccba..94fd76dccd6 100644 --- a/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java @@ -240,6 +240,9 @@ private void handle(PeerPublishedDelayedPayoutTxMessage tradeMessage, NodeAddres // Peer has sent a SignedWitness /////////////////////////////////////////////////////////////////////////////////////////// + // TODO this should not be in the trade protocol. The sending is done in the domain, so should be the handling of + // the msg. If it is part of the normal trade protocol we should add the sending and handling to the steps where + // it happen. private void handle(TraderSignedWitnessMessage tradeMessage) { // Publish signed witness, if it is valid and ours processModel.getAccountAgeWitnessService().publishOwnSignedWitness(tradeMessage.getSignedWitness()); From 8885e8551fc4ab31a8e39d8f25746c3353ff637c Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 17:27:21 -0500 Subject: [PATCH 34/56] Move cancelTrade states to sub classes --- .../bisq/core/trade/BuyerAsMakerTrade.java | 8 +- .../bisq/core/trade/BuyerAsTakerTrade.java | 8 +- .../main/java/bisq/core/trade/BuyerTrade.java | 66 +++++++++++++++- .../bisq/core/trade/SellerAsMakerTrade.java | 8 +- .../bisq/core/trade/SellerAsTakerTrade.java | 8 +- .../java/bisq/core/trade/SellerTrade.java | 66 +++++++++++++++- core/src/main/java/bisq/core/trade/Trade.java | 79 +++++++++++++------ .../protocol/BuyersCancelTradeProtocol.java | 21 ++++- .../protocol/SellersCancelTradeProtocol.java | 19 +++++ ...cessCancelTradeRequestAcceptedMessage.java | 8 +- ...cessCancelTradeRequestRejectedMessage.java | 8 +- .../cancel/SendRequestCancelTradeMessage.java | 15 ++-- .../SetupCanceledTradePayoutTxListener.java | 5 +- .../BroadcastCanceledTradePayoutTx.java | 5 +- .../ProcessRequestCancelTradeMessage.java | 7 +- ...SendCancelTradeRequestAcceptedMessage.java | 16 ++-- ...SendCancelTradeRequestRejectedMessage.java | 15 ++-- .../buyer/BuyersCancelTradePresentation.java | 18 +++-- .../SellersCancelTradePresentation.java | 10 +-- proto/src/main/proto/pb.proto | 3 +- 20 files changed, 322 insertions(+), 71 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/BuyerAsMakerTrade.java b/core/src/main/java/bisq/core/trade/BuyerAsMakerTrade.java index e6cecc1e4f9..8d900195d2f 100644 --- a/core/src/main/java/bisq/core/trade/BuyerAsMakerTrade.java +++ b/core/src/main/java/bisq/core/trade/BuyerAsMakerTrade.java @@ -94,7 +94,7 @@ public static Tradable fromProto(protobuf.BuyerAsMakerTrade buyerAsMakerTradePro trade.setTradePrice(proto.getTradePrice()); trade.setTradingPeerNodeAddress(proto.hasTradingPeerNodeAddress() ? NodeAddress.fromProto(proto.getTradingPeerNodeAddress()) : null); - return fromProto(trade, + return BuyerTrade.fromProto(trade, proto, coreProtoResolver); } @@ -115,4 +115,10 @@ public void handleTakeOfferRequest(InputsForDepositTxRequest message, ErrorMessageHandler errorMessageHandler) { ((MakerProtocol) tradeProtocol).handleTakeOfferRequest(message, taker, errorMessageHandler); } + + + @Override + public String toString() { + return "BuyerAsMakerTrade{} " + super.toString(); + } } diff --git a/core/src/main/java/bisq/core/trade/BuyerAsTakerTrade.java b/core/src/main/java/bisq/core/trade/BuyerAsTakerTrade.java index d9b5f86c290..baaf344da5e 100644 --- a/core/src/main/java/bisq/core/trade/BuyerAsTakerTrade.java +++ b/core/src/main/java/bisq/core/trade/BuyerAsTakerTrade.java @@ -86,7 +86,7 @@ public static Tradable fromProto(protobuf.BuyerAsTakerTrade buyerAsTakerTradePro BtcWalletService btcWalletService, CoreProtoResolver coreProtoResolver) { protobuf.Trade proto = buyerAsTakerTradeProto.getTrade(); - return fromProto(new BuyerAsTakerTrade( + return BuyerTrade.fromProto(new BuyerAsTakerTrade( Offer.fromProto(proto.getOffer()), Coin.valueOf(proto.getTradeAmountAsLong()), Coin.valueOf(proto.getTxFeeAsLong()), @@ -118,4 +118,10 @@ public void takeAvailableOffer() { checkArgument(tradeProtocol instanceof TakerProtocol, "tradeProtocol NOT instanceof TakerProtocol"); ((TakerProtocol) tradeProtocol).takeAvailableOffer(); } + + + @Override + public String toString() { + return "BuyerAsTakerTrade{} " + super.toString(); + } } diff --git a/core/src/main/java/bisq/core/trade/BuyerTrade.java b/core/src/main/java/bisq/core/trade/BuyerTrade.java index 6e100a347ca..3e361a47bbb 100644 --- a/core/src/main/java/bisq/core/trade/BuyerTrade.java +++ b/core/src/main/java/bisq/core/trade/BuyerTrade.java @@ -19,16 +19,26 @@ import bisq.core.btc.wallet.BtcWalletService; import bisq.core.offer.Offer; +import bisq.core.proto.CoreProtoResolver; import bisq.core.trade.protocol.BuyerProtocol; import bisq.network.p2p.NodeAddress; import bisq.common.handlers.ErrorMessageHandler; import bisq.common.handlers.ResultHandler; +import bisq.common.proto.ProtoUtil; import bisq.common.storage.Storage; +import com.google.protobuf.Message; + import org.bitcoinj.core.Coin; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; + +import java.util.Optional; + +import lombok.Getter; import lombok.extern.slf4j.Slf4j; import javax.annotation.Nullable; @@ -50,6 +60,18 @@ public enum CancelTradeState { RECEIVED_REJECTED_MSG } + // Added at v1.3.9 + @Getter + @Nullable + public BuyerTrade.CancelTradeState cancelTradeState; + @Getter + transient final private ObjectProperty cancelTradeStateProperty = new SimpleObjectProperty<>(); + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Constructor + /////////////////////////////////////////////////////////////////////////////////////////// + BuyerTrade(Offer offer, Coin tradeAmount, Coin txFee, @@ -96,6 +118,35 @@ public enum CancelTradeState { btcWalletService); } + /////////////////////////////////////////////////////////////////////////////////////////// + // PROTO BUFFER + /////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public Message toProtoMessage() { + protobuf.Trade.Builder builder = getBuilder(); + Optional.ofNullable(cancelTradeState).ifPresent(e -> builder.setCancelTradeState(cancelTradeState.name())); + return builder.build(); + } + + public static Tradable fromProto(BuyerTrade trade, protobuf.Trade proto, CoreProtoResolver coreProtoResolver) { + trade.setCancelTradeState(ProtoUtil.enumFromProto(BuyerTrade.CancelTradeState.class, proto.getCancelTradeState())); + return Trade.fromProto(trade, + proto, + coreProtoResolver); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // API + /////////////////////////////////////////////////////////////////////////////////////////// + + public void setCancelTradeState(BuyerTrade.CancelTradeState cancelTradeState) { + this.cancelTradeState = cancelTradeState; + cancelTradeStateProperty.set(cancelTradeState); + persist(); + } + public void onFiatPaymentStarted(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { checkArgument(tradeProtocol instanceof BuyerProtocol, "Check failed: tradeProtocol instanceof BuyerProtocol"); ((BuyerProtocol) tradeProtocol).onFiatPaymentStarted(resultHandler, errorMessageHandler); @@ -110,7 +161,11 @@ public Coin getPayoutAmount() { @Override public boolean wasCanceledTrade() { - switch (buyersCancelTradeState) { + if (cancelTradeState == null) { + return false; + } + + switch (cancelTradeState) { case RECEIVED_ACCEPTED_MSG: case PAYOUT_TX_SEEN_IN_NETWORK: return true; @@ -118,4 +173,13 @@ public boolean wasCanceledTrade() { return false; } } + + + @Override + public String toString() { + return "BuyerTrade{" + + "\n buyersCancelTradeState=" + cancelTradeState + + ",\n buyersCancelTradeStateProperty=" + cancelTradeStateProperty + + "\n} " + super.toString(); + } } diff --git a/core/src/main/java/bisq/core/trade/SellerAsMakerTrade.java b/core/src/main/java/bisq/core/trade/SellerAsMakerTrade.java index 5e9b5883f9d..85248f520c4 100644 --- a/core/src/main/java/bisq/core/trade/SellerAsMakerTrade.java +++ b/core/src/main/java/bisq/core/trade/SellerAsMakerTrade.java @@ -95,7 +95,7 @@ public static Tradable fromProto(protobuf.SellerAsMakerTrade sellerAsMakerTradeP trade.setTradePrice(proto.getTradePrice()); trade.setTradingPeerNodeAddress(proto.hasTradingPeerNodeAddress() ? NodeAddress.fromProto(proto.getTradingPeerNodeAddress()) : null); - return fromProto(trade, + return SellerTrade.fromProto(trade, proto, coreProtoResolver); } @@ -114,4 +114,10 @@ protected void createTradeProtocol() { public void handleTakeOfferRequest(InputsForDepositTxRequest message, NodeAddress taker, ErrorMessageHandler errorMessageHandler) { ((MakerProtocol) tradeProtocol).handleTakeOfferRequest(message, taker, errorMessageHandler); } + + + @Override + public String toString() { + return "SellerAsMakerTrade{} " + super.toString(); + } } diff --git a/core/src/main/java/bisq/core/trade/SellerAsTakerTrade.java b/core/src/main/java/bisq/core/trade/SellerAsTakerTrade.java index 79debd8137c..c46e731e45e 100644 --- a/core/src/main/java/bisq/core/trade/SellerAsTakerTrade.java +++ b/core/src/main/java/bisq/core/trade/SellerAsTakerTrade.java @@ -86,7 +86,7 @@ public static Tradable fromProto(protobuf.SellerAsTakerTrade sellerAsTakerTradeP BtcWalletService btcWalletService, CoreProtoResolver coreProtoResolver) { protobuf.Trade proto = sellerAsTakerTradeProto.getTrade(); - return fromProto(new SellerAsTakerTrade( + return SellerTrade.fromProto(new SellerAsTakerTrade( Offer.fromProto(proto.getOffer()), Coin.valueOf(proto.getTradeAmountAsLong()), Coin.valueOf(proto.getTxFeeAsLong()), @@ -118,4 +118,10 @@ public void takeAvailableOffer() { checkArgument(tradeProtocol instanceof TakerProtocol, "tradeProtocol NOT instanceof TakerProtocol"); ((TakerProtocol) tradeProtocol).takeAvailableOffer(); } + + + @Override + public String toString() { + return "SellerAsTakerTrade{} " + super.toString(); + } } diff --git a/core/src/main/java/bisq/core/trade/SellerTrade.java b/core/src/main/java/bisq/core/trade/SellerTrade.java index 15e12e2d8b4..cd5ad3e8840 100644 --- a/core/src/main/java/bisq/core/trade/SellerTrade.java +++ b/core/src/main/java/bisq/core/trade/SellerTrade.java @@ -19,16 +19,26 @@ import bisq.core.btc.wallet.BtcWalletService; import bisq.core.offer.Offer; +import bisq.core.proto.CoreProtoResolver; import bisq.core.trade.protocol.SellerProtocol; import bisq.network.p2p.NodeAddress; import bisq.common.handlers.ErrorMessageHandler; import bisq.common.handlers.ResultHandler; +import bisq.common.proto.ProtoUtil; import bisq.common.storage.Storage; +import com.google.protobuf.Message; + import org.bitcoinj.core.Coin; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; + +import java.util.Optional; + +import lombok.Getter; import lombok.extern.slf4j.Slf4j; import javax.annotation.Nullable; @@ -53,6 +63,18 @@ public enum CancelTradeState { REQUEST_REJECTED_MSG_SEND_FAILED } + // Added at v1.3.9 + @Getter + @Nullable + public SellerTrade.CancelTradeState cancelTradeState; + @Getter + transient final private ObjectProperty cancelTradeStateProperty = new SimpleObjectProperty<>(); + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Constructor + /////////////////////////////////////////////////////////////////////////////////////////// + SellerTrade(Offer offer, Coin tradeAmount, Coin txFee, @@ -99,6 +121,36 @@ public enum CancelTradeState { btcWalletService); } + + /////////////////////////////////////////////////////////////////////////////////////////// + // PROTO BUFFER + /////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public Message toProtoMessage() { + protobuf.Trade.Builder builder = getBuilder(); + Optional.ofNullable(cancelTradeState).ifPresent(e -> builder.setCancelTradeState(cancelTradeState.name())); + return builder.build(); + } + + public static Tradable fromProto(SellerTrade trade, protobuf.Trade proto, CoreProtoResolver coreProtoResolver) { + trade.setCancelTradeState(ProtoUtil.enumFromProto(SellerTrade.CancelTradeState.class, proto.getCancelTradeState())); + return Trade.fromProto(trade, + proto, + coreProtoResolver); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // API + /////////////////////////////////////////////////////////////////////////////////////////// + + public void setCancelTradeState(SellerTrade.CancelTradeState cancelTradeState) { + this.cancelTradeState = cancelTradeState; + cancelTradeStateProperty.set(cancelTradeState); + persist(); + } + public void onFiatPaymentReceived(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { checkArgument(tradeProtocol instanceof SellerProtocol, "tradeProtocol NOT instanceof SellerProtocol"); ((SellerProtocol) tradeProtocol).onFiatPaymentReceived(resultHandler, errorMessageHandler); @@ -111,7 +163,10 @@ public Coin getPayoutAmount() { @Override public boolean wasCanceledTrade() { - switch (sellersCancelTradeState) { + if (cancelTradeState == null) { + return false; + } + switch (cancelTradeState) { case REQUEST_ACCEPTED_PAYOUT_TX_PUBLISHED: case REQUEST_ACCEPTED_MSG_SENT: case REQUEST_ACCEPTED_MSG_ARRIVED: @@ -122,5 +177,14 @@ public boolean wasCanceledTrade() { return false; } } + + + @Override + public String toString() { + return "SellerTrade{" + + "\n sellersCancelTradeState=" + cancelTradeState + + ",\n sellersCancelTradeStateProperty=" + cancelTradeStateProperty + + "\n} " + super.toString(); + } } diff --git a/core/src/main/java/bisq/core/trade/Trade.java b/core/src/main/java/bisq/core/trade/Trade.java index d32c2ad3301..32c2c2cc2ce 100644 --- a/core/src/main/java/bisq/core/trade/Trade.java +++ b/core/src/main/java/bisq/core/trade/Trade.java @@ -57,7 +57,6 @@ import bisq.common.util.Utilities; import com.google.protobuf.ByteString; -import com.google.protobuf.Message; import org.bitcoinj.core.Coin; import org.bitcoinj.core.Transaction; @@ -449,17 +448,17 @@ public static protobuf.Trade.TradePeriodState toProtoMessage(Trade.TradePeriodSt @Getter transient final private IntegerProperty assetTxProofResultUpdateProperty = new SimpleIntegerProperty(); - @Getter + /* @Getter // Added at v1.3.9 public SellerTrade.CancelTradeState sellersCancelTradeState; @Getter transient final private ObjectProperty sellersCancelTradeStateProperty = new SimpleObjectProperty<>(); - - @Getter +*/ + /*@Getter public BuyerTrade.CancelTradeState buyersCancelTradeState; @Getter transient final private ObjectProperty buyersCancelTradeStateProperty = new SimpleObjectProperty<>(); - +*/ /////////////////////////////////////////////////////////////////////////////////////////// // Constructor, initialization @@ -529,9 +528,9 @@ protected Trade(Offer offer, // PROTO BUFFER /////////////////////////////////////////////////////////////////////////////////////////// - @Override + /* @Override public Message toProtoMessage() { - final protobuf.Trade.Builder builder = protobuf.Trade.newBuilder() + protobuf.Trade.Builder builder = getBuilder() .setOffer(checkNotNull(offer).toProtoMessage()) .setIsCurrencyForTakerFeeBtc(isCurrencyForTakerFeeBtc) .setTxFeeAsLong(txFeeAsLong) @@ -573,10 +572,56 @@ public Message toProtoMessage() { Optional.ofNullable(delayedPayoutTxBytes).ifPresent(e -> builder.setDelayedPayoutTxBytes(ByteString.copyFrom(delayedPayoutTxBytes))); Optional.ofNullable(counterCurrencyExtraData).ifPresent(e -> builder.setCounterCurrencyExtraData(counterCurrencyExtraData)); Optional.ofNullable(assetTxProofResult).ifPresent(e -> builder.setAssetTxProofResult(assetTxProofResult.name())); - Optional.ofNullable(sellersCancelTradeState).ifPresent(e -> builder.setSellersCancelTradeState(sellersCancelTradeState.name())); - Optional.ofNullable(buyersCancelTradeState).ifPresent(e -> builder.setBuyersCancelTradeState(buyersCancelTradeState.name())); + Optional.ofNullable(sellersCancelTradeState).ifPresent(e -> builder.setCancelTradeState(sellersCancelTradeState.name())); + Optional.ofNullable(buyersCancelTradeState).ifPresent(e -> builder.setCancelTradeState(buyersCancelTradeState.name())); return builder.build(); + }*/ + + protected protobuf.Trade.Builder getBuilder() { + protobuf.Trade.Builder builder = protobuf.Trade.newBuilder() + .setOffer(checkNotNull(offer).toProtoMessage()) + .setIsCurrencyForTakerFeeBtc(isCurrencyForTakerFeeBtc) + .setTxFeeAsLong(txFeeAsLong) + .setTakerFeeAsLong(takerFeeAsLong) + .setTakeOfferDate(takeOfferDate) + .setProcessModel(processModel.toProtoMessage()) + .setTradeAmountAsLong(tradeAmountAsLong) + .setTradePrice(tradePrice) + .setState(Trade.State.toProtoMessage(state)) + .setDisputeState(Trade.DisputeState.toProtoMessage(disputeState)) + .setTradePeriodState(Trade.TradePeriodState.toProtoMessage(tradePeriodState)) + .addAllChatMessage(chatMessages.stream() + .map(msg -> msg.toProtoNetworkEnvelope().getChatMessage()) + .collect(Collectors.toList())) + .setLockTime(lockTime) + .setLastRefreshRequestDate(lastRefreshRequestDate); + + Optional.ofNullable(takerFeeTxId).ifPresent(builder::setTakerFeeTxId); + Optional.ofNullable(depositTxId).ifPresent(builder::setDepositTxId); + Optional.ofNullable(payoutTxId).ifPresent(builder::setPayoutTxId); + Optional.ofNullable(tradingPeerNodeAddress).ifPresent(e -> builder.setTradingPeerNodeAddress(tradingPeerNodeAddress.toProtoMessage())); + Optional.ofNullable(contract).ifPresent(e -> builder.setContract(contract.toProtoMessage())); + Optional.ofNullable(contractAsJson).ifPresent(builder::setContractAsJson); + Optional.ofNullable(contractHash).ifPresent(e -> builder.setContractHash(ByteString.copyFrom(contractHash))); + Optional.ofNullable(takerContractSignature).ifPresent(builder::setTakerContractSignature); + Optional.ofNullable(makerContractSignature).ifPresent(builder::setMakerContractSignature); + Optional.ofNullable(arbitratorNodeAddress).ifPresent(e -> builder.setArbitratorNodeAddress(arbitratorNodeAddress.toProtoMessage())); + Optional.ofNullable(mediatorNodeAddress).ifPresent(e -> builder.setMediatorNodeAddress(mediatorNodeAddress.toProtoMessage())); + Optional.ofNullable(refundAgentNodeAddress).ifPresent(e -> builder.setRefundAgentNodeAddress(refundAgentNodeAddress.toProtoMessage())); + Optional.ofNullable(arbitratorBtcPubKey).ifPresent(e -> builder.setArbitratorBtcPubKey(ByteString.copyFrom(arbitratorBtcPubKey))); + Optional.ofNullable(takerPaymentAccountId).ifPresent(builder::setTakerPaymentAccountId); + Optional.ofNullable(errorMessage).ifPresent(builder::setErrorMessage); + Optional.ofNullable(arbitratorPubKeyRing).ifPresent(e -> builder.setArbitratorPubKeyRing(arbitratorPubKeyRing.toProtoMessage())); + Optional.ofNullable(mediatorPubKeyRing).ifPresent(e -> builder.setMediatorPubKeyRing(mediatorPubKeyRing.toProtoMessage())); + Optional.ofNullable(refundAgentPubKeyRing).ifPresent(e -> builder.setRefundAgentPubKeyRing(refundAgentPubKeyRing.toProtoMessage())); + Optional.ofNullable(counterCurrencyTxId).ifPresent(e -> builder.setCounterCurrencyTxId(counterCurrencyTxId)); + Optional.ofNullable(mediationResultState).ifPresent(e -> builder.setMediationResultState(MediationResultState.toProtoMessage(mediationResultState))); + Optional.ofNullable(refundResultState).ifPresent(e -> builder.setRefundResultState(RefundResultState.toProtoMessage(refundResultState))); + Optional.ofNullable(delayedPayoutTxBytes).ifPresent(e -> builder.setDelayedPayoutTxBytes(ByteString.copyFrom(delayedPayoutTxBytes))); + Optional.ofNullable(counterCurrencyExtraData).ifPresent(e -> builder.setCounterCurrencyExtraData(counterCurrencyExtraData)); + Optional.ofNullable(assetTxProofResult).ifPresent(e -> builder.setAssetTxProofResult(assetTxProofResult.name())); + return builder; } public static Trade fromProto(Trade trade, protobuf.Trade proto, CoreProtoResolver coreProtoResolver) { @@ -617,9 +662,6 @@ public static Trade fromProto(Trade trade, protobuf.Trade proto, CoreProtoResolv } trade.setAssetTxProofResult(persistedAssetTxProofResult); - trade.setSellersCancelTradeState(ProtoUtil.enumFromProto(SellerTrade.CancelTradeState.class, proto.getSellersCancelTradeState())); - trade.setBuyersCancelTradeState(ProtoUtil.enumFromProto(BuyerTrade.CancelTradeState.class, proto.getBuyersCancelTradeState())); - trade.chatMessages.addAll(proto.getChatMessageList().stream() .map(ChatMessage::fromPayloadProto) .collect(Collectors.toList())); @@ -910,17 +952,6 @@ public void setAssetTxProofResult(@Nullable AssetTxProofResult assetTxProofResul persist(); } - public void setSellersCancelTradeState(SellerTrade.CancelTradeState cancelTradeState) { - this.sellersCancelTradeState = cancelTradeState; - sellersCancelTradeStateProperty.set(cancelTradeState); - persist(); - } - - public void setBuyersCancelTradeState(BuyerTrade.CancelTradeState cancelTradeState) { - this.buyersCancelTradeState = cancelTradeState; - buyersCancelTradeStateProperty.set(cancelTradeState); - persist(); - } /////////////////////////////////////////////////////////////////////////////////////////// // Getter @@ -1262,8 +1293,6 @@ public String toString() { ",\n refundResultState=" + refundResultState + ",\n refundResultStateProperty=" + refundResultStateProperty + ",\n lastRefreshRequestDate=" + lastRefreshRequestDate + - ",\n sellersCancelTradeState=" + sellersCancelTradeState + - ",\n buyersCancelTradeState=" + buyersCancelTradeState + "\n}"; } } diff --git a/core/src/main/java/bisq/core/trade/protocol/BuyersCancelTradeProtocol.java b/core/src/main/java/bisq/core/trade/protocol/BuyersCancelTradeProtocol.java index 1b63e44b067..109cb3dcd4e 100644 --- a/core/src/main/java/bisq/core/trade/protocol/BuyersCancelTradeProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/BuyersCancelTradeProtocol.java @@ -33,6 +33,9 @@ import bisq.common.handlers.ErrorMessageHandler; import bisq.common.handlers.ResultHandler; +import lombok.extern.slf4j.Slf4j; + +@Slf4j public class BuyersCancelTradeProtocol extends CancelTradeProtocol { BuyersCancelTradeProtocol(Trade trade) { @@ -45,6 +48,11 @@ public class BuyersCancelTradeProtocol extends CancelTradeProtocol { /////////////////////////////////////////////////////////////////////////////////////////// public void onRequestCancelTrade(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { + if (trade.isDisputed()) { + log.info("We got onRequestCancelTrade called but the trade have been disputed already. We ignore the call."); + return; + } + TradeTaskRunner taskRunner = new TradeTaskRunner(trade, () -> { resultHandler.handleResult(); @@ -72,6 +80,12 @@ protected void handle(CancelTradeRequestAcceptedMessage tradeMessage, NodeAddres trade.getProcessModel().setTradeMessage(tradeMessage); trade.getProcessModel().setTempTradingPeerNodeAddress(sender); + if (trade.isDisputed()) { + log.info("We received a CancelTradeRequestAcceptedMessage but the trade have been disputed already. We ignore the message."); + trade.getProcessModel().removeMailboxMessageAfterProcessing(trade); + return; + } + TradeTaskRunner taskRunner = new TradeTaskRunner(trade, () -> handleTaskRunnerSuccess(tradeMessage, "handle CancelTradeRequestAcceptedMessage"), errorMessage -> handleTaskRunnerFault(tradeMessage, errorMessage)); @@ -82,11 +96,16 @@ protected void handle(CancelTradeRequestAcceptedMessage tradeMessage, NodeAddres taskRunner.run(); } - protected void handle(CancelTradeRequestRejectedMessage tradeMessage, NodeAddress sender) { trade.getProcessModel().setTradeMessage(tradeMessage); trade.getProcessModel().setTempTradingPeerNodeAddress(sender); + if (trade.isDisputed()) { + log.info("We received a CancelTradeRequestRejectedMessage but the trade have been disputed already. We ignore the request."); + trade.getProcessModel().removeMailboxMessageAfterProcessing(trade); + return; + } + TradeTaskRunner taskRunner = new TradeTaskRunner(trade, () -> handleTaskRunnerSuccess(tradeMessage, "handle CancelTradeRequestRejectedMessage"), errorMessage -> handleTaskRunnerFault(tradeMessage, errorMessage)); diff --git a/core/src/main/java/bisq/core/trade/protocol/SellersCancelTradeProtocol.java b/core/src/main/java/bisq/core/trade/protocol/SellersCancelTradeProtocol.java index 4ae4decc0e1..bc581b48d49 100644 --- a/core/src/main/java/bisq/core/trade/protocol/SellersCancelTradeProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/SellersCancelTradeProtocol.java @@ -33,6 +33,9 @@ import bisq.common.handlers.ErrorMessageHandler; import bisq.common.handlers.ResultHandler; +import lombok.extern.slf4j.Slf4j; + +@Slf4j public class SellersCancelTradeProtocol extends CancelTradeProtocol { SellersCancelTradeProtocol(Trade trade) { @@ -50,6 +53,11 @@ public void onAcceptRequest(ResultHandler resultHandler, ErrorMessageHandler err return; } + if (trade.isDisputed()) { + log.info("We got onAcceptRequest called but the trade have been disputed already. We ignore the call."); + return; + } + TradeTaskRunner taskRunner = new TradeTaskRunner(trade, () -> { resultHandler.handleResult(); @@ -75,6 +83,11 @@ public void onRejectRequest(ResultHandler resultHandler, ErrorMessageHandler err return; } + if (trade.isDisputed()) { + log.info("We got onRejectRequest called but the trade have been disputed already. We ignore the call."); + return; + } + TradeTaskRunner taskRunner = new TradeTaskRunner(trade, () -> { resultHandler.handleResult(); @@ -100,6 +113,12 @@ protected void handle(RequestCancelTradeMessage tradeMessage, NodeAddress sender trade.getProcessModel().setTradeMessage(tradeMessage); trade.getProcessModel().setTempTradingPeerNodeAddress(sender); + if (trade.isDisputed()) { + log.info("We received a RequestCancelTradeMessage but the trade have been disputed already. We ignore the message."); + trade.getProcessModel().removeMailboxMessageAfterProcessing(trade); + return; + } + TradeTaskRunner taskRunner = new TradeTaskRunner(trade, () -> handleTaskRunnerSuccess(tradeMessage, "handle RequestCancelTradeMessage"), errorMessage -> handleTaskRunnerFault(tradeMessage, errorMessage)); diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestAcceptedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestAcceptedMessage.java index a84880e1ed0..9ff4af591a8 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestAcceptedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestAcceptedMessage.java @@ -46,13 +46,14 @@ public ProcessCancelTradeRequestAcceptedMessage(TaskRunner taskHandler, Trade tr protected void run() { try { runInterceptHook(); + + checkArgument(!trade.isDisputed(), "A dispute has already started."); + CancelTradeRequestAcceptedMessage message = (CancelTradeRequestAcceptedMessage) processModel.getTradeMessage(); Validator.checkTradeId(processModel.getOfferId(), message); checkNotNull(message); checkArgument(message.getPayoutTx() != null); - checkArgument(!trade.isDisputed(), "onRejectRequest must not be called once a dispute has started."); - // update to the latest peer address of our peer if the message is correct trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress()); @@ -61,7 +62,8 @@ protected void run() { trade.setPayoutTx(committedCanceledTradePayoutTx); BtcWalletService.printTx("CanceledTradePayoutTx received from peer", committedCanceledTradePayoutTx); - trade.setBuyersCancelTradeState(BuyerTrade.CancelTradeState.RECEIVED_ACCEPTED_MSG); + checkArgument(trade instanceof BuyerTrade); + (((BuyerTrade) trade)).setCancelTradeState(BuyerTrade.CancelTradeState.RECEIVED_ACCEPTED_MSG); trade.setState(Trade.State.BUYER_RECEIVED_PAYOUT_TX_PUBLISHED_MSG); // We need to delay that call as we might get executed at startup after mailbox messages are diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestRejectedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestRejectedMessage.java index 964ddabe676..2e7011484e6 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestRejectedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestRejectedMessage.java @@ -41,15 +41,17 @@ public ProcessCancelTradeRequestRejectedMessage(TaskRunner taskHandler, Trade tr protected void run() { try { runInterceptHook(); + + checkArgument(!trade.isDisputed(), "A dispute has already started."); + CancelTradeRequestRejectedMessage message = (CancelTradeRequestRejectedMessage) processModel.getTradeMessage(); Validator.checkTradeId(processModel.getOfferId(), message); checkNotNull(message); - checkArgument(!trade.isDisputed(), "onRejectRequest must not be called once a dispute has started."); - // update to the latest peer address of our peer if the message is correct trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress()); - trade.setBuyersCancelTradeState(BuyerTrade.CancelTradeState.RECEIVED_REJECTED_MSG); + checkArgument(trade instanceof BuyerTrade); + (((BuyerTrade) trade)).setCancelTradeState(BuyerTrade.CancelTradeState.RECEIVED_REJECTED_MSG); processModel.removeMailboxMessageAfterProcessing(trade); complete(); } catch (Throwable t) { diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SendRequestCancelTradeMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SendRequestCancelTradeMessage.java index b623a2f38ce..1d4e26f87d5 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SendRequestCancelTradeMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SendRequestCancelTradeMessage.java @@ -39,9 +39,14 @@ @Slf4j public class SendRequestCancelTradeMessage extends SendMailboxMessageTask { + private final BuyerTrade buyerTrade; + @SuppressWarnings({"unused"}) public SendRequestCancelTradeMessage(TaskRunner taskHandler, Trade trade) { super(taskHandler, trade); + + checkArgument(trade instanceof BuyerTrade); + buyerTrade = ((BuyerTrade) trade); } @Override @@ -62,22 +67,22 @@ protected TradeMessage getMessage(String id) { @Override protected void setStateSent() { - trade.setBuyersCancelTradeState(BuyerTrade.CancelTradeState.REQUEST_MSG_SENT); + buyerTrade.setCancelTradeState(BuyerTrade.CancelTradeState.REQUEST_MSG_SENT); } @Override protected void setStateArrived() { - trade.setBuyersCancelTradeState(BuyerTrade.CancelTradeState.REQUEST_MSG_ARRIVED); + buyerTrade.setCancelTradeState(BuyerTrade.CancelTradeState.REQUEST_MSG_ARRIVED); } @Override protected void setStateStoredInMailbox() { - trade.setBuyersCancelTradeState(BuyerTrade.CancelTradeState.REQUEST_MSG_IN_MAILBOX); + buyerTrade.setCancelTradeState(BuyerTrade.CancelTradeState.REQUEST_MSG_IN_MAILBOX); } @Override protected void setStateFault() { - trade.setBuyersCancelTradeState(BuyerTrade.CancelTradeState.REQUEST_MSG_SEND_FAILED); + buyerTrade.setCancelTradeState(BuyerTrade.CancelTradeState.REQUEST_MSG_SEND_FAILED); } @Override @@ -85,7 +90,7 @@ protected void run() { try { runInterceptHook(); - checkArgument(!trade.isDisputed(), "onRejectRequest must not be called once a dispute has started."); + checkArgument(!trade.isDisputed(), "A dispute has already started."); super.run(); } catch (Throwable t) { diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SetupCanceledTradePayoutTxListener.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SetupCanceledTradePayoutTxListener.java index 64fbecbdfa6..4b2fc1b73af 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SetupCanceledTradePayoutTxListener.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SetupCanceledTradePayoutTxListener.java @@ -26,6 +26,8 @@ import lombok.extern.slf4j.Slf4j; +import static com.google.common.base.Preconditions.checkArgument; + @Slf4j public class SetupCanceledTradePayoutTxListener extends SetupPayoutTxListener { @SuppressWarnings({"unused"}) @@ -47,7 +49,8 @@ protected void run() { @Override protected void setState() { - trade.setBuyersCancelTradeState(BuyerTrade.CancelTradeState.PAYOUT_TX_SEEN_IN_NETWORK); + checkArgument(trade instanceof BuyerTrade); + (((BuyerTrade) trade)).setCancelTradeState(BuyerTrade.CancelTradeState.PAYOUT_TX_SEEN_IN_NETWORK); if (trade.getPayoutTx() != null) { trade.setState(Trade.State.BUYER_SAW_PAYOUT_TX_IN_NETWORK); diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/BroadcastCanceledTradePayoutTx.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/BroadcastCanceledTradePayoutTx.java index 8a59c7b39b1..4947eb23bde 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/BroadcastCanceledTradePayoutTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/BroadcastCanceledTradePayoutTx.java @@ -25,6 +25,8 @@ import lombok.extern.slf4j.Slf4j; +import static com.google.common.base.Preconditions.checkArgument; + @Slf4j public class BroadcastCanceledTradePayoutTx extends BroadcastPayoutTx { @SuppressWarnings({"unused"}) @@ -45,7 +47,8 @@ protected void run() { @Override protected void setState() { - trade.setSellersCancelTradeState(SellerTrade.CancelTradeState.REQUEST_ACCEPTED_PAYOUT_TX_PUBLISHED); + checkArgument(trade instanceof SellerTrade); + ((SellerTrade) trade).setCancelTradeState(SellerTrade.CancelTradeState.REQUEST_ACCEPTED_PAYOUT_TX_PUBLISHED); trade.setState(Trade.State.SELLER_PUBLISHED_PAYOUT_TX); } } diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/ProcessRequestCancelTradeMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/ProcessRequestCancelTradeMessage.java index 8fab42a8b5b..b31ddaa0aa9 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/ProcessRequestCancelTradeMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/ProcessRequestCancelTradeMessage.java @@ -42,19 +42,20 @@ protected void run() { try { runInterceptHook(); + checkArgument(!trade.isDisputed(), "A dispute has already started."); + RequestCancelTradeMessage message = (RequestCancelTradeMessage) processModel.getTradeMessage(); Validator.checkTradeId(processModel.getOfferId(), message); checkNotNull(message); - checkArgument(!trade.isDisputed(), "onRejectRequest must not be called once a dispute has started."); - processModel.getTradingPeer().setCanceledTradePayoutTxSignature(checkNotNull(message.getTxSignature())); // update to the latest peer address of our peer if the message is correct trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress()); processModel.removeMailboxMessageAfterProcessing(trade); - trade.setSellersCancelTradeState(SellerTrade.CancelTradeState.RECEIVED_REQUEST); + checkArgument(trade instanceof SellerTrade); + ((SellerTrade) trade).setCancelTradeState(SellerTrade.CancelTradeState.RECEIVED_REQUEST); complete(); } catch (Throwable t) { diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestAcceptedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestAcceptedMessage.java index 3dee1b0d36c..157e1e82dfd 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestAcceptedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestAcceptedMessage.java @@ -37,9 +37,14 @@ @Slf4j public class SendCancelTradeRequestAcceptedMessage extends SendMailboxMessageTask { + private final SellerTrade sellerTrade; + @SuppressWarnings({"unused"}) public SendCancelTradeRequestAcceptedMessage(TaskRunner taskHandler, Trade trade) { super(taskHandler, trade); + + checkArgument(trade instanceof SellerTrade); + sellerTrade = (SellerTrade) trade; } @Override @@ -55,25 +60,26 @@ protected TradeMessage getMessage(String id) { @Override protected void setStateSent() { - trade.setSellersCancelTradeState(SellerTrade.CancelTradeState.REQUEST_ACCEPTED_MSG_SENT); + sellerTrade.setCancelTradeState(SellerTrade.CancelTradeState.REQUEST_ACCEPTED_MSG_SENT); trade.setState(Trade.State.SELLER_SENT_PAYOUT_TX_PUBLISHED_MSG); } + @Override protected void setStateArrived() { - trade.setSellersCancelTradeState(SellerTrade.CancelTradeState.REQUEST_ACCEPTED_MSG_ARRIVED); + sellerTrade.setCancelTradeState(SellerTrade.CancelTradeState.REQUEST_ACCEPTED_MSG_ARRIVED); trade.setState(Trade.State.SELLER_SAW_ARRIVED_PAYOUT_TX_PUBLISHED_MSG); } @Override protected void setStateStoredInMailbox() { - trade.setSellersCancelTradeState(SellerTrade.CancelTradeState.REQUEST_ACCEPTED_MSG_IN_MAILBOX); + sellerTrade.setCancelTradeState(SellerTrade.CancelTradeState.REQUEST_ACCEPTED_MSG_IN_MAILBOX); trade.setState(Trade.State.SELLER_STORED_IN_MAILBOX_PAYOUT_TX_PUBLISHED_MSG); } @Override protected void setStateFault() { - trade.setSellersCancelTradeState(SellerTrade.CancelTradeState.REQUEST_ACCEPTED_MSG_SEND_FAILED); + sellerTrade.setCancelTradeState(SellerTrade.CancelTradeState.REQUEST_ACCEPTED_MSG_SEND_FAILED); trade.setState(Trade.State.SELLER_SEND_FAILED_PAYOUT_TX_PUBLISHED_MSG); } @@ -82,7 +88,7 @@ protected void run() { try { runInterceptHook(); - checkArgument(!trade.isDisputed(), "onRejectRequest must not be called once a dispute has started."); + checkArgument(!trade.isDisputed(), "A dispute has already started."); if (trade.getPayoutTx() == null) { log.error("trade.getPayoutTx() = " + trade.getPayoutTx()); diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestRejectedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestRejectedMessage.java index fa0001fa6bf..fb217b42039 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestRejectedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestRejectedMessage.java @@ -34,9 +34,14 @@ @Slf4j public class SendCancelTradeRequestRejectedMessage extends SendMailboxMessageTask { + private final SellerTrade sellerTrade; + @SuppressWarnings({"unused"}) public SendCancelTradeRequestRejectedMessage(TaskRunner taskHandler, Trade trade) { super(taskHandler, trade); + + checkArgument(trade instanceof SellerTrade); + sellerTrade = ((SellerTrade) trade); } @Override @@ -50,22 +55,22 @@ protected TradeMessage getMessage(String id) { @Override protected void setStateSent() { - trade.setSellersCancelTradeState(SellerTrade.CancelTradeState.REQUEST_REJECTED_MSG_SENT); + sellerTrade.setCancelTradeState(SellerTrade.CancelTradeState.REQUEST_REJECTED_MSG_SENT); } @Override protected void setStateArrived() { - trade.setSellersCancelTradeState(SellerTrade.CancelTradeState.REQUEST_REJECTED_MSG_ARRIVED); + sellerTrade.setCancelTradeState(SellerTrade.CancelTradeState.REQUEST_REJECTED_MSG_ARRIVED); } @Override protected void setStateStoredInMailbox() { - trade.setSellersCancelTradeState(SellerTrade.CancelTradeState.REQUEST_REJECTED_MSG_IN_MAILBOX); + sellerTrade.setCancelTradeState(SellerTrade.CancelTradeState.REQUEST_REJECTED_MSG_IN_MAILBOX); } @Override protected void setStateFault() { - trade.setSellersCancelTradeState(SellerTrade.CancelTradeState.REQUEST_REJECTED_MSG_SEND_FAILED); + sellerTrade.setCancelTradeState(SellerTrade.CancelTradeState.REQUEST_REJECTED_MSG_SEND_FAILED); } @Override @@ -73,7 +78,7 @@ protected void run() { try { runInterceptHook(); - checkArgument(!trade.isDisputed(), "onRejectRequest must not be called once a dispute has started."); + checkArgument(!trade.isDisputed(), "A dispute has already started."); super.run(); } catch (Throwable t) { diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyersCancelTradePresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyersCancelTradePresentation.java index 80d43880fda..1bec8083296 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyersCancelTradePresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyersCancelTradePresentation.java @@ -42,7 +42,7 @@ */ @Slf4j public class BuyersCancelTradePresentation { - private final Trade trade; + private final BuyerTrade trade; private final TradeCancellationManager manager; private final CoinFormatter formatter; private Button cancelTradeButton; @@ -58,7 +58,7 @@ public class BuyersCancelTradePresentation { BuyersCancelTradePresentation(Trade trade, TradeCancellationManager manager, CoinFormatter formatter) { - this.trade = trade; + this.trade = (BuyerTrade) trade; this.manager = manager; this.formatter = formatter; } @@ -87,8 +87,8 @@ public void initialize(HBox hBox, public void activate() { - trade.getBuyersCancelTradeStateProperty().addListener(cancelTradeStateListener); - onStateChanged(trade.getBuyersCancelTradeStateProperty().get()); + trade.getCancelTradeStateProperty().addListener(cancelTradeStateListener); + onStateChanged(trade.getCancelTradeStateProperty().get()); trade.disputeStateProperty().addListener(disputeStateListener); onDisputeStateChanged(); @@ -96,7 +96,7 @@ public void activate() { public void deactivate() { if (cancelTradeStateListener != null) { - trade.getBuyersCancelTradeStateProperty().removeListener(cancelTradeStateListener); + trade.getCancelTradeStateProperty().removeListener(cancelTradeStateListener); } if (disputeStateListener != null) { trade.disputeStateProperty().removeListener(disputeStateListener); @@ -135,7 +135,13 @@ private void doRequestCancelTrade() { private void onDisputeStateChanged() { if (trade.isDisputed()) { - disableButton(); + cancelTradeButton.setVisible(false); + cancelTradeButton.setManaged(false); + msgSentStatusLabel.setVisible(false); + msgSentStatusLabel.setManaged(false); + msgSentBusyAnimation.stop(); + msgSentBusyAnimation.setVisible(false); + msgSentBusyAnimation.setManaged(false); } } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java index 78265873270..a54db1f5f7a 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java @@ -40,7 +40,7 @@ */ @Slf4j public class SellersCancelTradePresentation { - private final Trade trade; + private final SellerTrade trade; private final TradeCancellationManager manager; private final CoinFormatter formatter; private TitledGroupBg cancelRequestTitledGroupBg; @@ -56,7 +56,7 @@ public class SellersCancelTradePresentation { SellersCancelTradePresentation(Trade trade, TradeCancellationManager manager, CoinFormatter formatter) { - this.trade = trade; + this.trade = (SellerTrade) trade; this.manager = manager; this.formatter = formatter; } @@ -83,8 +83,8 @@ public void initialize(TitledGroupBg cancelRequestTitledGroupBg, public void activate() { cancelRequestButton.setOnAction(e -> showPopup()); - trade.getSellersCancelTradeStateProperty().addListener(cancelTradeStateListener); - onStateChanged(trade.getSellersCancelTradeStateProperty().get()); + trade.getCancelTradeStateProperty().addListener(cancelTradeStateListener); + onStateChanged(trade.getCancelTradeStateProperty().get()); trade.disputeStateProperty().addListener(disputeStateListener); onDisputeStateChanged(); @@ -94,7 +94,7 @@ public void deactivate() { cancelRequestButton.setOnAction(null); if (cancelTradeStateListener != null) { - trade.getSellersCancelTradeStateProperty().removeListener(cancelTradeStateListener); + trade.getCancelTradeStateProperty().removeListener(cancelTradeStateListener); } if (disputeStateListener != null) { diff --git a/proto/src/main/proto/pb.proto b/proto/src/main/proto/pb.proto index f4ec5a5654f..da589768faa 100644 --- a/proto/src/main/proto/pb.proto +++ b/proto/src/main/proto/pb.proto @@ -1421,8 +1421,7 @@ message Trade { int64 last_refresh_request_date = 36; string counter_currency_extra_data = 37; string asset_tx_proof_result = 38; // name of AssetTxProofResult enum - string sellers_cancel_trade_state = 39; - string buyers_cancel_trade_state = 40; + string cancel_trade_state = 39; } message BuyerAsMakerTrade { From f71b2fbae0b3484a0b5d958e9a9e0ee6bab2f0f1 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 18:09:14 -0500 Subject: [PATCH 35/56] Update comments, remove todo --- .../bisq/core/trade/protocol/BuyersCancelTradeProtocol.java | 2 +- .../core/trade/protocol/SellersCancelTradeProtocol.java | 4 ++-- .../java/bisq/desktop/main/offer/MutableOfferViewModel.java | 2 +- .../steps/buyer/BuyersCancelTradePresentation.java | 6 ++++-- .../steps/seller/SellersCancelTradePresentation.java | 1 - 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/protocol/BuyersCancelTradeProtocol.java b/core/src/main/java/bisq/core/trade/protocol/BuyersCancelTradeProtocol.java index 109cb3dcd4e..384abeceeba 100644 --- a/core/src/main/java/bisq/core/trade/protocol/BuyersCancelTradeProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/BuyersCancelTradeProtocol.java @@ -49,7 +49,7 @@ public class BuyersCancelTradeProtocol extends CancelTradeProtocol { public void onRequestCancelTrade(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { if (trade.isDisputed()) { - log.info("We got onRequestCancelTrade called but the trade have been disputed already. We ignore the call."); + errorMessageHandler.handleErrorMessage("We got onRequestCancelTrade called but the trade have been disputed already."); return; } diff --git a/core/src/main/java/bisq/core/trade/protocol/SellersCancelTradeProtocol.java b/core/src/main/java/bisq/core/trade/protocol/SellersCancelTradeProtocol.java index bc581b48d49..0b40e881452 100644 --- a/core/src/main/java/bisq/core/trade/protocol/SellersCancelTradeProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/SellersCancelTradeProtocol.java @@ -54,7 +54,7 @@ public void onAcceptRequest(ResultHandler resultHandler, ErrorMessageHandler err } if (trade.isDisputed()) { - log.info("We got onAcceptRequest called but the trade have been disputed already. We ignore the call."); + errorMessageHandler.handleErrorMessage("We got onAcceptRequest called but the trade have been disputed already."); return; } @@ -84,7 +84,7 @@ public void onRejectRequest(ResultHandler resultHandler, ErrorMessageHandler err } if (trade.isDisputed()) { - log.info("We got onRejectRequest called but the trade have been disputed already. We ignore the call."); + errorMessageHandler.handleErrorMessage("We got onRejectRequest called but the trade have been disputed already."); return; } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java index 989d063b25e..2d85e0f6a42 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java @@ -231,7 +231,7 @@ public void activate() { if (DevEnv.isDevMode()) { UserThread.runAfter(() -> { amount.set("0.001"); - price.set("0.008"); + price.set("69983"); minAmount.set(amount.get()); onFocusOutPriceAsPercentageTextField(true, false); applyMakerFee(); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyersCancelTradePresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyersCancelTradePresentation.java index 1bec8083296..9616c78929d 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyersCancelTradePresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyersCancelTradePresentation.java @@ -36,9 +36,11 @@ import lombok.extern.slf4j.Slf4j; /** - * Handles the UI aspects of cancelling a trade + * Handles the UI aspects of cancelling a trade. * - * todo: handle dispute + * We do not show the state of the ACK messages but if desired it would need a listener to + * trade.getProcessModel().getPaymentStartedMessageStateProperty() and apply the icons. See BuyerStep3View for an + * implementation. */ @Slf4j public class BuyersCancelTradePresentation { diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java index a54db1f5f7a..a92b1c8ab26 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java @@ -36,7 +36,6 @@ /** * Handles the UI aspects of cancelling a trade * - * todo: handle dispute */ @Slf4j public class SellersCancelTradePresentation { From 9047ab939cafa4eaabec8a7ae25ff1ddf226b57c Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 18:28:34 -0500 Subject: [PATCH 36/56] Remove mailbox msg at failure cases in trade protocol tasks --- .../tasks/ProcessPeerPublishedDelayedPayoutTxMessage.java | 2 ++ .../buyer/BuyerProcessDepositTxAndDelayedPayoutTxMessage.java | 1 + .../tasks/buyer/BuyerProcessPayoutTxPublishedMessage.java | 1 + .../buyer/cancel/ProcessCancelTradeRequestAcceptedMessage.java | 1 + .../buyer/cancel/ProcessCancelTradeRequestRejectedMessage.java | 1 + .../tasks/mediation/ProcessMediatedPayoutSignatureMessage.java | 2 ++ .../mediation/ProcessMediatedPayoutTxPublishedMessage.java | 2 ++ .../SellerProcessCounterCurrencyTransferStartedMessage.java | 2 ++ .../tasks/seller/cancel/ProcessRequestCancelTradeMessage.java | 1 + 9 files changed, 13 insertions(+) diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/ProcessPeerPublishedDelayedPayoutTxMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/ProcessPeerPublishedDelayedPayoutTxMessage.java index d0dc9300530..e4825322093 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/ProcessPeerPublishedDelayedPayoutTxMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/ProcessPeerPublishedDelayedPayoutTxMessage.java @@ -58,6 +58,8 @@ protected void run() { complete(); } catch (Throwable t) { + processModel.removeMailboxMessageAfterProcessing(trade); + failed(t); } } diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerProcessDepositTxAndDelayedPayoutTxMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerProcessDepositTxAndDelayedPayoutTxMessage.java index e95960e043f..31be38faa0b 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerProcessDepositTxAndDelayedPayoutTxMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerProcessDepositTxAndDelayedPayoutTxMessage.java @@ -77,6 +77,7 @@ protected void run() { complete(); } catch (Throwable t) { + processModel.removeMailboxMessageAfterProcessing(trade); failed(t); } } diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerProcessPayoutTxPublishedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerProcessPayoutTxPublishedMessage.java index 245dd40aacb..cec40f9a894 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerProcessPayoutTxPublishedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerProcessPayoutTxPublishedMessage.java @@ -67,6 +67,7 @@ protected void run() { processModel.removeMailboxMessageAfterProcessing(trade); complete(); } catch (Throwable t) { + processModel.removeMailboxMessageAfterProcessing(trade); failed(t); } } diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestAcceptedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestAcceptedMessage.java index 9ff4af591a8..683fe1f2757 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestAcceptedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestAcceptedMessage.java @@ -77,6 +77,7 @@ protected void run() { processModel.removeMailboxMessageAfterProcessing(trade); complete(); } catch (Throwable t) { + processModel.removeMailboxMessageAfterProcessing(trade); failed(t); } } diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestRejectedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestRejectedMessage.java index 2e7011484e6..4512c0f7a92 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestRejectedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/ProcessCancelTradeRequestRejectedMessage.java @@ -55,6 +55,7 @@ protected void run() { processModel.removeMailboxMessageAfterProcessing(trade); complete(); } catch (Throwable t) { + processModel.removeMailboxMessageAfterProcessing(trade); failed(t); } } diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/ProcessMediatedPayoutSignatureMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/ProcessMediatedPayoutSignatureMessage.java index 9ae9aedc340..e201da7c5fe 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/ProcessMediatedPayoutSignatureMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/ProcessMediatedPayoutSignatureMessage.java @@ -55,6 +55,8 @@ protected void run() { complete(); } catch (Throwable t) { + processModel.removeMailboxMessageAfterProcessing(trade); + failed(t); } } diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/ProcessMediatedPayoutTxPublishedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/ProcessMediatedPayoutTxPublishedMessage.java index 247409c2ef3..723e1a44745 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/ProcessMediatedPayoutTxPublishedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/ProcessMediatedPayoutTxPublishedMessage.java @@ -78,6 +78,8 @@ protected void run() { processModel.removeMailboxMessageAfterProcessing(trade); complete(); } catch (Throwable t) { + processModel.removeMailboxMessageAfterProcessing(trade); + failed(t); } } diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerProcessCounterCurrencyTransferStartedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerProcessCounterCurrencyTransferStartedMessage.java index ee996ffd9c1..e09bf0158f1 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerProcessCounterCurrencyTransferStartedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerProcessCounterCurrencyTransferStartedMessage.java @@ -66,6 +66,8 @@ protected void run() { complete(); } catch (Throwable t) { + processModel.removeMailboxMessageAfterProcessing(trade); + failed(t); } } diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/ProcessRequestCancelTradeMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/ProcessRequestCancelTradeMessage.java index b31ddaa0aa9..22e0b205256 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/ProcessRequestCancelTradeMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/ProcessRequestCancelTradeMessage.java @@ -59,6 +59,7 @@ protected void run() { complete(); } catch (Throwable t) { + processModel.removeMailboxMessageAfterProcessing(trade); failed(t); } } From 82fd068fbd0d62aaa64f0ac7b63b4c368f2873cf Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 19:27:27 -0500 Subject: [PATCH 37/56] Remove commented out code. Codacy still complains about empty TradeCancellationManager constructor, but that is needed as it used the @Inject annotation. This rule should be removed. `Avoid unnecessary constructors - the compiler will generate these for you` Found a have how to make Coday ignore lines even they do not support that directly. Will try it out... https://stackoverflow.com/questions/61760176/how-to-specify-code-lines-to-exclude-them-from-codacy-analysis // eslint-disable-line no-eval --- core/src/main/java/bisq/core/trade/Trade.java | 61 ------------------- .../SellersCancelTradePresentation.java | 3 + 2 files changed, 3 insertions(+), 61 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/Trade.java b/core/src/main/java/bisq/core/trade/Trade.java index 32c2c2cc2ce..110193a276d 100644 --- a/core/src/main/java/bisq/core/trade/Trade.java +++ b/core/src/main/java/bisq/core/trade/Trade.java @@ -448,17 +448,6 @@ public static protobuf.Trade.TradePeriodState toProtoMessage(Trade.TradePeriodSt @Getter transient final private IntegerProperty assetTxProofResultUpdateProperty = new SimpleIntegerProperty(); - /* @Getter - // Added at v1.3.9 - public SellerTrade.CancelTradeState sellersCancelTradeState; - @Getter - transient final private ObjectProperty sellersCancelTradeStateProperty = new SimpleObjectProperty<>(); -*/ - /*@Getter - public BuyerTrade.CancelTradeState buyersCancelTradeState; - @Getter - transient final private ObjectProperty buyersCancelTradeStateProperty = new SimpleObjectProperty<>(); -*/ /////////////////////////////////////////////////////////////////////////////////////////// // Constructor, initialization @@ -528,56 +517,6 @@ protected Trade(Offer offer, // PROTO BUFFER /////////////////////////////////////////////////////////////////////////////////////////// - /* @Override - public Message toProtoMessage() { - protobuf.Trade.Builder builder = getBuilder() - .setOffer(checkNotNull(offer).toProtoMessage()) - .setIsCurrencyForTakerFeeBtc(isCurrencyForTakerFeeBtc) - .setTxFeeAsLong(txFeeAsLong) - .setTakerFeeAsLong(takerFeeAsLong) - .setTakeOfferDate(takeOfferDate) - .setProcessModel(processModel.toProtoMessage()) - .setTradeAmountAsLong(tradeAmountAsLong) - .setTradePrice(tradePrice) - .setState(Trade.State.toProtoMessage(state)) - .setDisputeState(Trade.DisputeState.toProtoMessage(disputeState)) - .setTradePeriodState(Trade.TradePeriodState.toProtoMessage(tradePeriodState)) - .addAllChatMessage(chatMessages.stream() - .map(msg -> msg.toProtoNetworkEnvelope().getChatMessage()) - .collect(Collectors.toList())) - .setLockTime(lockTime) - .setLastRefreshRequestDate(lastRefreshRequestDate); - - Optional.ofNullable(takerFeeTxId).ifPresent(builder::setTakerFeeTxId); - Optional.ofNullable(depositTxId).ifPresent(builder::setDepositTxId); - Optional.ofNullable(payoutTxId).ifPresent(builder::setPayoutTxId); - Optional.ofNullable(tradingPeerNodeAddress).ifPresent(e -> builder.setTradingPeerNodeAddress(tradingPeerNodeAddress.toProtoMessage())); - Optional.ofNullable(contract).ifPresent(e -> builder.setContract(contract.toProtoMessage())); - Optional.ofNullable(contractAsJson).ifPresent(builder::setContractAsJson); - Optional.ofNullable(contractHash).ifPresent(e -> builder.setContractHash(ByteString.copyFrom(contractHash))); - Optional.ofNullable(takerContractSignature).ifPresent(builder::setTakerContractSignature); - Optional.ofNullable(makerContractSignature).ifPresent(builder::setMakerContractSignature); - Optional.ofNullable(arbitratorNodeAddress).ifPresent(e -> builder.setArbitratorNodeAddress(arbitratorNodeAddress.toProtoMessage())); - Optional.ofNullable(mediatorNodeAddress).ifPresent(e -> builder.setMediatorNodeAddress(mediatorNodeAddress.toProtoMessage())); - Optional.ofNullable(refundAgentNodeAddress).ifPresent(e -> builder.setRefundAgentNodeAddress(refundAgentNodeAddress.toProtoMessage())); - Optional.ofNullable(arbitratorBtcPubKey).ifPresent(e -> builder.setArbitratorBtcPubKey(ByteString.copyFrom(arbitratorBtcPubKey))); - Optional.ofNullable(takerPaymentAccountId).ifPresent(builder::setTakerPaymentAccountId); - Optional.ofNullable(errorMessage).ifPresent(builder::setErrorMessage); - Optional.ofNullable(arbitratorPubKeyRing).ifPresent(e -> builder.setArbitratorPubKeyRing(arbitratorPubKeyRing.toProtoMessage())); - Optional.ofNullable(mediatorPubKeyRing).ifPresent(e -> builder.setMediatorPubKeyRing(mediatorPubKeyRing.toProtoMessage())); - Optional.ofNullable(refundAgentPubKeyRing).ifPresent(e -> builder.setRefundAgentPubKeyRing(refundAgentPubKeyRing.toProtoMessage())); - Optional.ofNullable(counterCurrencyTxId).ifPresent(e -> builder.setCounterCurrencyTxId(counterCurrencyTxId)); - Optional.ofNullable(mediationResultState).ifPresent(e -> builder.setMediationResultState(MediationResultState.toProtoMessage(mediationResultState))); - Optional.ofNullable(refundResultState).ifPresent(e -> builder.setRefundResultState(RefundResultState.toProtoMessage(refundResultState))); - Optional.ofNullable(delayedPayoutTxBytes).ifPresent(e -> builder.setDelayedPayoutTxBytes(ByteString.copyFrom(delayedPayoutTxBytes))); - Optional.ofNullable(counterCurrencyExtraData).ifPresent(e -> builder.setCounterCurrencyExtraData(counterCurrencyExtraData)); - Optional.ofNullable(assetTxProofResult).ifPresent(e -> builder.setAssetTxProofResult(assetTxProofResult.name())); - Optional.ofNullable(sellersCancelTradeState).ifPresent(e -> builder.setCancelTradeState(sellersCancelTradeState.name())); - Optional.ofNullable(buyersCancelTradeState).ifPresent(e -> builder.setCancelTradeState(buyersCancelTradeState.name())); - - return builder.build(); - }*/ - protected protobuf.Trade.Builder getBuilder() { protobuf.Trade.Builder builder = protobuf.Trade.newBuilder() .setOffer(checkNotNull(offer).toProtoMessage()) diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java index a92b1c8ab26..e88b937e694 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java @@ -178,6 +178,9 @@ private void onStateChanged(SellerTrade.CancelTradeState state) { case REQUEST_REJECTED_MSG_SEND_FAILED: cancelRequestInfoLabel.setText(Res.get("portfolio.pending.seller.rejectResponse.failed")); break; + default: + log.error("Unexpected state {}", state); + break; } } From 0f7f3d2d0e29d2ce1dcc57037476909f6ac87cb3 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 19:28:23 -0500 Subject: [PATCH 38/56] Try to get Codacy to ignore lines --- .../main/java/bisq/core/trade/TradeCancellationManager.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/TradeCancellationManager.java b/core/src/main/java/bisq/core/trade/TradeCancellationManager.java index 40cfd83b3f3..bc276abf965 100644 --- a/core/src/main/java/bisq/core/trade/TradeCancellationManager.java +++ b/core/src/main/java/bisq/core/trade/TradeCancellationManager.java @@ -44,9 +44,9 @@ public final class TradeCancellationManager { // Constructor /////////////////////////////////////////////////////////////////////////////////////////// - @Inject - public TradeCancellationManager() { - } + @Inject // eslint-disable-line no-eval + public TradeCancellationManager() { // eslint-disable-line no-eval + } // eslint-disable-line no-eval /////////////////////////////////////////////////////////////////////////////////////////// From 0e9540dd08274db27e1d4a752b0593fcbb511ce0 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 19:50:23 -0500 Subject: [PATCH 39/56] Remove constructor as Codacy does not like empty constructors. It removes the @Inject annotation with it which I think is not great as it makes it more obscure how that class gets created. But it works as it is used as param in another injected class. The "trick" with ``// eslint-disable-line no-eval` did not work. --- .../java/bisq/core/trade/TradeCancellationManager.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/TradeCancellationManager.java b/core/src/main/java/bisq/core/trade/TradeCancellationManager.java index bc276abf965..aacf92212a0 100644 --- a/core/src/main/java/bisq/core/trade/TradeCancellationManager.java +++ b/core/src/main/java/bisq/core/trade/TradeCancellationManager.java @@ -28,7 +28,6 @@ import org.bitcoinj.core.Coin; -import com.google.inject.Inject; import com.google.inject.Singleton; import lombok.extern.slf4j.Slf4j; @@ -40,15 +39,6 @@ @Singleton public final class TradeCancellationManager { - /////////////////////////////////////////////////////////////////////////////////////////// - // Constructor - /////////////////////////////////////////////////////////////////////////////////////////// - - @Inject // eslint-disable-line no-eval - public TradeCancellationManager() { // eslint-disable-line no-eval - } // eslint-disable-line no-eval - - /////////////////////////////////////////////////////////////////////////////////////////// // Buyers User intent /////////////////////////////////////////////////////////////////////////////////////////// From 6b5e08d4a378df58b7189b8af702d0c01cd29aa0 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 20:19:23 -0500 Subject: [PATCH 40/56] Moved witness signing and msg sending to trade protocol task --- .../witness/AccountAgeWitnessService.java | 44 --------- .../java/bisq/core/trade/TradeManager.java | 3 - .../messages/TraderSignedWitnessMessage.java | 7 +- .../trade/protocol/SellerAsMakerProtocol.java | 4 +- .../trade/protocol/SellerAsTakerProtocol.java | 4 +- ...MaybeSignWitnessAndSendWitnessMessage.java | 99 +++++++++++++++++++ 6 files changed, 109 insertions(+), 52 deletions(-) create mode 100644 core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerMaybeSignWitnessAndSendWitnessMessage.java diff --git a/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java b/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java index c1a55e2bb0b..3ceb8c0105d 100644 --- a/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java +++ b/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java @@ -35,14 +35,11 @@ import bisq.core.support.dispute.arbitration.TraderDataItem; import bisq.core.trade.Contract; import bisq.core.trade.Trade; -import bisq.core.trade.messages.TraderSignedWitnessMessage; import bisq.core.trade.protocol.TradingPeer; import bisq.core.user.User; import bisq.network.p2p.BootstrapListener; -import bisq.network.p2p.NodeAddress; import bisq.network.p2p.P2PService; -import bisq.network.p2p.SendMailboxMessageListener; import bisq.network.p2p.storage.P2PDataStorage; import bisq.network.p2p.storage.persistence.AppendOnlyDataStoreService; @@ -76,7 +73,6 @@ import java.util.Optional; import java.util.Random; import java.util.Set; -import java.util.UUID; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -868,44 +864,4 @@ public boolean isSignWitnessTrade(Trade trade) { !peerHasSignedWitness(trade) && tradeAmountIsSufficient(trade.getTradeAmount()); } - - public void maybeSignWitness(Trade trade) { - if (isSignWitnessTrade(trade)) { - var signedWitnessOptional = traderSignPeersAccountAgeWitness(trade); - signedWitnessOptional.ifPresent(signedWitness -> sendSignedWitnessToPeer(signedWitness, trade)); - } - } - - private void sendSignedWitnessToPeer(SignedWitness signedWitness, Trade trade) { - if (trade == null) return; - - NodeAddress tradingPeerNodeAddress = trade.getTradingPeerNodeAddress(); - var traderSignedWitnessMessage = new TraderSignedWitnessMessage(UUID.randomUUID().toString(), trade.getId(), - tradingPeerNodeAddress, signedWitness); - - p2PService.sendEncryptedMailboxMessage( - tradingPeerNodeAddress, - trade.getProcessModel().getTradingPeer().getPubKeyRing(), - traderSignedWitnessMessage, - new SendMailboxMessageListener() { - @Override - public void onArrived() { - log.info("SendMailboxMessageListener onArrived tradeId={} at peer {} SignedWitness {}", - trade.getId(), tradingPeerNodeAddress, signedWitness); - } - - @Override - public void onStoredInMailbox() { - log.info("SendMailboxMessageListener onStoredInMailbox tradeId={} at peer {} SignedWitness {}", - trade.getId(), tradingPeerNodeAddress, signedWitness); - } - - @Override - public void onFault(String errorMessage) { - log.error("SendMailboxMessageListener onFault tradeId={} at peer {} SignedWitness {}", - trade.getId(), tradingPeerNodeAddress, signedWitness); - } - } - ); - } } diff --git a/core/src/main/java/bisq/core/trade/TradeManager.java b/core/src/main/java/bisq/core/trade/TradeManager.java index 2c2a872cbbd..2f78008eb07 100644 --- a/core/src/main/java/bisq/core/trade/TradeManager.java +++ b/core/src/main/java/bisq/core/trade/TradeManager.java @@ -350,9 +350,6 @@ public void onUserConfirmedFiatPaymentReceived(SellerTrade sellerTrade, ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { sellerTrade.onFiatPaymentReceived(resultHandler, errorMessageHandler); - - //TODO move to trade protocol task - accountAgeWitnessService.maybeSignWitness(sellerTrade); } private void initPendingTrade(Trade trade) { diff --git a/core/src/main/java/bisq/core/trade/messages/TraderSignedWitnessMessage.java b/core/src/main/java/bisq/core/trade/messages/TraderSignedWitnessMessage.java index c1172f08741..63108cdfda0 100644 --- a/core/src/main/java/bisq/core/trade/messages/TraderSignedWitnessMessage.java +++ b/core/src/main/java/bisq/core/trade/messages/TraderSignedWitnessMessage.java @@ -24,6 +24,8 @@ import bisq.common.app.Version; +import java.util.UUID; + import lombok.EqualsAndHashCode; import lombok.Value; @@ -33,12 +35,11 @@ public class TraderSignedWitnessMessage extends TradeMessage implements MailboxM private final NodeAddress senderNodeAddress; private final SignedWitness signedWitness; - public TraderSignedWitnessMessage(String uid, - String tradeId, + public TraderSignedWitnessMessage(String tradeId, NodeAddress senderNodeAddress, SignedWitness signedWitness) { this(Version.getP2PMessageVersion(), - uid, + UUID.randomUUID().toString(), tradeId, senderNodeAddress, signedWitness); diff --git a/core/src/main/java/bisq/core/trade/protocol/SellerAsMakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/SellerAsMakerProtocol.java index 1859adce905..516313bcba9 100644 --- a/core/src/main/java/bisq/core/trade/protocol/SellerAsMakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/SellerAsMakerProtocol.java @@ -36,6 +36,7 @@ import bisq.core.trade.protocol.tasks.seller.SellerBroadcastPayoutTx; import bisq.core.trade.protocol.tasks.seller.SellerCreatesDelayedPayoutTx; import bisq.core.trade.protocol.tasks.seller.SellerFinalizesDelayedPayoutTx; +import bisq.core.trade.protocol.tasks.seller.SellerMaybeSignWitnessAndSendWitnessMessage; import bisq.core.trade.protocol.tasks.seller.SellerProcessCounterCurrencyTransferStartedMessage; import bisq.core.trade.protocol.tasks.seller.SellerProcessDelayedPayoutTxSignatureResponse; import bisq.core.trade.protocol.tasks.seller.SellerPublishesDepositTx; @@ -232,7 +233,8 @@ public void onFiatPaymentReceived(ResultHandler resultHandler, ErrorMessageHandl MakerVerifyTakerFeePayment.class, SellerSignAndFinalizePayoutTx.class, SellerBroadcastPayoutTx.class, - SellerSendPayoutTxPublishedMessage.class + SellerSendPayoutTxPublishedMessage.class, + SellerMaybeSignWitnessAndSendWitnessMessage.class ); taskRunner.run(); } else { diff --git a/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java index 965486ef8d5..1938ad0237b 100644 --- a/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java @@ -31,6 +31,7 @@ import bisq.core.trade.protocol.tasks.seller.SellerBroadcastPayoutTx; import bisq.core.trade.protocol.tasks.seller.SellerCreatesDelayedPayoutTx; import bisq.core.trade.protocol.tasks.seller.SellerFinalizesDelayedPayoutTx; +import bisq.core.trade.protocol.tasks.seller.SellerMaybeSignWitnessAndSendWitnessMessage; import bisq.core.trade.protocol.tasks.seller.SellerProcessCounterCurrencyTransferStartedMessage; import bisq.core.trade.protocol.tasks.seller.SellerProcessDelayedPayoutTxSignatureResponse; import bisq.core.trade.protocol.tasks.seller.SellerPublishesDepositTx; @@ -223,7 +224,8 @@ public void onFiatPaymentReceived(ResultHandler resultHandler, ErrorMessageHandl TakerVerifyMakerFeePayment.class, SellerSignAndFinalizePayoutTx.class, SellerBroadcastPayoutTx.class, - SellerSendPayoutTxPublishedMessage.class + SellerSendPayoutTxPublishedMessage.class, + SellerMaybeSignWitnessAndSendWitnessMessage.class ); taskRunner.run(); } else { diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerMaybeSignWitnessAndSendWitnessMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerMaybeSignWitnessAndSendWitnessMessage.java new file mode 100644 index 00000000000..0744cf7b32f --- /dev/null +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerMaybeSignWitnessAndSendWitnessMessage.java @@ -0,0 +1,99 @@ +/* + * This file is part of Bisq. + * + * Bisq 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. + * + * Bisq 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 Bisq. If not, see . + */ + +package bisq.core.trade.protocol.tasks.seller; + +import bisq.core.account.sign.SignedWitness; +import bisq.core.account.witness.AccountAgeWitnessService; +import bisq.core.trade.Trade; +import bisq.core.trade.messages.TradeMessage; +import bisq.core.trade.messages.TraderSignedWitnessMessage; +import bisq.core.trade.protocol.tasks.SendMailboxMessageTask; + +import bisq.common.taskrunner.TaskRunner; + +import java.util.Optional; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class SellerMaybeSignWitnessAndSendWitnessMessage extends SendMailboxMessageTask { + private SignedWitness signedWitness; + + @SuppressWarnings({"unused"}) + public SellerMaybeSignWitnessAndSendWitnessMessage(TaskRunner taskHandler, Trade trade) { + super(taskHandler, trade); + } + + @Override + protected TradeMessage getMessage(String id) { + return new TraderSignedWitnessMessage(trade.getId(), processModel.getMyNodeAddress(), signedWitness); + } + + @Override + protected void setStateSent() { + log.info("Sent TraderSignedWitnessMessage: tradeId={} at peer {} SignedWitness {}", + trade.getId(), trade.getTradingPeerNodeAddress(), signedWitness); + } + + @Override + protected void setStateArrived() { + log.info("TraderSignedWitnessMessage arrived: tradeId={} at peer {} SignedWitness {}", + trade.getId(), trade.getTradingPeerNodeAddress(), signedWitness); + } + + @Override + protected void setStateStoredInMailbox() { + log.info("TraderSignedWitnessMessage storedInMailbox: tradeId={} at peer {} SignedWitness {}", + trade.getId(), trade.getTradingPeerNodeAddress(), signedWitness); + } + + @Override + protected void setStateFault() { + log.error("TraderSignedWitnessMessage failed: tradeId={} at peer {} SignedWitness {}", + trade.getId(), trade.getTradingPeerNodeAddress(), signedWitness); + } + + @Override + protected void run() { + try { + runInterceptHook(); + + AccountAgeWitnessService accountAgeWitnessService = processModel.getAccountAgeWitnessService(); + if (!accountAgeWitnessService.isSignWitnessTrade(trade)) { + log.warn("Is not a witness trade"); + complete(); + return; + } + + Optional signedWitnessOptional = accountAgeWitnessService.traderSignPeersAccountAgeWitness(trade); + if (!signedWitnessOptional.isPresent()) { + log.warn("signedWitnessOptional is not present"); + // TODO not sure if that is a failure case or a valid case, but this follows existing impl logic + complete(); + return; + } + + signedWitness = signedWitnessOptional.get(); + + // Message sending is handled in base class. + super.run(); + } catch (Throwable t) { + failed(t); + } + } +} From e3c6aa2c97e036153aa848858afef9b698f22677 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 21:02:11 -0500 Subject: [PATCH 41/56] Refactoring: Rename param to avoid confusion with allowBroadcast and to be more consistent with other calling methods using the same param name --- .../main/java/bisq/network/p2p/storage/P2PDataStorage.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/p2p/src/main/java/bisq/network/p2p/storage/P2PDataStorage.java b/p2p/src/main/java/bisq/network/p2p/storage/P2PDataStorage.java index 2283547a1f7..fea9faba6cf 100644 --- a/p2p/src/main/java/bisq/network/p2p/storage/P2PDataStorage.java +++ b/p2p/src/main/java/bisq/network/p2p/storage/P2PDataStorage.java @@ -479,16 +479,16 @@ public void onError(Throwable throwable) { * be broadcast to the P2P network. * @param payload PersistableNetworkPayload to add to the network * @param sender local NodeAddress, if available - * @param allowReBroadcast true if the PersistableNetworkPayload should be rebroadcast even if it + * @param reBroadcast true if the PersistableNetworkPayload should be rebroadcast even if it * already exists locally * @return true if the PersistableNetworkPayload passes all validation and exists in the P2PDataStore * on completion */ public boolean addPersistableNetworkPayload(PersistableNetworkPayload payload, @Nullable NodeAddress sender, - boolean allowReBroadcast) { + boolean reBroadcast) { return addPersistableNetworkPayload( - payload, sender, true, allowReBroadcast, false); + payload, sender, true, reBroadcast, false); } private boolean addPersistableNetworkPayload(PersistableNetworkPayload payload, From 286402fc1165ee21d3fb4e89b626c1babaa8057d Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 21:02:47 -0500 Subject: [PATCH 42/56] Add comments --- .../core/trade/protocol/SellerAsMakerProtocol.java | 3 +++ .../core/trade/protocol/SellerAsTakerProtocol.java | 3 +++ .../java/bisq/core/trade/protocol/TradeProtocol.java | 10 +++++++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/protocol/SellerAsMakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/SellerAsMakerProtocol.java index 516313bcba9..ec26d8bb569 100644 --- a/core/src/main/java/bisq/core/trade/protocol/SellerAsMakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/SellerAsMakerProtocol.java @@ -227,6 +227,9 @@ public void onFiatPaymentReceived(ResultHandler resultHandler, ErrorMessageHandl handleTaskRunnerFault(errorMessage); }); + // SellerSendPayoutTxPublishedMessage and SellerMaybeSignWitnessAndSendWitnessMessage are sending both a + // msg which should have been consolidated in 1 message to avoid that the peer has to process 2 messages + // arriving around the same time. This breaks the concept of a strict sequential task execution. taskRunner.addTasks( ApplyFilter.class, MakerVerifyTakerAccount.class, diff --git a/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java index 1938ad0237b..d4608a767f0 100644 --- a/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java @@ -218,6 +218,9 @@ public void onFiatPaymentReceived(ResultHandler resultHandler, ErrorMessageHandl handleTaskRunnerFault(errorMessage); }); + // SellerSendPayoutTxPublishedMessage and SellerMaybeSignWitnessAndSendWitnessMessage are sending both a + // msg which should have been consolidated in 1 message to avoid that the peer has to process 2 messages + // arriving around the same time. This breaks the concept of a strict sequential task execution. taskRunner.addTasks( ApplyFilter.class, TakerVerifyMakerAccount.class, diff --git a/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java b/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java index 94fd76dccd6..5a977074a71 100644 --- a/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java @@ -240,9 +240,13 @@ private void handle(PeerPublishedDelayedPayoutTxMessage tradeMessage, NodeAddres // Peer has sent a SignedWitness /////////////////////////////////////////////////////////////////////////////////////////// - // TODO this should not be in the trade protocol. The sending is done in the domain, so should be the handling of - // the msg. If it is part of the normal trade protocol we should add the sending and handling to the steps where - // it happen. + // It would be unsafe to use the TradeTaskRunner framework here as we expect the PeerPublishedDelayedPayoutTxMessage + // around the same time. The ProcessPeerPublishedDelayedPayoutTxMessage task is synchronous so there would not be + // an issue if we start another task runner and set the trade message to the process model, but if the code in + // ProcessPeerPublishedDelayedPayoutTxMessage would become async in future it would introduce inconsistent model + // data. The TradeTaskRunner framework does not support parallel/concurrent execution. The 2 messages should have been + // packed into one and the problem would have been avoided. Now it seems to be the best approach to leave the + // protocol framework and process the message in the AccountAgeWitness domain. private void handle(TraderSignedWitnessMessage tradeMessage) { // Publish signed witness, if it is valid and ours processModel.getAccountAgeWitnessService().publishOwnSignedWitness(tradeMessage.getSignedWitness()); From f819a0d764430256803c0b8988b3438775dac46d Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 21:03:30 -0500 Subject: [PATCH 43/56] Let signer broadcast signedWitness as well. Change reBroadcast flag to true. --- .../java/bisq/core/account/sign/SignedWitnessService.java | 5 ++++- .../SellerMaybeSignWitnessAndSendWitnessMessage.java | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/bisq/core/account/sign/SignedWitnessService.java b/core/src/main/java/bisq/core/account/sign/SignedWitnessService.java index e27bf2493cd..85f00179db9 100644 --- a/core/src/main/java/bisq/core/account/sign/SignedWitnessService.java +++ b/core/src/main/java/bisq/core/account/sign/SignedWitnessService.java @@ -494,7 +494,10 @@ void addToMap(SignedWitness signedWitness) { private void publishSignedWitness(SignedWitness signedWitness) { if (!signedWitnessMap.containsKey(signedWitness.getHashAsByteArray())) { log.info("broadcast signed witness {}", signedWitness.toString()); - p2PService.addPersistableNetworkPayload(signedWitness, false); + // We set reBroadcast to true. The signer has broadcast the signedWitness as + // well, so it might be that we have received the data already, but we prefer to re-broadcast + // to achieve better resilience. + p2PService.addPersistableNetworkPayload(signedWitness, true); addToMap(signedWitness); } } diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerMaybeSignWitnessAndSendWitnessMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerMaybeSignWitnessAndSendWitnessMessage.java index 0744cf7b32f..0d4071b7ed5 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerMaybeSignWitnessAndSendWitnessMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerMaybeSignWitnessAndSendWitnessMessage.java @@ -90,7 +90,13 @@ protected void run() { signedWitness = signedWitnessOptional.get(); - // Message sending is handled in base class. + // The signer broadcasts as well the signedWitness. In case the receiver will not get the message we have + // better resilience that the data is in the network. We set reBroadcast to true but do not expect that the + // signedWitness exists already as we just created it. + // TODO check with @sqrrm + processModel.getP2PService().addPersistableNetworkPayload(signedWitness, true); + + // Message sending is handled in base class (SendMailboxMessageTask). super.run(); } catch (Throwable t) { failed(t); From 396c6f4a0906c73aeba7a7f79069b314673f13cf Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 21:27:18 -0500 Subject: [PATCH 44/56] Use a deterministic id instead of uid --- .../BuyerSendCounterCurrencyTransferStartedMessage.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerSendCounterCurrencyTransferStartedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerSendCounterCurrencyTransferStartedMessage.java index 40cd15750a8..940ac3d7929 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerSendCounterCurrencyTransferStartedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerSendCounterCurrencyTransferStartedMessage.java @@ -28,8 +28,6 @@ import bisq.common.taskrunner.TaskRunner; -import java.util.UUID; - import lombok.extern.slf4j.Slf4j; @Slf4j @@ -48,6 +46,11 @@ protected void run() { final String id = processModel.getOfferId(); AddressEntry payoutAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.TRADE_PAYOUT); + // We do not use a real unique ID here as we want to be able to re-send the exact same message in case the + // peer does not respond with an ACK msg in a certain time interval. To avoid that we get dangling mailbox + // messages where only the one which gets processed by the peer would be removed we use the same uid. All + // other data stays the same when we re-send the message at any time later. + String deterministicId = trade.getId() + processModel.getMyNodeAddress().getFullAddress(); final CounterCurrencyTransferStartedMessage message = new CounterCurrencyTransferStartedMessage( id, payoutAddressEntry.getAddressString(), @@ -55,7 +58,7 @@ protected void run() { processModel.getPayoutTxSignature(), trade.getCounterCurrencyTxId(), trade.getCounterCurrencyExtraData(), - UUID.randomUUID().toString() + deterministicId ); NodeAddress peersNodeAddress = trade.getTradingPeerNodeAddress(); log.info("Send {} to peer {}. tradeId={}, uid={}", From 93f24a471c0225f89c674f0f59814ffadfdd3fb1 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 21:29:59 -0500 Subject: [PATCH 45/56] Refactor: Use SendMailboxMessageTask to avoid duplicated code --- ...CounterCurrencyTransferStartedMessage.java | 105 ++++++++---------- 1 file changed, 47 insertions(+), 58 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerSendCounterCurrencyTransferStartedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerSendCounterCurrencyTransferStartedMessage.java index 940ac3d7929..1d6b6bdb682 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerSendCounterCurrencyTransferStartedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerSendCounterCurrencyTransferStartedMessage.java @@ -21,80 +21,69 @@ import bisq.core.btc.wallet.BtcWalletService; import bisq.core.trade.Trade; import bisq.core.trade.messages.CounterCurrencyTransferStartedMessage; -import bisq.core.trade.protocol.tasks.TradeTask; - -import bisq.network.p2p.NodeAddress; -import bisq.network.p2p.SendMailboxMessageListener; +import bisq.core.trade.messages.TradeMessage; +import bisq.core.trade.protocol.tasks.SendMailboxMessageTask; import bisq.common.taskrunner.TaskRunner; import lombok.extern.slf4j.Slf4j; @Slf4j -public class BuyerSendCounterCurrencyTransferStartedMessage extends TradeTask { +public class BuyerSendCounterCurrencyTransferStartedMessage extends SendMailboxMessageTask { @SuppressWarnings({"unused"}) public BuyerSendCounterCurrencyTransferStartedMessage(TaskRunner taskHandler, Trade trade) { super(taskHandler, trade); } + @Override + protected TradeMessage getMessage(String tradeId) { + BtcWalletService walletService = processModel.getBtcWalletService(); + String id = processModel.getOfferId(); + AddressEntry payoutAddressEntry = walletService.getOrCreateAddressEntry(id, + AddressEntry.Context.TRADE_PAYOUT); + // We do not use a real unique ID here as we want to be able to re-send the exact same message in case the + // peer does not respond with an ACK msg in a certain time interval. To avoid that we get dangling mailbox + // messages where only the one which gets processed by the peer would be removed we use the same uid. All + // other data stays the same when we re-send the message at any time later. + String deterministicId = tradeId + processModel.getMyNodeAddress().getFullAddress(); + + return new CounterCurrencyTransferStartedMessage( + id, + payoutAddressEntry.getAddressString(), + processModel.getMyNodeAddress(), + processModel.getPayoutTxSignature(), + trade.getCounterCurrencyTxId(), + trade.getCounterCurrencyExtraData(), + deterministicId + ); + } + + @Override + protected void setStateSent() { + trade.setState(Trade.State.BUYER_SENT_FIAT_PAYMENT_INITIATED_MSG); + } + + @Override + protected void setStateArrived() { + trade.setState(Trade.State.BUYER_SAW_ARRIVED_FIAT_PAYMENT_INITIATED_MSG); + } + + @Override + protected void setStateStoredInMailbox() { + trade.setState(Trade.State.BUYER_STORED_IN_MAILBOX_FIAT_PAYMENT_INITIATED_MSG); + } + + @Override + protected void setStateFault() { + trade.setState(Trade.State.BUYER_SEND_FAILED_FIAT_PAYMENT_INITIATED_MSG); + } + @Override protected void run() { try { runInterceptHook(); - BtcWalletService walletService = processModel.getBtcWalletService(); - final String id = processModel.getOfferId(); - AddressEntry payoutAddressEntry = walletService.getOrCreateAddressEntry(id, - AddressEntry.Context.TRADE_PAYOUT); - // We do not use a real unique ID here as we want to be able to re-send the exact same message in case the - // peer does not respond with an ACK msg in a certain time interval. To avoid that we get dangling mailbox - // messages where only the one which gets processed by the peer would be removed we use the same uid. All - // other data stays the same when we re-send the message at any time later. - String deterministicId = trade.getId() + processModel.getMyNodeAddress().getFullAddress(); - final CounterCurrencyTransferStartedMessage message = new CounterCurrencyTransferStartedMessage( - id, - payoutAddressEntry.getAddressString(), - processModel.getMyNodeAddress(), - processModel.getPayoutTxSignature(), - trade.getCounterCurrencyTxId(), - trade.getCounterCurrencyExtraData(), - deterministicId - ); - NodeAddress peersNodeAddress = trade.getTradingPeerNodeAddress(); - log.info("Send {} to peer {}. tradeId={}, uid={}", - message.getClass().getSimpleName(), peersNodeAddress, message.getTradeId(), message.getUid()); - trade.setState(Trade.State.BUYER_SENT_FIAT_PAYMENT_INITIATED_MSG); - processModel.getP2PService().sendEncryptedMailboxMessage( - peersNodeAddress, - processModel.getTradingPeer().getPubKeyRing(), - message, - new SendMailboxMessageListener() { - @Override - public void onArrived() { - log.info("{} arrived at peer {}. tradeId={}, uid={}", - message.getClass().getSimpleName(), peersNodeAddress, message.getTradeId(), message.getUid()); - trade.setState(Trade.State.BUYER_SAW_ARRIVED_FIAT_PAYMENT_INITIATED_MSG); - complete(); - } - - @Override - public void onStoredInMailbox() { - log.info("{} stored in mailbox for peer {}. tradeId={}, uid={}", - message.getClass().getSimpleName(), peersNodeAddress, message.getTradeId(), message.getUid()); - trade.setState(Trade.State.BUYER_STORED_IN_MAILBOX_FIAT_PAYMENT_INITIATED_MSG); - complete(); - } - - @Override - public void onFault(String errorMessage) { - log.error("{} failed: Peer {}. tradeId={}, uid={}, errorMessage={}", - message.getClass().getSimpleName(), peersNodeAddress, message.getTradeId(), message.getUid(), errorMessage); - trade.setState(Trade.State.BUYER_SEND_FAILED_FIAT_PAYMENT_INITIATED_MSG); - appendToErrorMessage("Sending message failed: message=" + message + "\nerrorMessage=" + errorMessage); - failed(errorMessage); - } - } - ); + super.run(); } catch (Throwable t) { failed(t); } From ab2e54f1f68270115f0877ff486745346c8d14f7 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 21:59:20 -0500 Subject: [PATCH 46/56] Resend payment started message as long we dont get an ACK --- ...CounterCurrencyTransferStartedMessage.java | 90 ++++++++++++++----- 1 file changed, 69 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerSendCounterCurrencyTransferStartedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerSendCounterCurrencyTransferStartedMessage.java index 1d6b6bdb682..a96992ee57c 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerSendCounterCurrencyTransferStartedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerSendCounterCurrencyTransferStartedMessage.java @@ -18,44 +18,60 @@ package bisq.core.trade.protocol.tasks.buyer; import bisq.core.btc.model.AddressEntry; -import bisq.core.btc.wallet.BtcWalletService; +import bisq.core.network.MessageState; +import bisq.core.payment.payload.PaymentMethod; import bisq.core.trade.Trade; import bisq.core.trade.messages.CounterCurrencyTransferStartedMessage; import bisq.core.trade.messages.TradeMessage; import bisq.core.trade.protocol.tasks.SendMailboxMessageTask; +import bisq.common.Timer; +import bisq.common.UserThread; import bisq.common.taskrunner.TaskRunner; +import javafx.beans.value.ChangeListener; + +import java.util.concurrent.TimeUnit; + import lombok.extern.slf4j.Slf4j; +import static com.google.common.base.Preconditions.checkNotNull; + @Slf4j public class BuyerSendCounterCurrencyTransferStartedMessage extends SendMailboxMessageTask { - @SuppressWarnings({"unused"}) + private static final long MAX_REFRESH_INTERVAL = TimeUnit.HOURS.toMillis(4); + + private ChangeListener listener; + private Timer timer; + private CounterCurrencyTransferStartedMessage counterCurrencyTransferStartedMessage; + + public BuyerSendCounterCurrencyTransferStartedMessage(TaskRunner taskHandler, Trade trade) { super(taskHandler, trade); } @Override protected TradeMessage getMessage(String tradeId) { - BtcWalletService walletService = processModel.getBtcWalletService(); - String id = processModel.getOfferId(); - AddressEntry payoutAddressEntry = walletService.getOrCreateAddressEntry(id, - AddressEntry.Context.TRADE_PAYOUT); - // We do not use a real unique ID here as we want to be able to re-send the exact same message in case the - // peer does not respond with an ACK msg in a certain time interval. To avoid that we get dangling mailbox - // messages where only the one which gets processed by the peer would be removed we use the same uid. All - // other data stays the same when we re-send the message at any time later. - String deterministicId = tradeId + processModel.getMyNodeAddress().getFullAddress(); - - return new CounterCurrencyTransferStartedMessage( - id, - payoutAddressEntry.getAddressString(), - processModel.getMyNodeAddress(), - processModel.getPayoutTxSignature(), - trade.getCounterCurrencyTxId(), - trade.getCounterCurrencyExtraData(), - deterministicId - ); + if (counterCurrencyTransferStartedMessage == null) { + AddressEntry payoutAddressEntry = processModel.getBtcWalletService().getOrCreateAddressEntry(tradeId, + AddressEntry.Context.TRADE_PAYOUT); + + // We do not use a real unique ID here as we want to be able to re-send the exact same message in case the + // peer does not respond with an ACK msg in a certain time interval. To avoid that we get dangling mailbox + // messages where only the one which gets processed by the peer would be removed we use the same uid. All + // other data stays the same when we re-send the message at any time later. + String deterministicId = tradeId + processModel.getMyNodeAddress().getFullAddress(); + counterCurrencyTransferStartedMessage = new CounterCurrencyTransferStartedMessage( + tradeId, + payoutAddressEntry.getAddressString(), + processModel.getMyNodeAddress(), + processModel.getPayoutTxSignature(), + trade.getCounterCurrencyTxId(), + trade.getCounterCurrencyExtraData(), + deterministicId + ); + } + return counterCurrencyTransferStartedMessage; } @Override @@ -66,16 +82,19 @@ protected void setStateSent() { @Override protected void setStateArrived() { trade.setState(Trade.State.BUYER_SAW_ARRIVED_FIAT_PAYMENT_INITIATED_MSG); + stop(); } @Override protected void setStateStoredInMailbox() { trade.setState(Trade.State.BUYER_STORED_IN_MAILBOX_FIAT_PAYMENT_INITIATED_MSG); + start(); } @Override protected void setStateFault() { trade.setState(Trade.State.BUYER_SEND_FAILED_FIAT_PAYMENT_INITIATED_MSG); + start(); } @Override @@ -88,4 +107,33 @@ protected void run() { failed(t); } } + + private void stop() { + if (timer != null) { + timer.stop(); + processModel.getPaymentStartedMessageStateProperty().removeListener(listener); + } + } + + // The listeners ensure we don't get GCed even we have completed the task. + private void start() { + if (timer != null) { + return; + } + + PaymentMethod paymentMethod = checkNotNull(trade.getOffer()).getPaymentMethod(); + // For instant trades with 1 hour we want a short interval, otherwise a few hours should be ok. + long interval = Math.min(paymentMethod.getMaxTradePeriod() / 5, MAX_REFRESH_INTERVAL); + interval = 1000; + timer = UserThread.runPeriodically(() -> super.run(), interval, TimeUnit.MILLISECONDS); + + listener = (observable, oldValue, newValue) -> { + // Once we receive an ACK from our msg we know the peer has received the msg and we stop. + if (newValue == MessageState.ACKNOWLEDGED) { + // Ensure listener construction is completed before remove call + UserThread.execute(this::stop); + } + }; + processModel.getPaymentStartedMessageStateProperty().addListener(listener); + } } From 873d2cfbc23803c535480e573e04ef683c4e51f3 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 22:13:40 -0500 Subject: [PATCH 47/56] Start BuyerSendCounterCurrencyTransferStartedMessage at startup again in case we have not received an ACK --- core/src/main/java/bisq/core/trade/BuyerTrade.java | 1 - .../core/trade/protocol/BuyerAsMakerProtocol.java | 13 +++++++++++++ .../core/trade/protocol/BuyerAsTakerProtocol.java | 13 +++++++++++++ ...erSendCounterCurrencyTransferStartedMessage.java | 2 ++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/bisq/core/trade/BuyerTrade.java b/core/src/main/java/bisq/core/trade/BuyerTrade.java index 3e361a47bbb..c58063bfeac 100644 --- a/core/src/main/java/bisq/core/trade/BuyerTrade.java +++ b/core/src/main/java/bisq/core/trade/BuyerTrade.java @@ -174,7 +174,6 @@ public boolean wasCanceledTrade() { } } - @Override public String toString() { return "BuyerTrade{" + diff --git a/core/src/main/java/bisq/core/trade/protocol/BuyerAsMakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/BuyerAsMakerProtocol.java index 0b9c9ccd2f1..e91a49816ca 100644 --- a/core/src/main/java/bisq/core/trade/protocol/BuyerAsMakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/BuyerAsMakerProtocol.java @@ -87,6 +87,19 @@ public BuyerAsMakerProtocol(BuyerAsMakerTrade trade) { taskRunner.addTasks(BuyerSetupPayoutTxListener.class); taskRunner.run(); } + + // We might have 2 taskRunners as BuyerSetupPayoutTxListener might have been started as well + if (trade.getState() == Trade.State.BUYER_STORED_IN_MAILBOX_FIAT_PAYMENT_INITIATED_MSG || + trade.getState() == Trade.State.BUYER_SEND_FAILED_FIAT_PAYMENT_INITIATED_MSG) { + // In case we have not received an ACK from the CounterCurrencyTransferStartedMessage we re-send it + // periodically in BuyerSendCounterCurrencyTransferStartedMessage + TradeTaskRunner taskRunner = new TradeTaskRunner(trade, + () -> handleTaskRunnerSuccess("BuyerSendCounterCurrencyTransferStartedMessage"), + this::handleTaskRunnerFault); + + taskRunner.addTasks(BuyerSendCounterCurrencyTransferStartedMessage.class); + taskRunner.run(); + } } @Override diff --git a/core/src/main/java/bisq/core/trade/protocol/BuyerAsTakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/BuyerAsTakerProtocol.java index bca0efd4a6c..c0c8b3a3cf1 100644 --- a/core/src/main/java/bisq/core/trade/protocol/BuyerAsTakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/BuyerAsTakerProtocol.java @@ -95,6 +95,19 @@ public BuyerAsTakerProtocol(BuyerAsTakerTrade trade) { taskRunner.addTasks(BuyerSetupPayoutTxListener.class); taskRunner.run(); } + + // We might have 2 taskRunners as BuyerSetupPayoutTxListener might have been started as well + if (trade.getState() == Trade.State.BUYER_STORED_IN_MAILBOX_FIAT_PAYMENT_INITIATED_MSG || + trade.getState() == Trade.State.BUYER_SEND_FAILED_FIAT_PAYMENT_INITIATED_MSG) { + // In case we have not received an ACK from the CounterCurrencyTransferStartedMessage we re-send it + // periodically in BuyerSendCounterCurrencyTransferStartedMessage + TradeTaskRunner taskRunner = new TradeTaskRunner(trade, + () -> handleTaskRunnerSuccess("BuyerSendCounterCurrencyTransferStartedMessage"), + this::handleTaskRunnerFault); + + taskRunner.addTasks(BuyerSendCounterCurrencyTransferStartedMessage.class); + taskRunner.run(); + } } @Override diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerSendCounterCurrencyTransferStartedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerSendCounterCurrencyTransferStartedMessage.java index a96992ee57c..7166e2e1b20 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerSendCounterCurrencyTransferStartedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerSendCounterCurrencyTransferStartedMessage.java @@ -130,6 +130,8 @@ private void start() { listener = (observable, oldValue, newValue) -> { // Once we receive an ACK from our msg we know the peer has received the msg and we stop. if (newValue == MessageState.ACKNOWLEDGED) { + // We treat a ACK like BUYER_SAW_ARRIVED_FIAT_PAYMENT_INITIATED_MSG + trade.setState(Trade.State.BUYER_SAW_ARRIVED_FIAT_PAYMENT_INITIATED_MSG); // Ensure listener construction is completed before remove call UserThread.execute(this::stop); } From 00bb8db7841e3c09912a1d4b466b64d38dd3be0a Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 10 Sep 2020 22:17:34 -0500 Subject: [PATCH 48/56] Add comment --- .../java/bisq/core/trade/protocol/SellerAsMakerProtocol.java | 1 + .../java/bisq/core/trade/protocol/SellerAsTakerProtocol.java | 1 + .../SellerProcessCounterCurrencyTransferStartedMessage.java | 1 - 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/bisq/core/trade/protocol/SellerAsMakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/SellerAsMakerProtocol.java index ec26d8bb569..6e9c649deca 100644 --- a/core/src/main/java/bisq/core/trade/protocol/SellerAsMakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/SellerAsMakerProtocol.java @@ -188,6 +188,7 @@ private void handle(DelayedPayoutTxSignatureResponse tradeMessage, NodeAddress s // After peer has started Fiat tx /////////////////////////////////////////////////////////////////////////////////////////// + // It might be that this get called repeated if peer re-sent the message as he did not receive an ACK private void handle(CounterCurrencyTransferStartedMessage tradeMessage, NodeAddress sender) { processModel.setTradeMessage(tradeMessage); processModel.setTempTradingPeerNodeAddress(sender); diff --git a/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java index d4608a767f0..9672efc463d 100644 --- a/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java @@ -179,6 +179,7 @@ private void handle(DelayedPayoutTxSignatureResponse tradeMessage, NodeAddress s // After peer has started Fiat tx /////////////////////////////////////////////////////////////////////////////////////////// + // It might be that this get called repeated if peer re-sent the message as he did not receive an ACK private void handle(CounterCurrencyTransferStartedMessage tradeMessage, NodeAddress sender) { processModel.setTradeMessage(tradeMessage); processModel.setTempTradingPeerNodeAddress(sender); diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerProcessCounterCurrencyTransferStartedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerProcessCounterCurrencyTransferStartedMessage.java index e09bf0158f1..519a52dcb64 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerProcessCounterCurrencyTransferStartedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerProcessCounterCurrencyTransferStartedMessage.java @@ -27,7 +27,6 @@ import lombok.extern.slf4j.Slf4j; import static com.google.common.base.Preconditions.checkNotNull; - @Slf4j public class SellerProcessCounterCurrencyTransferStartedMessage extends TradeTask { @SuppressWarnings({"unused"}) From 2b056383740339cbb3fc7fa289a46331a595a539 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Fri, 11 Sep 2020 09:05:29 -0500 Subject: [PATCH 49/56] Remove dev test value --- .../buyer/BuyerSendCounterCurrencyTransferStartedMessage.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerSendCounterCurrencyTransferStartedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerSendCounterCurrencyTransferStartedMessage.java index 7166e2e1b20..4ddd7cefd30 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerSendCounterCurrencyTransferStartedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerSendCounterCurrencyTransferStartedMessage.java @@ -124,7 +124,6 @@ private void start() { PaymentMethod paymentMethod = checkNotNull(trade.getOffer()).getPaymentMethod(); // For instant trades with 1 hour we want a short interval, otherwise a few hours should be ok. long interval = Math.min(paymentMethod.getMaxTradePeriod() / 5, MAX_REFRESH_INTERVAL); - interval = 1000; timer = UserThread.runPeriodically(() -> super.run(), interval, TimeUnit.MILLISECONDS); listener = (observable, oldValue, newValue) -> { From bf3ce347ddf772aff519f9b8879dd5115ca47055 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Fri, 11 Sep 2020 09:36:26 -0500 Subject: [PATCH 50/56] Refactor: Rename signAccountAgeWitness to signAndPublishAccountAgeWitness Helps to make it more explicit that we not only sign but also broadcast the data. --- .../core/account/sign/SignedWitnessService.java | 14 ++++++-------- .../account/witness/AccountAgeWitnessService.java | 10 +++++----- ...ellerMaybeSignWitnessAndSendWitnessMessage.java | 2 +- .../account/sign/SignedWitnessServiceTest.java | 4 ++-- .../witness/AccountAgeWitnessServiceTest.java | 2 +- .../fiataccounts/FiatAccountsDataModel.java | 2 +- 6 files changed, 16 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/bisq/core/account/sign/SignedWitnessService.java b/core/src/main/java/bisq/core/account/sign/SignedWitnessService.java index 85f00179db9..d45e4cefd24 100644 --- a/core/src/main/java/bisq/core/account/sign/SignedWitnessService.java +++ b/core/src/main/java/bisq/core/account/sign/SignedWitnessService.java @@ -272,16 +272,16 @@ private String signAccountAgeWitness(Coin tradeAmount, return ""; } - public void selfSignAccountAgeWitness(AccountAgeWitness accountAgeWitness) throws CryptoException { + public void signAndPublishAccountAgeWitness(AccountAgeWitness accountAgeWitness) throws CryptoException { log.info("Sign own accountAgeWitness {}", accountAgeWitness); - signAccountAgeWitness(MINIMUM_TRADE_AMOUNT_FOR_SIGNING, accountAgeWitness, + signAndPublishAccountAgeWitness(MINIMUM_TRADE_AMOUNT_FOR_SIGNING, accountAgeWitness, keyRing.getSignatureKeyPair().getPublic()); } // Any peer can sign with DSA key - public Optional signAccountAgeWitness(Coin tradeAmount, - AccountAgeWitness accountAgeWitness, - PublicKey peersPubKey) throws CryptoException { + public Optional signAndPublishAccountAgeWitness(Coin tradeAmount, + AccountAgeWitness accountAgeWitness, + PublicKey peersPubKey) throws CryptoException { if (isSignedAccountAgeWitness(accountAgeWitness)) { log.warn("Trader trying to sign already signed accountagewitness {}", accountAgeWitness.toString()); return Optional.empty(); @@ -494,9 +494,7 @@ void addToMap(SignedWitness signedWitness) { private void publishSignedWitness(SignedWitness signedWitness) { if (!signedWitnessMap.containsKey(signedWitness.getHashAsByteArray())) { log.info("broadcast signed witness {}", signedWitness.toString()); - // We set reBroadcast to true. The signer has broadcast the signedWitness as - // well, so it might be that we have received the data already, but we prefer to re-broadcast - // to achieve better resilience. + // We set reBroadcast to true to achieve better resilience. p2PService.addPersistableNetworkPayload(signedWitness, true); addToMap(signedWitness); } diff --git a/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java b/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java index 3ceb8c0105d..3f0cbdb327a 100644 --- a/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java +++ b/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java @@ -198,7 +198,7 @@ public void onUpdatedDataReceived() { private void onBootStrapped() { republishAllFiatAccounts(); - signSameNameAccounts(); + signAndPublishSameNameAccounts(); } @@ -668,7 +668,7 @@ public void arbitratorSignAccountAgeWitness(AccountAgeWitness accountAgeWitness, signedWitnessService.signAccountAgeWitness(accountAgeWitness, key, tradersPubKey, time); } - public Optional traderSignPeersAccountAgeWitness(Trade trade) { + public Optional traderSignAndPublishPeersAccountAgeWitness(Trade trade) { AccountAgeWitness peersWitness = findTradePeerWitness(trade).orElse(null); Coin tradeAmount = trade.getTradeAmount(); checkNotNull(trade.getProcessModel().getTradingPeer().getPubKeyRing(), "Peer must have a keyring"); @@ -678,7 +678,7 @@ public Optional traderSignPeersAccountAgeWitness(Trade trade) { checkNotNull(peersPubKey, "Peers pub key must not be null"); try { - return signedWitnessService.signAccountAgeWitness(tradeAmount, peersWitness, peersPubKey); + return signedWitnessService.signAndPublishAccountAgeWitness(tradeAmount, peersWitness, peersPubKey); } catch (CryptoException e) { log.warn("Trader failed to sign witness, exception {}", e.toString()); } @@ -823,7 +823,7 @@ public Set getOrphanSignedWitnesses() { .collect(Collectors.toSet()); } - public void signSameNameAccounts() { + public void signAndPublishSameNameAccounts() { // Collect accounts that have ownerId to sign unsigned accounts with the same ownderId var signerAccounts = Objects.requireNonNull(user.getPaymentAccounts()).stream() .filter(account -> account.getOwnerId() != null && @@ -838,7 +838,7 @@ public void signSameNameAccounts() { signerAccounts.forEach(signer -> unsignedAccounts.forEach(unsigned -> { if (signer.getOwnerId().equals(unsigned.getOwnerId())) { try { - signedWitnessService.selfSignAccountAgeWitness( + signedWitnessService.signAndPublishAccountAgeWitness( getMyWitness(unsigned.getPaymentAccountPayload())); } catch (CryptoException e) { log.warn("Self signing failed, exception {}", e.toString()); diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerMaybeSignWitnessAndSendWitnessMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerMaybeSignWitnessAndSendWitnessMessage.java index 0d4071b7ed5..e17064913fd 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerMaybeSignWitnessAndSendWitnessMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerMaybeSignWitnessAndSendWitnessMessage.java @@ -80,7 +80,7 @@ protected void run() { return; } - Optional signedWitnessOptional = accountAgeWitnessService.traderSignPeersAccountAgeWitness(trade); + Optional signedWitnessOptional = accountAgeWitnessService.traderSignAndPublishPeersAccountAgeWitness(trade); if (!signedWitnessOptional.isPresent()) { log.warn("signedWitnessOptional is not present"); // TODO not sure if that is a failure case or a valid case, but this follows existing impl logic diff --git a/core/src/test/java/bisq/core/account/sign/SignedWitnessServiceTest.java b/core/src/test/java/bisq/core/account/sign/SignedWitnessServiceTest.java index 338a9b3a705..55a6e8879b9 100644 --- a/core/src/test/java/bisq/core/account/sign/SignedWitnessServiceTest.java +++ b/core/src/test/java/bisq/core/account/sign/SignedWitnessServiceTest.java @@ -354,7 +354,7 @@ public void testSignAccountAgeWitness_withTooLowTradeAmount() throws CryptoExcep when(keyRing.getSignatureKeyPair()).thenReturn(signerKeyPair); AccountAgeWitness accountAgeWitness = new AccountAgeWitness(account1DataHash, accountCreationTime); - signedWitnessService.signAccountAgeWitness(Coin.ZERO, accountAgeWitness, peerKeyPair.getPublic()); + signedWitnessService.signAndPublishAccountAgeWitness(Coin.ZERO, accountAgeWitness, peerKeyPair.getPublic()); verify(p2pService, never()).addPersistableNetworkPayload(any(PersistableNetworkPayload.class), anyBoolean()); } @@ -370,7 +370,7 @@ public void testSignAccountAgeWitness_withSufficientTradeAmount() throws CryptoE AccountAgeWitness accountAgeWitness = new AccountAgeWitness(account1DataHash, accountCreationTime); - signedWitnessService.signAccountAgeWitness(SignedWitnessService.MINIMUM_TRADE_AMOUNT_FOR_SIGNING, accountAgeWitness, peerKeyPair.getPublic()); + signedWitnessService.signAndPublishAccountAgeWitness(SignedWitnessService.MINIMUM_TRADE_AMOUNT_FOR_SIGNING, accountAgeWitness, peerKeyPair.getPublic()); verify(p2pService, times(1)).addPersistableNetworkPayload(any(PersistableNetworkPayload.class), anyBoolean()); } diff --git a/core/src/test/java/bisq/core/account/witness/AccountAgeWitnessServiceTest.java b/core/src/test/java/bisq/core/account/witness/AccountAgeWitnessServiceTest.java index 2b2d11e5621..10840861ddc 100644 --- a/core/src/test/java/bisq/core/account/witness/AccountAgeWitnessServiceTest.java +++ b/core/src/test/java/bisq/core/account/witness/AccountAgeWitnessServiceTest.java @@ -301,7 +301,7 @@ public void testArbitratorSignDummyWitness() throws CryptoException { signAccountAgeWitness(aew2, pubKeyRing2.getSignaturePubKey(), aew2.getDate(), user1KeyRing); // user2 signs user3 signAccountAgeWitness(aew3, pubKeyRing3.getSignaturePubKey(), aew3.getDate(), user2KeyRing); - signedWitnessService.signAccountAgeWitness(SignedWitnessService.MINIMUM_TRADE_AMOUNT_FOR_SIGNING, aew2, + signedWitnessService.signAndPublishAccountAgeWitness(SignedWitnessService.MINIMUM_TRADE_AMOUNT_FOR_SIGNING, aew2, pubKeyRing2.getSignaturePubKey()); assertTrue(service.accountIsSigner(aew1)); assertTrue(service.accountIsSigner(aew2)); diff --git a/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsDataModel.java b/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsDataModel.java index 2cd3dc1ff3d..a9b5f3baccf 100644 --- a/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/account/content/fiataccounts/FiatAccountsDataModel.java @@ -130,7 +130,7 @@ public void onSaveNewAccount(PaymentAccount paymentAccount) { user.addPaymentAccount(paymentAccount); accountAgeWitnessService.publishMyAccountAgeWitness(paymentAccount.getPaymentAccountPayload()); - accountAgeWitnessService.signSameNameAccounts(); + accountAgeWitnessService.signAndPublishSameNameAccounts(); } public boolean onDeleteAccount(PaymentAccount paymentAccount) { From 5e46366791bae6f5aa0c7d278c398df175542f4c Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Fri, 11 Sep 2020 09:37:19 -0500 Subject: [PATCH 51/56] Remove duplicate broadcast of witness data --- .../SellerMaybeSignWitnessAndSendWitnessMessage.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerMaybeSignWitnessAndSendWitnessMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerMaybeSignWitnessAndSendWitnessMessage.java index e17064913fd..cd52f058528 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerMaybeSignWitnessAndSendWitnessMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerMaybeSignWitnessAndSendWitnessMessage.java @@ -80,6 +80,7 @@ protected void run() { return; } + // Broadcast is done in accountAgeWitness domain. Optional signedWitnessOptional = accountAgeWitnessService.traderSignAndPublishPeersAccountAgeWitness(trade); if (!signedWitnessOptional.isPresent()) { log.warn("signedWitnessOptional is not present"); @@ -90,12 +91,6 @@ protected void run() { signedWitness = signedWitnessOptional.get(); - // The signer broadcasts as well the signedWitness. In case the receiver will not get the message we have - // better resilience that the data is in the network. We set reBroadcast to true but do not expect that the - // signedWitness exists already as we just created it. - // TODO check with @sqrrm - processModel.getP2PService().addPersistableNetworkPayload(signedWitness, true); - // Message sending is handled in base class (SendMailboxMessageTask). super.run(); } catch (Throwable t) { From c2296d4f553f0a2b57d8dc164ce437daba559f56 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Fri, 11 Sep 2020 11:57:20 -0500 Subject: [PATCH 52/56] Send witness with PayoutTxPublishedMessage --- .../messages/PayoutTxPublishedMessage.java | 43 ++++++-- .../messages/TraderSignedWitnessMessage.java | 28 +---- .../trade/protocol/SellerAsMakerProtocol.java | 4 +- .../trade/protocol/SellerAsTakerProtocol.java | 4 +- .../core/trade/protocol/TradeProtocol.java | 21 ---- .../BuyerProcessPayoutTxPublishedMessage.java | 10 ++ ...CounterCurrencyTransferStartedMessage.java | 2 + .../cancel/SendRequestCancelTradeMessage.java | 2 + .../SendMediatedPayoutTxPublishedMessage.java | 3 +- ...MaybeSignWitnessAndSendWitnessMessage.java | 100 ------------------ .../SellerSendPayoutTxPublishedMessage.java | 26 ++++- ...SendCancelTradeRequestAcceptedMessage.java | 3 +- ...SendCancelTradeRequestRejectedMessage.java | 3 +- proto/src/main/proto/pb.proto | 12 ++- 14 files changed, 89 insertions(+), 172 deletions(-) delete mode 100644 core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerMaybeSignWitnessAndSendWitnessMessage.java diff --git a/core/src/main/java/bisq/core/trade/messages/PayoutTxPublishedMessage.java b/core/src/main/java/bisq/core/trade/messages/PayoutTxPublishedMessage.java index cae6469c1ea..e1564525c83 100644 --- a/core/src/main/java/bisq/core/trade/messages/PayoutTxPublishedMessage.java +++ b/core/src/main/java/bisq/core/trade/messages/PayoutTxPublishedMessage.java @@ -17,6 +17,8 @@ package bisq.core.trade.messages; +import bisq.core.account.sign.SignedWitness; + import bisq.network.p2p.MailboxMessage; import bisq.network.p2p.NodeAddress; @@ -26,23 +28,35 @@ import com.google.protobuf.ByteString; +import java.util.Optional; +import java.util.UUID; + import lombok.EqualsAndHashCode; import lombok.Value; +import lombok.extern.slf4j.Slf4j; +import javax.annotation.Nullable; + +@Slf4j @EqualsAndHashCode(callSuper = true) @Value public final class PayoutTxPublishedMessage extends TradeMessage implements MailboxMessage { private final byte[] payoutTx; private final NodeAddress senderNodeAddress; + // Added in v1.3.9 + @Nullable + private final SignedWitness signedWitness; + public PayoutTxPublishedMessage(String tradeId, byte[] payoutTx, NodeAddress senderNodeAddress, - String uid) { + @Nullable SignedWitness signedWitness) { this(tradeId, payoutTx, senderNodeAddress, - uid, + signedWitness, + UUID.randomUUID().toString(), Version.getP2PMessageVersion()); } @@ -54,28 +68,37 @@ public PayoutTxPublishedMessage(String tradeId, private PayoutTxPublishedMessage(String tradeId, byte[] payoutTx, NodeAddress senderNodeAddress, + @Nullable SignedWitness signedWitness, String uid, int messageVersion) { super(messageVersion, tradeId, uid); this.payoutTx = payoutTx; this.senderNodeAddress = senderNodeAddress; + this.signedWitness = signedWitness; } @Override public protobuf.NetworkEnvelope toProtoNetworkEnvelope() { - return getNetworkEnvelopeBuilder() - .setPayoutTxPublishedMessage(protobuf.PayoutTxPublishedMessage.newBuilder() - .setTradeId(tradeId) - .setPayoutTx(ByteString.copyFrom(payoutTx)) - .setSenderNodeAddress(senderNodeAddress.toProtoMessage()) - .setUid(uid)) - .build(); + protobuf.PayoutTxPublishedMessage.Builder builder = protobuf.PayoutTxPublishedMessage.newBuilder() + .setTradeId(tradeId) + .setPayoutTx(ByteString.copyFrom(payoutTx)) + .setSenderNodeAddress(senderNodeAddress.toProtoMessage()) + .setUid(uid); + Optional.ofNullable(signedWitness).ifPresent(signedWitness -> builder.setSignedWitness(signedWitness.toProtoSignedWitness())); + return getNetworkEnvelopeBuilder().setPayoutTxPublishedMessage(builder).build(); } public static NetworkEnvelope fromProto(protobuf.PayoutTxPublishedMessage proto, int messageVersion) { + // There is no method to check for a nullable non-primitive data type object but we know that all fields + // are empty/null, so we check for the signature to see if we got a valid signedWitness. + protobuf.SignedWitness protoSignedWitness = proto.getSignedWitness(); + SignedWitness signedWitness = !protoSignedWitness.getSignature().isEmpty() ? + SignedWitness.fromProto(protoSignedWitness) : + null; return new PayoutTxPublishedMessage(proto.getTradeId(), proto.getPayoutTx().toByteArray(), NodeAddress.fromProto(proto.getSenderNodeAddress()), + signedWitness, proto.getUid(), messageVersion); } @@ -85,7 +108,7 @@ public String toString() { return "PayoutTxPublishedMessage{" + "\n payoutTx=" + Utilities.bytesAsHexString(payoutTx) + ",\n senderNodeAddress=" + senderNodeAddress + - ",\n uid='" + uid + '\'' + + ",\n signedWitness=" + signedWitness + "\n} " + super.toString(); } } diff --git a/core/src/main/java/bisq/core/trade/messages/TraderSignedWitnessMessage.java b/core/src/main/java/bisq/core/trade/messages/TraderSignedWitnessMessage.java index 63108cdfda0..48fd88e0d35 100644 --- a/core/src/main/java/bisq/core/trade/messages/TraderSignedWitnessMessage.java +++ b/core/src/main/java/bisq/core/trade/messages/TraderSignedWitnessMessage.java @@ -22,29 +22,20 @@ import bisq.network.p2p.MailboxMessage; import bisq.network.p2p.NodeAddress; -import bisq.common.app.Version; - -import java.util.UUID; - import lombok.EqualsAndHashCode; import lombok.Value; +// Not used anymore from v.1.3.9 on. We need to keep it for backward compatibility. +// Now we send the signedWitness as part of the PayoutTxPublishedMessage to avoid that we send 2 messages and need to +// process 2 messages at the receiver. Parallel/concurrent handling of multiple messages per trade is not supported by +// the design of the trade protocol and should be avoided. +@Deprecated @EqualsAndHashCode(callSuper = true) @Value public class TraderSignedWitnessMessage extends TradeMessage implements MailboxMessage { private final NodeAddress senderNodeAddress; private final SignedWitness signedWitness; - public TraderSignedWitnessMessage(String tradeId, - NodeAddress senderNodeAddress, - SignedWitness signedWitness) { - this(Version.getP2PMessageVersion(), - UUID.randomUUID().toString(), - tradeId, - senderNodeAddress, - signedWitness); - } - /////////////////////////////////////////////////////////////////////////////////////////// // PROTO BUFFER @@ -77,13 +68,4 @@ public static TraderSignedWitnessMessage fromProto(protobuf.TraderSignedWitnessM NodeAddress.fromProto(proto.getSenderNodeAddress()), SignedWitness.fromProto(proto.getSignedWitness())); } - - @Override - public String toString() { - return "TraderSignedWitnessMessage{" + - "\n senderNodeAddress=" + senderNodeAddress + - "\n signedWitness=" + signedWitness + - "\n} " + super.toString(); - } - } diff --git a/core/src/main/java/bisq/core/trade/protocol/SellerAsMakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/SellerAsMakerProtocol.java index 6e9c649deca..57ef54b6332 100644 --- a/core/src/main/java/bisq/core/trade/protocol/SellerAsMakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/SellerAsMakerProtocol.java @@ -36,7 +36,6 @@ import bisq.core.trade.protocol.tasks.seller.SellerBroadcastPayoutTx; import bisq.core.trade.protocol.tasks.seller.SellerCreatesDelayedPayoutTx; import bisq.core.trade.protocol.tasks.seller.SellerFinalizesDelayedPayoutTx; -import bisq.core.trade.protocol.tasks.seller.SellerMaybeSignWitnessAndSendWitnessMessage; import bisq.core.trade.protocol.tasks.seller.SellerProcessCounterCurrencyTransferStartedMessage; import bisq.core.trade.protocol.tasks.seller.SellerProcessDelayedPayoutTxSignatureResponse; import bisq.core.trade.protocol.tasks.seller.SellerPublishesDepositTx; @@ -237,8 +236,7 @@ public void onFiatPaymentReceived(ResultHandler resultHandler, ErrorMessageHandl MakerVerifyTakerFeePayment.class, SellerSignAndFinalizePayoutTx.class, SellerBroadcastPayoutTx.class, - SellerSendPayoutTxPublishedMessage.class, - SellerMaybeSignWitnessAndSendWitnessMessage.class + SellerSendPayoutTxPublishedMessage.class ); taskRunner.run(); } else { diff --git a/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java index 9672efc463d..6f8ca1d7c8c 100644 --- a/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java @@ -31,7 +31,6 @@ import bisq.core.trade.protocol.tasks.seller.SellerBroadcastPayoutTx; import bisq.core.trade.protocol.tasks.seller.SellerCreatesDelayedPayoutTx; import bisq.core.trade.protocol.tasks.seller.SellerFinalizesDelayedPayoutTx; -import bisq.core.trade.protocol.tasks.seller.SellerMaybeSignWitnessAndSendWitnessMessage; import bisq.core.trade.protocol.tasks.seller.SellerProcessCounterCurrencyTransferStartedMessage; import bisq.core.trade.protocol.tasks.seller.SellerProcessDelayedPayoutTxSignatureResponse; import bisq.core.trade.protocol.tasks.seller.SellerPublishesDepositTx; @@ -228,8 +227,7 @@ public void onFiatPaymentReceived(ResultHandler resultHandler, ErrorMessageHandl TakerVerifyMakerFeePayment.class, SellerSignAndFinalizePayoutTx.class, SellerBroadcastPayoutTx.class, - SellerSendPayoutTxPublishedMessage.class, - SellerMaybeSignWitnessAndSendWitnessMessage.class + SellerSendPayoutTxPublishedMessage.class ); taskRunner.run(); } else { diff --git a/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java b/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java index 5a977074a71..7613026efa9 100644 --- a/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java @@ -24,7 +24,6 @@ import bisq.core.trade.messages.InputsForDepositTxRequest; import bisq.core.trade.messages.PeerPublishedDelayedPayoutTxMessage; import bisq.core.trade.messages.TradeMessage; -import bisq.core.trade.messages.TraderSignedWitnessMessage; import bisq.core.trade.messages.mediation.MediatedPayoutTxPublishedMessage; import bisq.core.trade.messages.mediation.MediatedPayoutTxSignatureMessage; import bisq.core.trade.protocol.tasks.ApplyFilter; @@ -236,22 +235,6 @@ private void handle(PeerPublishedDelayedPayoutTxMessage tradeMessage, NodeAddres taskRunner.run(); } - /////////////////////////////////////////////////////////////////////////////////////////// - // Peer has sent a SignedWitness - /////////////////////////////////////////////////////////////////////////////////////////// - - // It would be unsafe to use the TradeTaskRunner framework here as we expect the PeerPublishedDelayedPayoutTxMessage - // around the same time. The ProcessPeerPublishedDelayedPayoutTxMessage task is synchronous so there would not be - // an issue if we start another task runner and set the trade message to the process model, but if the code in - // ProcessPeerPublishedDelayedPayoutTxMessage would become async in future it would introduce inconsistent model - // data. The TradeTaskRunner framework does not support parallel/concurrent execution. The 2 messages should have been - // packed into one and the problem would have been avoided. Now it seems to be the best approach to leave the - // protocol framework and process the message in the AccountAgeWitness domain. - private void handle(TraderSignedWitnessMessage tradeMessage) { - // Publish signed witness, if it is valid and ours - processModel.getAccountAgeWitnessService().publishOwnSignedWitness(tradeMessage.getSignedWitness()); - } - /////////////////////////////////////////////////////////////////////////////////////////// // Dispatcher @@ -264,8 +247,6 @@ protected void doHandleDecryptedMessage(TradeMessage tradeMessage, NodeAddress s handle((MediatedPayoutTxPublishedMessage) tradeMessage, sender); } else if (tradeMessage instanceof PeerPublishedDelayedPayoutTxMessage) { handle((PeerPublishedDelayedPayoutTxMessage) tradeMessage, sender); - } else if (tradeMessage instanceof TraderSignedWitnessMessage) { - handle((TraderSignedWitnessMessage) tradeMessage); } cancelTradeProtocol.doHandleDecryptedMessage(tradeMessage, sender); @@ -315,8 +296,6 @@ protected void doApplyMailboxTradeMessage(TradeMessage tradeMessage, NodeAddress handle((MediatedPayoutTxPublishedMessage) tradeMessage, peerNodeAddress); } else if (tradeMessage instanceof PeerPublishedDelayedPayoutTxMessage) { handle((PeerPublishedDelayedPayoutTxMessage) tradeMessage, peerNodeAddress); - } else if (tradeMessage instanceof TraderSignedWitnessMessage) { - handle((TraderSignedWitnessMessage) tradeMessage); } cancelTradeProtocol.doApplyMailboxTradeMessage(tradeMessage, peerNodeAddress); diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerProcessPayoutTxPublishedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerProcessPayoutTxPublishedMessage.java index cec40f9a894..2b88f3d347c 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerProcessPayoutTxPublishedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerProcessPayoutTxPublishedMessage.java @@ -17,6 +17,7 @@ package bisq.core.trade.protocol.tasks.buyer; +import bisq.core.account.sign.SignedWitness; import bisq.core.btc.model.AddressEntry; import bisq.core.btc.wallet.BtcWalletService; import bisq.core.btc.wallet.WalletService; @@ -64,6 +65,15 @@ protected void run() { } else { log.info("We got the payout tx already set from BuyerSetupPayoutTxListener and do nothing here. trade ID={}", trade.getId()); } + + SignedWitness signedWitness = message.getSignedWitness(); + if (signedWitness != null) { + // We received the signedWitness from the seller and publish the data to the network. + // The signer has published it as well but we prefer to re-do it on our side as well to achieve higher + // resilience. + processModel.getAccountAgeWitnessService().publishOwnSignedWitness(signedWitness); + } + processModel.removeMailboxMessageAfterProcessing(trade); complete(); } catch (Throwable t) { diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerSendCounterCurrencyTransferStartedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerSendCounterCurrencyTransferStartedMessage.java index 4ddd7cefd30..83d1ba0c065 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerSendCounterCurrencyTransferStartedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/BuyerSendCounterCurrencyTransferStartedMessage.java @@ -33,10 +33,12 @@ import java.util.concurrent.TimeUnit; +import lombok.EqualsAndHashCode; import lombok.extern.slf4j.Slf4j; import static com.google.common.base.Preconditions.checkNotNull; +@EqualsAndHashCode(callSuper = true) @Slf4j public class BuyerSendCounterCurrencyTransferStartedMessage extends SendMailboxMessageTask { private static final long MAX_REFRESH_INTERVAL = TimeUnit.HOURS.toMillis(4); diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SendRequestCancelTradeMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SendRequestCancelTradeMessage.java index 1d4e26f87d5..6f829bde305 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SendRequestCancelTradeMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/buyer/cancel/SendRequestCancelTradeMessage.java @@ -32,11 +32,13 @@ import java.util.UUID; +import lombok.EqualsAndHashCode; import lombok.extern.slf4j.Slf4j; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +@EqualsAndHashCode(callSuper = true) @Slf4j public class SendRequestCancelTradeMessage extends SendMailboxMessageTask { private final BuyerTrade buyerTrade; diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutTxPublishedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutTxPublishedMessage.java index 68f8bafdafe..2efcf89c26e 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutTxPublishedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/mediation/SendMediatedPayoutTxPublishedMessage.java @@ -29,11 +29,12 @@ import java.util.UUID; +import lombok.EqualsAndHashCode; import lombok.extern.slf4j.Slf4j; import static com.google.common.base.Preconditions.checkNotNull; - +@EqualsAndHashCode(callSuper = true) @Slf4j public class SendMediatedPayoutTxPublishedMessage extends SendMailboxMessageTask { @SuppressWarnings({"unused"}) diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerMaybeSignWitnessAndSendWitnessMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerMaybeSignWitnessAndSendWitnessMessage.java deleted file mode 100644 index cd52f058528..00000000000 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerMaybeSignWitnessAndSendWitnessMessage.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq 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. - * - * Bisq 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 Bisq. If not, see . - */ - -package bisq.core.trade.protocol.tasks.seller; - -import bisq.core.account.sign.SignedWitness; -import bisq.core.account.witness.AccountAgeWitnessService; -import bisq.core.trade.Trade; -import bisq.core.trade.messages.TradeMessage; -import bisq.core.trade.messages.TraderSignedWitnessMessage; -import bisq.core.trade.protocol.tasks.SendMailboxMessageTask; - -import bisq.common.taskrunner.TaskRunner; - -import java.util.Optional; - -import lombok.extern.slf4j.Slf4j; - -@Slf4j -public class SellerMaybeSignWitnessAndSendWitnessMessage extends SendMailboxMessageTask { - private SignedWitness signedWitness; - - @SuppressWarnings({"unused"}) - public SellerMaybeSignWitnessAndSendWitnessMessage(TaskRunner taskHandler, Trade trade) { - super(taskHandler, trade); - } - - @Override - protected TradeMessage getMessage(String id) { - return new TraderSignedWitnessMessage(trade.getId(), processModel.getMyNodeAddress(), signedWitness); - } - - @Override - protected void setStateSent() { - log.info("Sent TraderSignedWitnessMessage: tradeId={} at peer {} SignedWitness {}", - trade.getId(), trade.getTradingPeerNodeAddress(), signedWitness); - } - - @Override - protected void setStateArrived() { - log.info("TraderSignedWitnessMessage arrived: tradeId={} at peer {} SignedWitness {}", - trade.getId(), trade.getTradingPeerNodeAddress(), signedWitness); - } - - @Override - protected void setStateStoredInMailbox() { - log.info("TraderSignedWitnessMessage storedInMailbox: tradeId={} at peer {} SignedWitness {}", - trade.getId(), trade.getTradingPeerNodeAddress(), signedWitness); - } - - @Override - protected void setStateFault() { - log.error("TraderSignedWitnessMessage failed: tradeId={} at peer {} SignedWitness {}", - trade.getId(), trade.getTradingPeerNodeAddress(), signedWitness); - } - - @Override - protected void run() { - try { - runInterceptHook(); - - AccountAgeWitnessService accountAgeWitnessService = processModel.getAccountAgeWitnessService(); - if (!accountAgeWitnessService.isSignWitnessTrade(trade)) { - log.warn("Is not a witness trade"); - complete(); - return; - } - - // Broadcast is done in accountAgeWitness domain. - Optional signedWitnessOptional = accountAgeWitnessService.traderSignAndPublishPeersAccountAgeWitness(trade); - if (!signedWitnessOptional.isPresent()) { - log.warn("signedWitnessOptional is not present"); - // TODO not sure if that is a failure case or a valid case, but this follows existing impl logic - complete(); - return; - } - - signedWitness = signedWitnessOptional.get(); - - // Message sending is handled in base class (SendMailboxMessageTask). - super.run(); - } catch (Throwable t) { - failed(t); - } - } -} diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerSendPayoutTxPublishedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerSendPayoutTxPublishedMessage.java index 002b4308ec2..969758a9ebb 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerSendPayoutTxPublishedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerSendPayoutTxPublishedMessage.java @@ -17,6 +17,8 @@ package bisq.core.trade.protocol.tasks.seller; +import bisq.core.account.sign.SignedWitness; +import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.trade.Trade; import bisq.core.trade.messages.PayoutTxPublishedMessage; import bisq.core.trade.messages.TradeMessage; @@ -26,15 +28,16 @@ import org.bitcoinj.core.Transaction; -import java.util.UUID; - +import lombok.EqualsAndHashCode; import lombok.extern.slf4j.Slf4j; import static com.google.common.base.Preconditions.checkNotNull; +@EqualsAndHashCode(callSuper = true) @Slf4j public class SellerSendPayoutTxPublishedMessage extends SendMailboxMessageTask { - @SuppressWarnings({"unused"}) + SignedWitness signedWitness = null; + public SellerSendPayoutTxPublishedMessage(TaskRunner taskHandler, Trade trade) { super(taskHandler, trade); } @@ -42,32 +45,47 @@ public SellerSendPayoutTxPublishedMessage(TaskRunner taskHandler, Trade trade) { @Override protected TradeMessage getMessage(String id) { Transaction payoutTx = checkNotNull(trade.getPayoutTx(), "trade.getPayoutTx() must not be null"); + + AccountAgeWitnessService accountAgeWitnessService = processModel.getAccountAgeWitnessService(); + if (accountAgeWitnessService.isSignWitnessTrade(trade)) { + // Broadcast is done in accountAgeWitness domain. + accountAgeWitnessService.traderSignAndPublishPeersAccountAgeWitness(trade).ifPresent(witness -> signedWitness = witness); + } + return new PayoutTxPublishedMessage( id, payoutTx.bitcoinSerialize(), processModel.getMyNodeAddress(), - UUID.randomUUID().toString() + signedWitness ); } @Override protected void setStateSent() { trade.setState(Trade.State.SELLER_SENT_PAYOUT_TX_PUBLISHED_MSG); + log.info("Sent PayoutTxPublishedMessage: tradeId={} at peer {} SignedWitness {}", + trade.getId(), trade.getTradingPeerNodeAddress(), signedWitness); } @Override protected void setStateArrived() { trade.setState(Trade.State.SELLER_SAW_ARRIVED_PAYOUT_TX_PUBLISHED_MSG); + log.info("PayoutTxPublishedMessage arrived: tradeId={} at peer {} SignedWitness {}", + trade.getId(), trade.getTradingPeerNodeAddress(), signedWitness); } @Override protected void setStateStoredInMailbox() { trade.setState(Trade.State.SELLER_STORED_IN_MAILBOX_PAYOUT_TX_PUBLISHED_MSG); + log.info("PayoutTxPublishedMessage storedInMailbox: tradeId={} at peer {} SignedWitness {}", + trade.getId(), trade.getTradingPeerNodeAddress(), signedWitness); } @Override protected void setStateFault() { trade.setState(Trade.State.SELLER_SEND_FAILED_PAYOUT_TX_PUBLISHED_MSG); + log.error("PayoutTxPublishedMessage failed: tradeId={} at peer {} SignedWitness {}", + trade.getId(), trade.getTradingPeerNodeAddress(), signedWitness); } @Override diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestAcceptedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestAcceptedMessage.java index 157e1e82dfd..38289d7b639 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestAcceptedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestAcceptedMessage.java @@ -29,12 +29,13 @@ import java.util.UUID; +import lombok.EqualsAndHashCode; import lombok.extern.slf4j.Slf4j; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; - +@EqualsAndHashCode(callSuper = true) @Slf4j public class SendCancelTradeRequestAcceptedMessage extends SendMailboxMessageTask { private final SellerTrade sellerTrade; diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestRejectedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestRejectedMessage.java index fb217b42039..1a0e1c40e84 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestRejectedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/cancel/SendCancelTradeRequestRejectedMessage.java @@ -27,11 +27,12 @@ import java.util.UUID; +import lombok.EqualsAndHashCode; import lombok.extern.slf4j.Slf4j; import static com.google.common.base.Preconditions.checkArgument; - +@EqualsAndHashCode(callSuper = true) @Slf4j public class SendCancelTradeRequestRejectedMessage extends SendMailboxMessageTask { private final SellerTrade sellerTrade; diff --git a/proto/src/main/proto/pb.proto b/proto/src/main/proto/pb.proto index da589768faa..bb4fb827f3f 100644 --- a/proto/src/main/proto/pb.proto +++ b/proto/src/main/proto/pb.proto @@ -77,7 +77,7 @@ message NetworkEnvelope { PeerPublishedDelayedPayoutTxMessage peer_published_delayed_payout_tx_message = 49; RefreshTradeStateRequest refresh_trade_state_request = 50; - TraderSignedWitnessMessage trader_signed_witness_message = 51; + TraderSignedWitnessMessage trader_signed_witness_message = 51 [deprecated = true]; RequestCancelTradeMessage request_cancel_trade_message = 52; CancelTradeRequestAcceptedMessage cancel_trade_accepted_message = 53; @@ -313,6 +313,7 @@ message PayoutTxPublishedMessage { bytes payout_tx = 2; NodeAddress sender_node_address = 3; string uid = 4; + SignedWitness signed_witness = 5; // Added in v1.3.9 } message MediatedPayoutTxPublishedMessage { @@ -354,11 +355,12 @@ message RefreshTradeStateRequest { NodeAddress sender_node_address = 3; } +// Deprecated since v1.3.9 message TraderSignedWitnessMessage { - string uid = 1; - string trade_id = 2; - NodeAddress sender_node_address = 3; - SignedWitness signed_witness = 4; + string uid = 1 [deprecated = true]; + string trade_id = 2 [deprecated = true]; + NodeAddress sender_node_address = 3 [deprecated = true]; + SignedWitness signed_witness = 4 [deprecated = true]; } // dispute From 37496c240a35e8e6afa819b89b4e5f9c59b08b16 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Fri, 11 Sep 2020 12:05:04 -0500 Subject: [PATCH 53/56] Remove refresh button We do the re-sending of the payment sent message via the BuyerSendCounterCurrencyTransferStartedMessage task on the buyer side, so seller do not need to do anything interactively. --- .../messages/RefreshTradeStateRequest.java | 24 ++------ .../trade/protocol/BuyerAsMakerProtocol.java | 23 ------- .../trade/protocol/BuyerAsTakerProtocol.java | 23 ------- .../pendingtrades/PendingTradesDataModel.java | 41 ------------- .../pendingtrades/PendingTradesView.java | 2 - .../steps/seller/SellerStep2View.java | 60 ------------------- proto/src/main/proto/pb.proto | 9 +-- 7 files changed, 10 insertions(+), 172 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/messages/RefreshTradeStateRequest.java b/core/src/main/java/bisq/core/trade/messages/RefreshTradeStateRequest.java index 907af09a652..62b2ab69460 100644 --- a/core/src/main/java/bisq/core/trade/messages/RefreshTradeStateRequest.java +++ b/core/src/main/java/bisq/core/trade/messages/RefreshTradeStateRequest.java @@ -20,25 +20,19 @@ import bisq.network.p2p.MailboxMessage; import bisq.network.p2p.NodeAddress; -import bisq.common.app.Version; - import lombok.EqualsAndHashCode; import lombok.Value; +/** + * Not used anymore since v1.3.9 + * We do the re-sending of the payment sent message via the BuyerSendCounterCurrencyTransferStartedMessage task on the + * buyer side, so seller do not need to do anything interactively. + */ @EqualsAndHashCode(callSuper = true) @Value public class RefreshTradeStateRequest extends TradeMessage implements MailboxMessage { private final NodeAddress senderNodeAddress; - public RefreshTradeStateRequest(String uid, - String tradeId, - NodeAddress senderNodeAddress) { - this(Version.getP2PMessageVersion(), - uid, - tradeId, - senderNodeAddress); - } - /////////////////////////////////////////////////////////////////////////////////////////// // PROTO BUFFER @@ -67,12 +61,4 @@ public static RefreshTradeStateRequest fromProto(protobuf.RefreshTradeStateReque proto.getTradeId(), NodeAddress.fromProto(proto.getSenderNodeAddress())); } - - @Override - public String toString() { - return "RefreshTradeStateRequest{" + - "\n senderNodeAddress=" + senderNodeAddress + - "\n} " + super.toString(); - } - } diff --git a/core/src/main/java/bisq/core/trade/protocol/BuyerAsMakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/BuyerAsMakerProtocol.java index e91a49816ca..3022a12d1d0 100644 --- a/core/src/main/java/bisq/core/trade/protocol/BuyerAsMakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/BuyerAsMakerProtocol.java @@ -23,7 +23,6 @@ import bisq.core.trade.messages.DepositTxAndDelayedPayoutTxMessage; import bisq.core.trade.messages.InputsForDepositTxRequest; import bisq.core.trade.messages.PayoutTxPublishedMessage; -import bisq.core.trade.messages.RefreshTradeStateRequest; import bisq.core.trade.messages.TradeMessage; import bisq.core.trade.protocol.tasks.ApplyFilter; import bisq.core.trade.protocol.tasks.PublishTradeStatistics; @@ -120,8 +119,6 @@ public void doApplyMailboxTradeMessage(TradeMessage tradeMessage, NodeAddress pe handle((DepositTxAndDelayedPayoutTxMessage) tradeMessage, peerNodeAddress); } else if (tradeMessage instanceof PayoutTxPublishedMessage) { handle((PayoutTxPublishedMessage) tradeMessage, peerNodeAddress); - } else if (tradeMessage instanceof RefreshTradeStateRequest) { - handle((RefreshTradeStateRequest) tradeMessage, peerNodeAddress); } } @@ -212,24 +209,6 @@ private void handle(PayoutTxPublishedMessage tradeMessage, NodeAddress peerNodeA taskRunner.run(); } - // TODO we do not remove the RefreshTradeStateRequest! - // A better approach IMO would be to automatically resend from the buyer side, so the seller does not need to do - // anything. The msg must be the same otherwise we end up with multiple msg and only one get removed once the - // peer processes it. - private void handle(RefreshTradeStateRequest tradeMessage, NodeAddress peerNodeAddress) { - log.debug("handle RefreshTradeStateRequest called with {} from {}", tradeMessage, peerNodeAddress); - // Resend CounterCurrencyTransferStartedMessage if it hasn't been acked yet and counterparty asked for a refresh - if (trade.getState().getPhase() == Trade.Phase.FIAT_SENT && - trade.getState().ordinal() >= Trade.State.BUYER_SENT_FIAT_PAYMENT_INITIATED_MSG.ordinal()) { - TradeTaskRunner taskRunner = new TradeTaskRunner(buyerAsMakerTrade, - () -> handleTaskRunnerSuccess("onRefreshTradeStateRequest"), - this::handleTaskRunnerFault); - taskRunner.addTasks( - BuyerSendCounterCurrencyTransferStartedMessage.class - ); - taskRunner.run(); - } - } /////////////////////////////////////////////////////////////////////////////////////////// // Called from UI @@ -284,8 +263,6 @@ protected void doHandleDecryptedMessage(TradeMessage tradeMessage, NodeAddress s handle((DepositTxAndDelayedPayoutTxMessage) tradeMessage, sender); } else if (tradeMessage instanceof PayoutTxPublishedMessage) { handle((PayoutTxPublishedMessage) tradeMessage, sender); - } else if (tradeMessage instanceof RefreshTradeStateRequest) { - handle((RefreshTradeStateRequest) tradeMessage, sender); } } } diff --git a/core/src/main/java/bisq/core/trade/protocol/BuyerAsTakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/BuyerAsTakerProtocol.java index c0c8b3a3cf1..ce32d0b4a5b 100644 --- a/core/src/main/java/bisq/core/trade/protocol/BuyerAsTakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/BuyerAsTakerProtocol.java @@ -25,7 +25,6 @@ import bisq.core.trade.messages.DepositTxAndDelayedPayoutTxMessage; import bisq.core.trade.messages.InputsForDepositTxResponse; import bisq.core.trade.messages.PayoutTxPublishedMessage; -import bisq.core.trade.messages.RefreshTradeStateRequest; import bisq.core.trade.messages.TradeMessage; import bisq.core.trade.protocol.tasks.ApplyFilter; import bisq.core.trade.protocol.tasks.PublishTradeStatistics; @@ -127,8 +126,6 @@ public void doApplyMailboxTradeMessage(TradeMessage tradeMessage, NodeAddress pe handle((DepositTxAndDelayedPayoutTxMessage) tradeMessage, peerNodeAddress); } else if (tradeMessage instanceof PayoutTxPublishedMessage) { handle((PayoutTxPublishedMessage) tradeMessage, peerNodeAddress); - } else if (tradeMessage instanceof RefreshTradeStateRequest) { - handle((RefreshTradeStateRequest) tradeMessage, peerNodeAddress); } } @@ -235,24 +232,6 @@ private void handle(PayoutTxPublishedMessage tradeMessage, NodeAddress peerNodeA taskRunner.run(); } - // TODO we do not remove the RefreshTradeStateRequest! - // A better approach IMO would be to automatically resend from the buyer side, so the seller does not need to do - // anything. The msg must be the same otherwise we end up with multiple msg and only one get removed once the - // peer processes it. - private void handle(RefreshTradeStateRequest tradeMessage, NodeAddress peerNodeAddress) { - log.debug("handle RefreshTradeStateRequest called with {} from {}", tradeMessage, peerNodeAddress); - // Resend CounterCurrencyTransferStartedMessage if it hasn't been acked yet and counterparty asked for a refresh - if (trade.getState().getPhase() == Trade.Phase.FIAT_SENT && - trade.getState().ordinal() >= Trade.State.BUYER_SENT_FIAT_PAYMENT_INITIATED_MSG.ordinal()) { - TradeTaskRunner taskRunner = new TradeTaskRunner(buyerAsTakerTrade, - () -> handleTaskRunnerSuccess("onRefreshTradeStateRequest"), - this::handleTaskRunnerFault); - taskRunner.addTasks( - BuyerSendCounterCurrencyTransferStartedMessage.class - ); - taskRunner.run(); - } - } /////////////////////////////////////////////////////////////////////////////////////////// // Called from UI @@ -308,8 +287,6 @@ protected void doHandleDecryptedMessage(TradeMessage tradeMessage, NodeAddress s handle((DepositTxAndDelayedPayoutTxMessage) tradeMessage, sender); } else if (tradeMessage instanceof PayoutTxPublishedMessage) { handle((PayoutTxPublishedMessage) tradeMessage, sender); - } else if (tradeMessage instanceof RefreshTradeStateRequest) { - handle((RefreshTradeStateRequest) tradeMessage, sender); } } } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesDataModel.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesDataModel.java index be95a4e56be..3f5e7f8f926 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesDataModel.java @@ -51,13 +51,10 @@ import bisq.core.trade.Trade; import bisq.core.trade.TradeCancellationManager; import bisq.core.trade.TradeManager; -import bisq.core.trade.messages.RefreshTradeStateRequest; import bisq.core.user.Preferences; import bisq.core.util.FormattingUtils; -import bisq.network.p2p.NodeAddress; import bisq.network.p2p.P2PService; -import bisq.network.p2p.SendMailboxMessageListener; import bisq.common.crypto.PubKeyRing; import bisq.common.handlers.ErrorMessageHandler; @@ -82,7 +79,6 @@ import org.spongycastle.crypto.params.KeyParameter; -import java.util.UUID; import java.util.stream.Collectors; import lombok.Getter; @@ -241,43 +237,6 @@ public void onMoveToFailedTrades() { tradeManager.addTradeToFailedTrades(getTrade()); } - // Ask counterparty to resend last action (in case message was lost) - public void refreshTradeState() { - Trade trade = getTrade(); - if (trade == null || !trade.allowedRefresh()) return; - - trade.logRefresh(); - NodeAddress tradingPeerNodeAddress = trade.getTradingPeerNodeAddress(); - - RefreshTradeStateRequest refreshReq = new RefreshTradeStateRequest(UUID.randomUUID().toString(), - trade.getId(), - tradingPeerNodeAddress); - p2PService.sendEncryptedMailboxMessage( - tradingPeerNodeAddress, - trade.getProcessModel().getTradingPeer().getPubKeyRing(), - refreshReq, - new SendMailboxMessageListener() { - @Override - public void onArrived() { - log.info("SendMailboxMessageListener onArrived tradeId={} at peer {}", - trade.getId(), tradingPeerNodeAddress); - } - - @Override - public void onStoredInMailbox() { - log.info("SendMailboxMessageListener onStoredInMailbox tradeId={} at peer {}", - trade.getId(), tradingPeerNodeAddress); - } - - @Override - public void onFault(String errorMessage) { - log.error("SendMailboxMessageListener onFault tradeId={} at peer {}", - trade.getId(), tradingPeerNodeAddress); - } - } - ); - tradeManager.persistTrades(); - } /////////////////////////////////////////////////////////////////////////////////////////// // Getters diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesView.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesView.java index 3776b3f1a7e..d211997f8a5 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesView.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/PendingTradesView.java @@ -216,8 +216,6 @@ public void initialize() { new Popup().warning(Res.get("portfolio.pending.removeFailedTrade")) .onAction(model.dataModel::onMoveToFailedTrades) .show(); - } else if (Utilities.isAltOrCtrlPressed(KeyCode.R, keyEvent)) { - model.dataModel.refreshTradeState(); } }; diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java index 2344e63088b..a82d2c5bbb0 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java @@ -25,18 +25,11 @@ import bisq.core.locale.Res; import bisq.core.payment.payload.F2FAccountPayload; -import bisq.core.trade.Trade; - -import bisq.common.Timer; -import bisq.common.UserThread; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.layout.GridPane; -import java.util.Date; -import java.util.concurrent.TimeUnit; - import static bisq.desktop.util.FormBuilder.addButtonAfterGroup; import static bisq.desktop.util.FormBuilder.addMultilineLabel; import static bisq.desktop.util.FormBuilder.addTitledGroupBg; @@ -44,8 +37,6 @@ public class SellerStep2View extends TradeStepView { - private GridPane refreshButtonPane; - private Timer timer; private SellersCancelTradePresentation sellersCancelTradePresentation; private Button cancelRequestButton; private Label cancelRequestInfoLabel; @@ -82,7 +73,6 @@ public void initialize() { } addCancelRequestBlock(); - addRefreshBlock(); sellersCancelTradePresentation.initialize(cancelRequestTitledGroupBg, cancelRequestInfoLabel, cancelRequestButton); } @@ -91,8 +81,6 @@ public void initialize() { public void activate() { super.activate(); - activateRefreshButton(); - sellersCancelTradePresentation.activate(); } @@ -100,8 +88,6 @@ public void activate() { public void deactivate() { super.deactivate(); - deActivateRefreshButtonTimer(); - sellersCancelTradePresentation.deactivate(); } @@ -121,52 +107,6 @@ private void addCancelRequestBlock() { cancelRequestButton = addButtonAfterGroup(gridPane, ++gridRow, Res.get("portfolio.pending.seller.cancelRequest.button")); } - private void addRefreshBlock() { - refreshButtonPane = new GridPane(); - TitledGroupBg refreshTitledGroupBg = addTitledGroupBg(refreshButtonPane, 0, 1, - Res.get("portfolio.pending.step2_seller.refresh"), Layout.COMPACT_GROUP_DISTANCE); - addMultilineLabel(refreshButtonPane, 1, Res.get("portfolio.pending.step2_seller.refreshInfo"), - Layout.COMPACT_FIRST_ROW_AND_COMPACT_GROUP_DISTANCE); - Button refreshButton = addButtonAfterGroup(refreshButtonPane, 2, Res.get("portfolio.pending.step2_seller.refresh")); - refreshButton.setOnAction(event -> onRefreshButton()); - - refreshTitledGroupBg.getStyleClass().add("last"); - cancelRequestTitledGroupBg.getStyleClass().remove("last"); - titledGroupBg.getStyleClass().remove("last"); - - GridPane.setRowIndex(refreshButtonPane, ++gridRow); - GridPane.setColumnIndex(refreshButtonPane, 0); - GridPane.setColumnSpan(refreshButtonPane, 2); - gridPane.getChildren().add(refreshButtonPane); - } - - private void activateRefreshButton() { - checkNotNull(model.dataModel.getTrade(), "No trade found"); - - Trade trade = model.dataModel.getTrade(); - var timeToNextRefresh = - trade.getLastRefreshRequestDate() + trade.getRefreshInterval() - new Date().getTime(); - if (timeToNextRefresh <= 0) { - refreshButtonPane.setVisible(true); - refreshButtonPane.setManaged(true); - } else { - refreshButtonPane.setVisible(false); - refreshButtonPane.setManaged(false); - timer = UserThread.runAfter(this::activateRefreshButton, timeToNextRefresh, TimeUnit.MILLISECONDS); - } - } - - private void deActivateRefreshButtonTimer() { - if (timer != null) { - timer.stop(); - } - } - - private void onRefreshButton() { - model.dataModel.refreshTradeState(); - activateRefreshButton(); - } - /////////////////////////////////////////////////////////////////////////////////////////// // Info diff --git a/proto/src/main/proto/pb.proto b/proto/src/main/proto/pb.proto index bb4fb827f3f..a81c52bbf62 100644 --- a/proto/src/main/proto/pb.proto +++ b/proto/src/main/proto/pb.proto @@ -76,7 +76,7 @@ message NetworkEnvelope { DepositTxAndDelayedPayoutTxMessage deposit_tx_and_delayed_payout_tx_message = 48; PeerPublishedDelayedPayoutTxMessage peer_published_delayed_payout_tx_message = 49; - RefreshTradeStateRequest refresh_trade_state_request = 50; + RefreshTradeStateRequest refresh_trade_state_request = 50 [deprecated = true]; TraderSignedWitnessMessage trader_signed_witness_message = 51 [deprecated = true]; RequestCancelTradeMessage request_cancel_trade_message = 52; @@ -349,10 +349,11 @@ message CancelTradeRequestRejectedMessage { string uid = 3; } +// Deprecated since v1.3.9 message RefreshTradeStateRequest { - string uid = 1; - string trade_id = 2; - NodeAddress sender_node_address = 3; + string uid = 1 [deprecated = true]; + string trade_id = 2 [deprecated = true]; + NodeAddress sender_node_address = 3 [deprecated = true]; } // Deprecated since v1.3.9 From d53f5ed4ad0976b36a912d0396d7d87a441e6240 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Fri, 11 Sep 2020 12:10:05 -0500 Subject: [PATCH 54/56] Refactor: Rename display strings --- .../resources/i18n/displayStrings.properties | 40 +++++++++---------- .../buyer/BuyersCancelTradePresentation.java | 18 ++++----- .../steps/seller/SellerStep2View.java | 6 +-- .../SellersCancelTradePresentation.java | 14 +++---- 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index 4cbb5970429..87efdf4fa6c 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -910,31 +910,31 @@ portfolio.failed.cantUnfail=This trade cannot be moved back to open trades at th portfolio.failed.depositTxNull=The trade cannot be completed. Deposit transaction is null portfolio.failed.delayedPayoutTxNull=The trade cannot be completed. Delayed payout transaction is null -portfolio.pending.buyer.requestCancelTrade=Cancel trade request -portfolio.pending.buyer.requestCancelTrade.msg=You can send a request to your trading peer for canceling the trade.\n\n\ +portfolio.pending.step2_buyer.requestCancelTrade=Cancel trade request +portfolio.pending.step2_buyer.requestCancelTrade.msg=You can send a request to your trading peer for canceling the trade.\n\n\ If the peer accepts your request you will get back a part of your security deposit. The other part will be given to \ your trading peer as compensation for the lost trade fee, trade opportunity and time.\n\n\ If the peer accepts your cancel request you will get back {0} from your security deposit.\n\n\ Do you want to make a request for cancellation? -portfolio.pending.buyer.request.sent=Cancellation request sent. -portfolio.pending.buyer.request.arrived=Cancellation request arrived. Awaiting peer's response. -portfolio.pending.buyer.request.inMailbox=Request stored in mailbox. Awaiting peer's response. -portfolio.pending.buyer.request.failed=Sending cancellation request failed. Please continue with the payment. -portfolio.pending.buyer.response.accepted=Your cancellation request was accepted by the peer. \ +portfolio.pending.step2_buyer.request.sent=Cancellation request sent. +portfolio.pending.step2_buyer.request.arrived=Cancellation request arrived. Awaiting peer's response. +portfolio.pending.step2_buyer.request.inMailbox=Request stored in mailbox. Awaiting peer's response. +portfolio.pending.step2_buyer.request.failed=Sending cancellation request failed. Please continue with the payment. +portfolio.pending.step2_buyer.response.accepted=Your cancellation request was accepted by the peer. \ The trade is closed and the payout completed.\n\n\ You can review the details of the trade in the 'History' screen. -portfolio.pending.buyer.response.rejected=Cancellation request got rejected. Continue with payment. - - -portfolio.pending.seller.cancelRequest.header=Peer requested for trade cancellation -portfolio.pending.seller.cancelRequest.info=Your peer requested cancellation of the trade. Click the button below for more details. -portfolio.pending.seller.cancelRequest.button=Open cancel trade request details -portfolio.pending.seller.decideLater=Decide later -portfolio.pending.seller.rejectResponse.sent=Reject response sent. -portfolio.pending.seller.rejectResponse.arrived=Reject response arrived. Awaiting that peer continues to send payment. -portfolio.pending.seller.rejectResponse.inMailbox=Reject response stored in mailbox. Awaiting that peer continues to send payment. -portfolio.pending.seller.rejectResponse.failed=Sending reject response failed. Awaiting that peer continues to send payment. -portfolio.pending.seller.receivedCancelTradeRequest.msg=Your trading peer requested cancellation of the trade.\n\n\ +portfolio.pending.step2_buyer.response.rejected=Cancellation request got rejected. Continue with payment. + + +portfolio.pending.step2_seller.cancelRequest.header=Peer requested for trade cancellation +portfolio.pending.step2_seller.cancelRequest.info=Your peer requested cancellation of the trade. Click the button below for more details. +portfolio.pending.step2_seller.cancelRequest.button=Open cancel trade request details +portfolio.pending.step2_seller.decideLater=Decide later +portfolio.pending.step2_seller.rejectResponse.sent=Reject response sent. +portfolio.pending.step2_seller.rejectResponse.arrived=Reject response arrived. Awaiting that peer continues to send payment. +portfolio.pending.step2_seller.rejectResponse.inMailbox=Reject response stored in mailbox. Awaiting that peer continues to send payment. +portfolio.pending.step2_seller.rejectResponse.failed=Sending reject response failed. Awaiting that peer continues to send payment. +portfolio.pending.step2_seller.receivedCancelTradeRequest.msg=Your trading peer requested cancellation of the trade.\n\n\ If you accept you will get back your trade amount, your security deposit and a part of his security deposit as \ compensation for the lost trade fee, trade opportunity and time.\n\n\ Your payout would be:\n\ @@ -946,7 +946,7 @@ portfolio.pending.seller.receivedCancelTradeRequest.msg=Your trading peer reques You can also communicate with the peer via the trader chat to find out about the reason for the cancellation \ request.\n\n\ Do you want to accept the request for cancellation? -portfolio.pending.seller.accepted=You accepted the peer's cancellation request. \ +portfolio.pending.step2_seller.accepted=You accepted the peer's cancellation request. \ The trade is closed and the payout completed.\n\n\ You can review the details of the trade in the 'History' screen. diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyersCancelTradePresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyersCancelTradePresentation.java index 9616c78929d..5b3a78b710e 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyersCancelTradePresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/buyer/BuyersCancelTradePresentation.java @@ -78,7 +78,7 @@ public void initialize(HBox hBox, this.msgSentBusyAnimation = msgSentBusyAnimation; this.msgSentStatusLabel = msgSentStatusLabel; - cancelTradeButton = new AutoTooltipButton(Res.get("portfolio.pending.buyer.requestCancelTrade")); + cancelTradeButton = new AutoTooltipButton(Res.get("portfolio.pending.step2_buyer.requestCancelTrade")); cancelTradeButton.setOnAction(e -> onRequestCancelTrade()); hBox.getChildren().add(1, cancelTradeButton); @@ -112,8 +112,8 @@ public void deactivate() { private void onRequestCancelTrade() { new Popup().width(850) - .headLine(Res.get("portfolio.pending.buyer.requestCancelTrade")) - .attention(Res.get("portfolio.pending.buyer.requestCancelTrade.msg", + .headLine(Res.get("portfolio.pending.step2_buyer.requestCancelTrade")) + .attention(Res.get("portfolio.pending.step2_buyer.requestCancelTrade.msg", formatter.formatCoinWithCode(manager.getSecurityDepositForRequester()))) .onAction(this::doRequestCancelTrade) .actionButtonText(Res.get("shared.yes")) @@ -161,24 +161,24 @@ private void onStateChanged(BuyerTrade.CancelTradeState state) { switch (state) { case REQUEST_MSG_SENT: msgSentBusyAnimation.play(); - msgSentStatusLabel.setText(Res.get("portfolio.pending.buyer.request.sent")); + msgSentStatusLabel.setText(Res.get("portfolio.pending.step2_buyer.request.sent")); break; case REQUEST_MSG_ARRIVED: - msgSentStatusLabel.setText(Res.get("portfolio.pending.buyer.request.arrived")); + msgSentStatusLabel.setText(Res.get("portfolio.pending.step2_buyer.request.arrived")); break; case REQUEST_MSG_IN_MAILBOX: - msgSentStatusLabel.setText(Res.get("portfolio.pending.buyer.request.inMailbox")); + msgSentStatusLabel.setText(Res.get("portfolio.pending.step2_buyer.request.inMailbox")); break; case REQUEST_MSG_SEND_FAILED: - msgSentStatusLabel.setText(Res.get("portfolio.pending.buyer.request.failed")); + msgSentStatusLabel.setText(Res.get("portfolio.pending.step2_buyer.request.failed")); break; case RECEIVED_ACCEPTED_MSG: case PAYOUT_TX_SEEN_IN_NETWORK: - new Popup().information(Res.get("portfolio.pending.buyer.response.accepted")).show(); + new Popup().information(Res.get("portfolio.pending.step2_buyer.response.accepted")).show(); break; case RECEIVED_REJECTED_MSG: - msgSentStatusLabel.setText(Res.get("portfolio.pending.buyer.response.rejected")); + msgSentStatusLabel.setText(Res.get("portfolio.pending.step2_buyer.response.rejected")); break; default: diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java index a82d2c5bbb0..2330fcf0170 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellerStep2View.java @@ -98,13 +98,13 @@ public void deactivate() { private void addCancelRequestBlock() { cancelRequestTitledGroupBg = addTitledGroupBg(gridPane, ++gridRow, 2, - Res.get("portfolio.pending.seller.cancelRequest.header"), Layout.COMPACT_GROUP_DISTANCE); - cancelRequestInfoLabel = addMultilineLabel(gridPane, gridRow, Res.get("portfolio.pending.seller.cancelRequest.info"), + Res.get("portfolio.pending.step2_seller.cancelRequest.header"), Layout.COMPACT_GROUP_DISTANCE); + cancelRequestInfoLabel = addMultilineLabel(gridPane, gridRow, Res.get("portfolio.pending.step2_seller.cancelRequest.info"), Layout.COMPACT_FIRST_ROW_AND_COMPACT_GROUP_DISTANCE); GridPane.setColumnSpan(cancelRequestInfoLabel, 2); cancelRequestTitledGroupBg.getStyleClass().add("last"); titledGroupBg.getStyleClass().remove("last"); - cancelRequestButton = addButtonAfterGroup(gridPane, ++gridRow, Res.get("portfolio.pending.seller.cancelRequest.button")); + cancelRequestButton = addButtonAfterGroup(gridPane, ++gridRow, Res.get("portfolio.pending.step2_seller.cancelRequest.button")); } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java index e88b937e694..be008d35c4d 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java @@ -110,7 +110,7 @@ private void onAcceptRequest() { hideButton(); manager.onAcceptRequest(trade, () -> { - new Popup().information(Res.get("portfolio.pending.seller.accepted")).show(); + new Popup().information(Res.get("portfolio.pending.step2_seller.accepted")).show(); }, errorMessage -> { }); } @@ -167,16 +167,16 @@ private void onStateChanged(SellerTrade.CancelTradeState state) { break; case REQUEST_REJECTED_MSG_SENT: - cancelRequestInfoLabel.setText(Res.get("portfolio.pending.seller.rejectResponse.sent")); + cancelRequestInfoLabel.setText(Res.get("portfolio.pending.step2_seller.rejectResponse.sent")); break; case REQUEST_REJECTED_MSG_ARRIVED: - cancelRequestInfoLabel.setText(Res.get("portfolio.pending.seller.rejectResponse.arrived")); + cancelRequestInfoLabel.setText(Res.get("portfolio.pending.step2_seller.rejectResponse.arrived")); break; case REQUEST_REJECTED_MSG_IN_MAILBOX: - cancelRequestInfoLabel.setText(Res.get("portfolio.pending.seller.rejectResponse.inMailbox")); + cancelRequestInfoLabel.setText(Res.get("portfolio.pending.step2_seller.rejectResponse.inMailbox")); break; case REQUEST_REJECTED_MSG_SEND_FAILED: - cancelRequestInfoLabel.setText(Res.get("portfolio.pending.seller.rejectResponse.failed")); + cancelRequestInfoLabel.setText(Res.get("portfolio.pending.step2_seller.rejectResponse.failed")); break; default: log.error("Unexpected state {}", state); @@ -192,7 +192,7 @@ private void onStateChanged(SellerTrade.CancelTradeState state) { private void showPopup() { if (!trade.isDisputed()) { new Popup().width(850) - .attention(Res.get("portfolio.pending.seller.receivedCancelTradeRequest.msg", + .attention(Res.get("portfolio.pending.step2_seller.receivedCancelTradeRequest.msg", formatter.formatCoinWithCode(trade.getTradeAmount()), formatter.formatCoinWithCode(manager.getDefaultSecDepositOfAcceptingTrader(trade)), formatter.formatCoinWithCode(manager.getLostSecDepositOfRequestingTrader(trade)))) @@ -200,7 +200,7 @@ private void showPopup() { .onAction(this::onAcceptRequest) .secondaryActionButtonText(Res.get("shared.reject")) .onSecondaryAction(this::onRejectRequest) - .closeButtonText(Res.get("portfolio.pending.seller.decideLater")) + .closeButtonText(Res.get("portfolio.pending.step2_seller.decideLater")) .onClose(this::onDecideLater) .show(); } From 1742da30332839a048f2ca38f03bdd0ffe557e75 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Fri, 11 Sep 2020 12:13:12 -0500 Subject: [PATCH 55/56] Refactor: Move display strings --- .../resources/i18n/displayStrings.properties | 84 ++++++++++--------- 1 file changed, 45 insertions(+), 39 deletions(-) diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index 87efdf4fa6c..c3dc1fc0a0c 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -606,6 +606,7 @@ portfolio.pending.step1.warn=The deposit transaction is still not confirmed. Thi portfolio.pending.step1.openForDispute=The deposit transaction is still not confirmed. \ You can wait longer or contact the mediator for assistance. +# Step 2 # suppress inspection "TrailingSpacesInProperty" portfolio.pending.step2.confReached=Your trade has reached at least one blockchain confirmation.\n(You can wait for more confirmations if you want - 6 confirmations are considered as very secure.)\n\n @@ -675,6 +676,23 @@ portfolio.pending.step2_buyer.confirmStart.proof.noneProvided=You have not enter See more details on the Bisq wiki: https://bisq.wiki/Trading_Monero#Auto-confirming_trades portfolio.pending.step2_buyer.confirmStart.proof.invalidInput=Input is not a 32 byte hexadecimal value portfolio.pending.step2_buyer.confirmStart.warningButton=Ignore and continue anyway + +# Cancel trade +portfolio.pending.step2_buyer.requestCancelTrade=Cancel trade request +portfolio.pending.step2_buyer.requestCancelTrade.msg=You can send a request to your trading peer for canceling the trade.\n\n\ + If the peer accepts your request you will get back a part of your security deposit. The other part will be given to \ + your trading peer as compensation for the lost trade fee, trade opportunity and time.\n\n\ + If the peer accepts your cancel request you will get back {0} from your security deposit.\n\n\ + Do you want to make a request for cancellation? +portfolio.pending.step2_buyer.request.sent=Cancellation request sent. +portfolio.pending.step2_buyer.request.arrived=Cancellation request arrived. Awaiting peer's response. +portfolio.pending.step2_buyer.request.inMailbox=Request stored in mailbox. Awaiting peer's response. +portfolio.pending.step2_buyer.request.failed=Sending cancellation request failed. Please continue with the payment. +portfolio.pending.step2_buyer.response.accepted=Your cancellation request was accepted by the peer. \ + The trade is closed and the payout completed.\n\n\ + You can review the details of the trade in the 'History' screen. +portfolio.pending.step2_buyer.response.rejected=Cancellation request got rejected. Continue with payment. + portfolio.pending.step2_seller.waitPayment.headline=Wait for payment portfolio.pending.step2_seller.f2fInfo.headline=Buyer's contact information portfolio.pending.step2_seller.waitPayment.msg=The deposit transaction has at least one blockchain confirmation.\nYou need to wait until the BTC buyer starts the {0} payment. @@ -683,6 +701,33 @@ portfolio.pending.step2_seller.openForDispute=The BTC buyer has not started thei portfolio.pending.step2_seller.refresh=Refresh Trade State portfolio.pending.step2_seller.refreshInfo=Sometimes P2P network messages acknowledging payment are not delivered, \ causing trades to get stuck. Hit the button below to make your peer resend the last message. + +# Cancel trade +portfolio.pending.step2_seller.cancelRequest.header=Peer requested for trade cancellation +portfolio.pending.step2_seller.cancelRequest.info=Your peer requested cancellation of the trade. Click the button below for more details. +portfolio.pending.step2_seller.cancelRequest.button=Open cancel trade request details +portfolio.pending.step2_seller.decideLater=Decide later +portfolio.pending.step2_seller.rejectResponse.sent=Reject response sent. +portfolio.pending.step2_seller.rejectResponse.arrived=Reject response arrived. Awaiting that peer continues to send payment. +portfolio.pending.step2_seller.rejectResponse.inMailbox=Reject response stored in mailbox. Awaiting that peer continues to send payment. +portfolio.pending.step2_seller.rejectResponse.failed=Sending reject response failed. Awaiting that peer continues to send payment. +portfolio.pending.step2_seller.receivedCancelTradeRequest.msg=Your trading peer requested cancellation of the trade.\n\n\ + If you accept you will get back your trade amount, your security deposit and a part of his security deposit as \ + compensation for the lost trade fee, trade opportunity and time.\n\n\ + Your payout would be:\n\ + - Trade amount: {0}\n\ + - Your security deposit: {1}\n\ + - Part of the peer''s security deposit: {2}\n\n\ + If you prefer to continue the trade, reject the peer''s cancel request. If the peer does not complete the trade \ + can open a dispute once the trade period is over.\n\n\ + You can also communicate with the peer via the trader chat to find out about the reason for the cancellation \ + request.\n\n\ + Do you want to accept the request for cancellation? +portfolio.pending.step2_seller.accepted=You accepted the peer's cancellation request. \ + The trade is closed and the payout completed.\n\n\ + You can review the details of the trade in the 'History' screen. + +# Trader chat tradeChat.chatWindowTitle=Chat window for trade with ID ''{0}'' tradeChat.openChat=Open chat window tradeChat.rules=You can communicate with your trade peer to resolve potential problems with this trade.\n\ @@ -910,45 +955,6 @@ portfolio.failed.cantUnfail=This trade cannot be moved back to open trades at th portfolio.failed.depositTxNull=The trade cannot be completed. Deposit transaction is null portfolio.failed.delayedPayoutTxNull=The trade cannot be completed. Delayed payout transaction is null -portfolio.pending.step2_buyer.requestCancelTrade=Cancel trade request -portfolio.pending.step2_buyer.requestCancelTrade.msg=You can send a request to your trading peer for canceling the trade.\n\n\ - If the peer accepts your request you will get back a part of your security deposit. The other part will be given to \ - your trading peer as compensation for the lost trade fee, trade opportunity and time.\n\n\ - If the peer accepts your cancel request you will get back {0} from your security deposit.\n\n\ - Do you want to make a request for cancellation? -portfolio.pending.step2_buyer.request.sent=Cancellation request sent. -portfolio.pending.step2_buyer.request.arrived=Cancellation request arrived. Awaiting peer's response. -portfolio.pending.step2_buyer.request.inMailbox=Request stored in mailbox. Awaiting peer's response. -portfolio.pending.step2_buyer.request.failed=Sending cancellation request failed. Please continue with the payment. -portfolio.pending.step2_buyer.response.accepted=Your cancellation request was accepted by the peer. \ - The trade is closed and the payout completed.\n\n\ - You can review the details of the trade in the 'History' screen. -portfolio.pending.step2_buyer.response.rejected=Cancellation request got rejected. Continue with payment. - - -portfolio.pending.step2_seller.cancelRequest.header=Peer requested for trade cancellation -portfolio.pending.step2_seller.cancelRequest.info=Your peer requested cancellation of the trade. Click the button below for more details. -portfolio.pending.step2_seller.cancelRequest.button=Open cancel trade request details -portfolio.pending.step2_seller.decideLater=Decide later -portfolio.pending.step2_seller.rejectResponse.sent=Reject response sent. -portfolio.pending.step2_seller.rejectResponse.arrived=Reject response arrived. Awaiting that peer continues to send payment. -portfolio.pending.step2_seller.rejectResponse.inMailbox=Reject response stored in mailbox. Awaiting that peer continues to send payment. -portfolio.pending.step2_seller.rejectResponse.failed=Sending reject response failed. Awaiting that peer continues to send payment. -portfolio.pending.step2_seller.receivedCancelTradeRequest.msg=Your trading peer requested cancellation of the trade.\n\n\ - If you accept you will get back your trade amount, your security deposit and a part of his security deposit as \ - compensation for the lost trade fee, trade opportunity and time.\n\n\ - Your payout would be:\n\ - - Trade amount: {0}\n\ - - Your security deposit: {1}\n\ - - Part of the peer''s security deposit: {2}\n\n\ - If you prefer to continue the trade, reject the peer''s cancel request. If the peer does not complete the trade \ - can open a dispute once the trade period is over.\n\n\ - You can also communicate with the peer via the trader chat to find out about the reason for the cancellation \ - request.\n\n\ - Do you want to accept the request for cancellation? -portfolio.pending.step2_seller.accepted=You accepted the peer's cancellation request. \ - The trade is closed and the payout completed.\n\n\ - You can review the details of the trade in the 'History' screen. #################################################################### # Funds From 71e452f75d694a28d0a0e85c478682776ffd2caf Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 16 Sep 2020 20:24:44 -0500 Subject: [PATCH 56/56] Apply suggestions from code review. Add todos for required changes --- .../main/java/bisq/core/btc/wallet/TradeWalletService.java | 5 ++++- core/src/main/java/bisq/core/trade/BuyerTrade.java | 2 +- core/src/main/java/bisq/core/trade/SellerTrade.java | 2 +- core/src/main/java/bisq/core/trade/Trade.java | 2 +- .../bisq/core/trade/protocol/BuyersCancelTradeProtocol.java | 1 + .../main/portfolio/closedtrades/ClosedTradesViewModel.java | 2 +- .../steps/seller/SellersCancelTradePresentation.java | 2 +- proto/src/main/proto/pb.proto | 4 ++-- 8 files changed, 12 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java b/core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java index 0fe16426d1a..ff6264fc243 100644 --- a/core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java +++ b/core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java @@ -836,6 +836,7 @@ public Transaction sellerSignsAndFinalizesPayoutTx(Transaction depositTx, // Canceled trade payoutTx /////////////////////////////////////////////////////////////////////////////////////////// + //TODO avoid code duplication public byte[] signCanceledTradePayoutTx(Transaction depositTx, Coin buyerPayoutAmount, Coin sellerPayoutAmount, @@ -845,7 +846,8 @@ public byte[] signCanceledTradePayoutTx(Transaction depositTx, byte[] buyerPubKey, byte[] sellerPubKey) throws AddressFormatException, TransactionVerificationException { - Transaction preparedPayoutTx = createPayoutTx(depositTx, buyerPayoutAmount, sellerPayoutAmount, buyerPayoutAddressString, sellerPayoutAddressString); + Transaction preparedPayoutTx = createPayoutTx(depositTx, buyerPayoutAmount, sellerPayoutAmount, + buyerPayoutAddressString, sellerPayoutAddressString); // MS redeemScript Script redeemScript = get2of2MultiSigRedeemScript(buyerPubKey, sellerPubKey); // MS output from prev. tx is index 0 @@ -860,6 +862,7 @@ public byte[] signCanceledTradePayoutTx(Transaction depositTx, return mySignature.encodeToDER(); } + //TODO avoid code duplication public Transaction finalizeCanceledTradePayoutTx(Transaction depositTx, byte[] buyerSignature, byte[] sellerSignature, diff --git a/core/src/main/java/bisq/core/trade/BuyerTrade.java b/core/src/main/java/bisq/core/trade/BuyerTrade.java index c58063bfeac..ccf9099f795 100644 --- a/core/src/main/java/bisq/core/trade/BuyerTrade.java +++ b/core/src/main/java/bisq/core/trade/BuyerTrade.java @@ -160,7 +160,7 @@ public Coin getPayoutAmount() { } @Override - public boolean wasCanceledTrade() { + public boolean isCanceled() { if (cancelTradeState == null) { return false; } diff --git a/core/src/main/java/bisq/core/trade/SellerTrade.java b/core/src/main/java/bisq/core/trade/SellerTrade.java index cd5ad3e8840..ecc46888721 100644 --- a/core/src/main/java/bisq/core/trade/SellerTrade.java +++ b/core/src/main/java/bisq/core/trade/SellerTrade.java @@ -162,7 +162,7 @@ public Coin getPayoutAmount() { } @Override - public boolean wasCanceledTrade() { + public boolean isCanceled() { if (cancelTradeState == null) { return false; } diff --git a/core/src/main/java/bisq/core/trade/Trade.java b/core/src/main/java/bisq/core/trade/Trade.java index 110193a276d..d0a93f62eb1 100644 --- a/core/src/main/java/bisq/core/trade/Trade.java +++ b/core/src/main/java/bisq/core/trade/Trade.java @@ -801,7 +801,7 @@ public void onComplete() { public abstract Coin getPayoutAmount(); - public abstract boolean wasCanceledTrade(); + public abstract boolean isCanceled(); /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/core/src/main/java/bisq/core/trade/protocol/BuyersCancelTradeProtocol.java b/core/src/main/java/bisq/core/trade/protocol/BuyersCancelTradeProtocol.java index 384abeceeba..cdcaa048d88 100644 --- a/core/src/main/java/bisq/core/trade/protocol/BuyersCancelTradeProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/BuyersCancelTradeProtocol.java @@ -64,6 +64,7 @@ public void onRequestCancelTrade(ResultHandler resultHandler, ErrorMessageHandle }); taskRunner.addTasks( ApplyFilter.class, + //TODO we must not sent the sig at that moment! SignCanceledTradePayoutTx.class, SendRequestCancelTradeMessage.class, SetupCanceledTradePayoutTxListener.class diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/closedtrades/ClosedTradesViewModel.java b/desktop/src/main/java/bisq/desktop/main/portfolio/closedtrades/ClosedTradesViewModel.java index bc20ef3a054..6d5496bfec3 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/closedtrades/ClosedTradesViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/closedtrades/ClosedTradesViewModel.java @@ -148,7 +148,7 @@ String getState(ClosedTradableListItem item) { Trade trade = (Trade) item.getTradable(); if (trade.isWithdrawn() || trade.isPayoutPublished()) { - if (trade.wasCanceledTrade()) { + if (trade.isCanceled()) { return Res.get("portfolio.closed.canceled"); } else { return Res.get("portfolio.closed.completed"); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java index be008d35c4d..8c05cd07904 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/pendingtrades/steps/seller/SellersCancelTradePresentation.java @@ -139,7 +139,7 @@ private void onDisputeStateChanged() { } private void onStateChanged(SellerTrade.CancelTradeState state) { - log.error("onStateChanged {} for trade {}", state, trade.getShortId()); + log.info("onStateChanged {} for trade {}", state, trade.getShortId()); if (state == null) { hideAll(); hideButton(); diff --git a/proto/src/main/proto/pb.proto b/proto/src/main/proto/pb.proto index a81c52bbf62..5a7546fc303 100644 --- a/proto/src/main/proto/pb.proto +++ b/proto/src/main/proto/pb.proto @@ -332,8 +332,8 @@ message MediatedPayoutTxSignatureMessage { message RequestCancelTradeMessage { string uid = 1; - string trade_id = 3; - bytes tx_signature = 2; + string trade_id = 2; + bytes tx_signature = 3; NodeAddress sender_node_address = 4; }