do not allow arbitrators to open disputes

This commit is contained in:
woodser 2024-08-01 16:58:45 -04:00
parent 9004c7f32a
commit 00ceeeba5f
2 changed files with 33 additions and 2 deletions

View File

@ -332,7 +332,15 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
// get trade // get trade
Trade trade = tradeManager.getTrade(dispute.getTradeId()); Trade trade = tradeManager.getTrade(dispute.getTradeId());
if (trade == null) { if (trade == null) {
log.warn("Dispute trade {} does not exist", dispute.getTradeId()); String errorMsg = "Dispute trade does not exist, tradeId=" + dispute.getTradeId();
faultHandler.handleFault(errorMsg, new IllegalStateException(errorMsg));
return;
}
// arbitrator cannot open disputes
if (trade.isArbitrator()) {
String errorMsg = "Arbitrators cannot open disputes.";
faultHandler.handleFault(errorMsg, new IllegalStateException(errorMsg));
return; return;
} }

View File

@ -87,9 +87,11 @@ import monero.wallet.model.MoneroTxWallet;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
@ -168,7 +170,28 @@ public final class ArbitrationManager extends DisputeManager<ArbitrationDisputeL
@Override @Override
public void cleanupDisputes() { public void cleanupDisputes() {
// no action
// remove disputes opened by arbitrator, which is not allowed
Set<Dispute> toRemoves = new HashSet<>();
List<Dispute> disputes = getDisputeList().getList();
for (Dispute dispute : disputes) {
// get dispute's trade
final Trade trade = tradeManager.getTrade(dispute.getTradeId());
if (trade == null) {
log.warn("Dispute trade {} does not exist", dispute.getTradeId());
return;
}
// collect dispute if owned by arbitrator
if (dispute.getTraderPubKeyRing().equals(trade.getArbitrator().getPubKeyRing())) {
toRemoves.add(dispute);
}
}
for (Dispute toRemove : toRemoves) {
log.warn("Removing invalid dispute opened by arbitrator, disputeId={}", toRemove.getTradeId(), toRemove.getId());
getDisputeList().remove(toRemove);
}
} }
@Override @Override