Use a checkArgument to ensure that the methods are not called once a

dispute has been opened. This will cause a Runtime exception but that
is justified as the caller need to ensure to do the check and do not
allow to get to that point.
This commit is contained in:
chimp1984 2020-09-06 23:22:31 -05:00 committed by Christoph Atteneder
parent 35cd7ac56b
commit f566e0975e
No known key found for this signature in database
GPG Key ID: CD5DC1C529CDFD3B
5 changed files with 16 additions and 20 deletions

View File

@ -55,6 +55,8 @@ import bisq.common.handlers.ResultHandler;
import lombok.extern.slf4j.Slf4j;
import static com.google.common.base.Preconditions.checkArgument;
@Slf4j
public class BuyerAsMakerProtocol extends TradeProtocol implements BuyerProtocol, MakerProtocol {
private final BuyerAsMakerTrade buyerAsMakerTrade;
@ -212,9 +214,8 @@ public class BuyerAsMakerProtocol extends TradeProtocol implements BuyerProtocol
// User clicked the "bank transfer started" button
@Override
public void onFiatPaymentStarted(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
if (wasDisputed(errorMessageHandler)) {
return;
}
checkArgument(!wasDisputed(), "A call to onFiatPaymentStarted is not permitted once a " +
"dispute has been opened.");
if (trade.isDepositConfirmed() && !trade.isFiatSent()) {
buyerAsMakerTrade.setState(Trade.State.BUYER_CONFIRMED_IN_UI_FIAT_PAYMENT_INITIATED);

View File

@ -59,6 +59,7 @@ import bisq.common.handlers.ResultHandler;
import lombok.extern.slf4j.Slf4j;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
@Slf4j
@ -237,9 +238,8 @@ public class BuyerAsTakerProtocol extends TradeProtocol implements BuyerProtocol
// User clicked the "bank transfer started" button
@Override
public void onFiatPaymentStarted(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
if (wasDisputed(errorMessageHandler)) {
return;
}
checkArgument(!wasDisputed(), "A call to onFiatPaymentStarted is not permitted once a " +
"dispute has been opened.");
if (!trade.isFiatSent()) {
buyerAsTakerTrade.setState(Trade.State.BUYER_CONFIRMED_IN_UI_FIAT_PAYMENT_INITIATED);

View File

@ -57,6 +57,8 @@ import bisq.common.handlers.ResultHandler;
import lombok.extern.slf4j.Slf4j;
import static com.google.common.base.Preconditions.checkArgument;
@Slf4j
public class SellerAsMakerProtocol extends TradeProtocol implements SellerProtocol, MakerProtocol {
private final SellerAsMakerTrade sellerAsMakerTrade;
@ -204,9 +206,8 @@ public class SellerAsMakerProtocol extends TradeProtocol implements SellerProtoc
// User clicked the "bank transfer received" button, so we release the funds for payout
@Override
public void onFiatPaymentReceived(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
if (wasDisputed(errorMessageHandler)) {
return;
}
checkArgument(!wasDisputed(), "A call to onFiatPaymentReceived is not permitted once a " +
"dispute has been opened.");
if (trade.getPayoutTx() == null) {
sellerAsMakerTrade.setState(Trade.State.SELLER_CONFIRMED_IN_UI_FIAT_PAYMENT_RECEIPT);

View File

@ -56,6 +56,7 @@ import bisq.common.handlers.ResultHandler;
import lombok.extern.slf4j.Slf4j;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
@Slf4j
@ -196,9 +197,8 @@ public class SellerAsTakerProtocol extends TradeProtocol implements SellerProtoc
// User clicked the "bank transfer received" button, so we release the funds for payout
@Override
public void onFiatPaymentReceived(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
if (wasDisputed(errorMessageHandler)) {
return;
}
checkArgument(!wasDisputed(), "A call to onFiatPaymentReceived is not permitted once a " +
"dispute has been opened.");
if (trade.getPayoutTx() == null) {
sellerAsTakerTrade.setState(Trade.State.SELLER_CONFIRMED_IN_UI_FIAT_PAYMENT_RECEIPT);

View File

@ -345,14 +345,8 @@ public abstract class TradeProtocol {
cleanup();
}
protected boolean wasDisputed(ErrorMessageHandler errorMessageHandler) {
if (trade.getDisputeState() != Trade.DisputeState.NO_DISPUTE) {
String msg = "Dispute have been opened once. We do not allow anymore to confirm payment by button click.";
log.error(msg);
errorMessageHandler.handleErrorMessage(msg);
return true;
}
return false;
protected boolean wasDisputed() {
return trade.getDisputeState() != Trade.DisputeState.NO_DISPUTE;
}
private void sendAckMessage(@Nullable TradeMessage tradeMessage, boolean result, @Nullable String errorMessage) {