From 66a152c8889c16bcad2ad8c826f0cb141ec30089 Mon Sep 17 00:00:00 2001 From: woodser Date: Thu, 14 Dec 2023 12:02:44 -0500 Subject: [PATCH] close open dispute on preparing payment received message --- core/src/main/java/haveno/core/trade/Trade.java | 6 +++++- .../tasks/ProcessPaymentReceivedMessage.java | 14 +++++++------- .../tasks/SellerPreparePaymentReceivedMessage.java | 7 +++++++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/haveno/core/trade/Trade.java b/core/src/main/java/haveno/core/trade/Trade.java index 32d9542d50..c2d8a8061e 100644 --- a/core/src/main/java/haveno/core/trade/Trade.java +++ b/core/src/main/java/haveno/core/trade/Trade.java @@ -1342,7 +1342,7 @@ public abstract class Trade implements Tradable, Model { for (Dispute dispute : getDisputes()) dispute.setDisputePayoutTxId(payoutTxId); // set final payout amounts - if (getDisputeState().isNotDisputed()) { + if (hasPaymentReceivedMessage()) { // TODO: replace with isPaymentReceived() but only if correct when trade completes with dispute BigInteger splitTxFee = payoutTx.getFee().divide(BigInteger.valueOf(2)); getBuyer().setPayoutTxFee(splitTxFee); getSeller().setPayoutTxFee(splitTxFee); @@ -1614,6 +1614,10 @@ public abstract class Trade implements Tradable, Model { return getState().getPhase().ordinal() >= Phase.PAYMENT_SENT.ordinal(); } + public boolean hasPaymentReceivedMessage() { + return (isSeller() ? getBuyer() : getSeller()).getPaymentReceivedMessage() != null; // seller stores message to buyer and arbitrator, peers store message from seller + } + public boolean isPaymentReceived() { return getState().getPhase().ordinal() >= Phase.PAYMENT_RECEIVED.ordinal(); } diff --git a/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessPaymentReceivedMessage.java b/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessPaymentReceivedMessage.java index b54febab9b..77eda0a1b6 100644 --- a/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessPaymentReceivedMessage.java +++ b/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessPaymentReceivedMessage.java @@ -78,17 +78,17 @@ public class ProcessPaymentReceivedMessage extends TradeTask { } trade.requestPersistence(); - // close open disputes - if (trade.getDisputeState().ordinal() >= Trade.DisputeState.DISPUTE_REQUESTED.ordinal()) { - trade.advanceDisputeState(Trade.DisputeState.DISPUTE_CLOSED); - for (Dispute dispute : trade.getDisputes()) { - dispute.setIsClosed(); - } - } // process payout tx unless already unlocked if (!trade.isPayoutUnlocked()) processPayoutTx(message); + // close open disputes + if (trade.isPayoutPublished() && trade.getDisputeState().ordinal() >= Trade.DisputeState.DISPUTE_REQUESTED.ordinal()) { + trade.advanceDisputeState(Trade.DisputeState.DISPUTE_CLOSED); + for (Dispute dispute : trade.getDisputes()) dispute.setIsClosed(); + } + + // publish signed witness SignedWitness signedWitness = message.getBuyerSignedWitness(); if (signedWitness != null && trade instanceof BuyerTrade) { // We received the signedWitness from the seller and publish the data to the network. diff --git a/core/src/main/java/haveno/core/trade/protocol/tasks/SellerPreparePaymentReceivedMessage.java b/core/src/main/java/haveno/core/trade/protocol/tasks/SellerPreparePaymentReceivedMessage.java index a4d8bb728a..98d2af9d78 100644 --- a/core/src/main/java/haveno/core/trade/protocol/tasks/SellerPreparePaymentReceivedMessage.java +++ b/core/src/main/java/haveno/core/trade/protocol/tasks/SellerPreparePaymentReceivedMessage.java @@ -18,6 +18,7 @@ package haveno.core.trade.protocol.tasks; import haveno.common.taskrunner.TaskRunner; +import haveno.core.support.dispute.Dispute; import haveno.core.trade.Trade; import lombok.extern.slf4j.Slf4j; import monero.wallet.model.MoneroTxWallet; @@ -63,6 +64,12 @@ public class SellerPreparePaymentReceivedMessage extends TradeTask { trade.processPayoutTx(trade.getArbitrator().getPaymentReceivedMessage().getSignedPayoutTxHex(), false, true); } + // close open disputes + if (trade.isPayoutPublished() && trade.getDisputeState().ordinal() >= Trade.DisputeState.DISPUTE_REQUESTED.ordinal()) { + trade.advanceDisputeState(Trade.DisputeState.DISPUTE_CLOSED); + for (Dispute dispute : trade.getDisputes()) dispute.setIsClosed(); + } + processModel.getTradeManager().requestPersistence(); complete(); } catch (Throwable t) {