mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-20 02:12:00 +01:00
Handle backward compatibility with new arbitration selection model.
This commit is contained in:
parent
d98f3c12cf
commit
1ba0402dfb
@ -19,6 +19,7 @@ package bisq.core.offer.availability;
|
||||
|
||||
import bisq.core.offer.Offer;
|
||||
import bisq.core.offer.messages.OfferAvailabilityResponse;
|
||||
import bisq.core.user.User;
|
||||
|
||||
import bisq.network.p2p.NodeAddress;
|
||||
import bisq.network.p2p.P2PService;
|
||||
@ -38,7 +39,8 @@ public class OfferAvailabilityModel implements Model {
|
||||
private final PubKeyRing pubKeyRing; // takers PubKey (my pubkey)
|
||||
@Getter
|
||||
private final P2PService p2PService;
|
||||
|
||||
@Getter
|
||||
final private User user;
|
||||
private NodeAddress peerNodeAddress; // maker
|
||||
private OfferAvailabilityResponse message;
|
||||
@Nullable
|
||||
@ -48,10 +50,12 @@ public class OfferAvailabilityModel implements Model {
|
||||
|
||||
public OfferAvailabilityModel(Offer offer,
|
||||
PubKeyRing pubKeyRing,
|
||||
P2PService p2PService) {
|
||||
P2PService p2PService,
|
||||
User user) {
|
||||
this.offer = offer;
|
||||
this.pubKeyRing = pubKeyRing;
|
||||
this.p2PService = p2PService;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public NodeAddress getPeerNodeAddress() {
|
||||
|
@ -22,12 +22,20 @@ import bisq.core.offer.Offer;
|
||||
import bisq.core.offer.availability.ArbitratorSelection;
|
||||
import bisq.core.offer.availability.OfferAvailabilityModel;
|
||||
import bisq.core.offer.messages.OfferAvailabilityResponse;
|
||||
import bisq.core.trade.protocol.ArbitratorSelectionRule;
|
||||
|
||||
import bisq.network.p2p.NodeAddress;
|
||||
|
||||
import bisq.common.taskrunner.Task;
|
||||
import bisq.common.taskrunner.TaskRunner;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class ProcessOfferAvailabilityResponse extends Task<OfferAvailabilityModel> {
|
||||
public ProcessOfferAvailabilityResponse(TaskRunner taskHandler, OfferAvailabilityModel model) {
|
||||
super(taskHandler, model);
|
||||
@ -35,29 +43,44 @@ public class ProcessOfferAvailabilityResponse extends Task<OfferAvailabilityMode
|
||||
|
||||
@Override
|
||||
protected void run() {
|
||||
Offer offer = model.getOffer();
|
||||
try {
|
||||
runInterceptHook();
|
||||
OfferAvailabilityResponse offerAvailabilityResponse = model.getMessage();
|
||||
|
||||
if (model.getOffer().getState() != Offer.State.REMOVED) {
|
||||
if (offer.getState() != Offer.State.REMOVED) {
|
||||
if (offerAvailabilityResponse.getAvailabilityResult() == AvailabilityResult.AVAILABLE) {
|
||||
model.getOffer().setState(Offer.State.AVAILABLE);
|
||||
offer.setState(Offer.State.AVAILABLE);
|
||||
if (ArbitratorSelection.isNewRuleActivated()) {
|
||||
NodeAddress selectedArbitrator = offerAvailabilityResponse.getArbitrator();
|
||||
if (selectedArbitrator == null)
|
||||
failed("You cannot take that offer because the offer maker is running an incompatible version.");
|
||||
else
|
||||
if (selectedArbitrator == null) {
|
||||
log.debug("Maker is on old version and does not send the selected arbitrator in the offerAvailabilityResponse. " +
|
||||
"We use the old selection model instead with the supported arbitrators of the offers");
|
||||
List<NodeAddress> acceptedArbitratorAddresses = model.getUser().getAcceptedArbitratorAddresses();
|
||||
log.error("acceptedArbitratorAddresses " + acceptedArbitratorAddresses);
|
||||
if (acceptedArbitratorAddresses != null) {
|
||||
try {
|
||||
model.setSelectedArbitrator(ArbitratorSelectionRule.select(Lists.newArrayList(acceptedArbitratorAddresses), offer));
|
||||
} catch (Throwable t) {
|
||||
failed("There is no arbitrator matching that offer. The maker has " +
|
||||
"not updated to the latest version and the arbitrators selected for that offer are not available anymore.");
|
||||
}
|
||||
} else {
|
||||
failed("There is no arbitrator available.");
|
||||
}
|
||||
} else {
|
||||
model.setSelectedArbitrator(selectedArbitrator);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
model.getOffer().setState(Offer.State.NOT_AVAILABLE);
|
||||
offer.setState(Offer.State.NOT_AVAILABLE);
|
||||
failed("Take offer attempt rejected because of: " + offerAvailabilityResponse.getAvailabilityResult());
|
||||
}
|
||||
}
|
||||
|
||||
complete();
|
||||
} catch (Throwable t) {
|
||||
model.getOffer().setErrorMessage("An error occurred.\n" +
|
||||
offer.setErrorMessage("An error occurred.\n" +
|
||||
"Error message:\n"
|
||||
+ t.getMessage());
|
||||
|
||||
|
@ -473,7 +473,8 @@ public class TradeManager implements PersistedDataHost {
|
||||
return new OfferAvailabilityModel(
|
||||
offer,
|
||||
keyRing.getPubKeyRing(),
|
||||
p2PService);
|
||||
p2PService,
|
||||
user);
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,8 +35,11 @@ import bisq.core.locale.Res;
|
||||
import bisq.core.locale.TradeCurrency;
|
||||
import bisq.core.offer.Offer;
|
||||
import bisq.core.offer.OfferPayload;
|
||||
import bisq.core.offer.availability.ArbitratorSelection;
|
||||
import bisq.core.user.Preferences;
|
||||
|
||||
import bisq.network.p2p.NodeAddress;
|
||||
|
||||
import javafx.scene.control.Tab;
|
||||
import javafx.scene.control.TabPane;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
@ -164,7 +167,8 @@ public abstract class OfferView extends ActivatableView<TabPane, Void> {
|
||||
@Override
|
||||
public void onCreateOffer(TradeCurrency tradeCurrency) {
|
||||
if (!createOfferViewOpen) {
|
||||
if (!arbitratorManager.isArbitratorAvailableForLanguage(preferences.getUserLanguage())) {
|
||||
boolean arbitratorAvailableForLanguage = arbitratorManager.isArbitratorAvailableForLanguage(preferences.getUserLanguage());
|
||||
if (!arbitratorAvailableForLanguage) {
|
||||
showNoArbitratorForUserLocaleWarning();
|
||||
}
|
||||
openCreateOffer(tradeCurrency);
|
||||
@ -177,11 +181,28 @@ public abstract class OfferView extends ActivatableView<TabPane, Void> {
|
||||
@Override
|
||||
public void onTakeOffer(Offer offer) {
|
||||
if (!takeOfferViewOpen) {
|
||||
if (!arbitratorManager.getArbitratorLanguages(offer.getArbitratorNodeAddresses()).stream()
|
||||
.anyMatch(languages -> languages.equals(preferences.getUserLanguage()))) {
|
||||
showNoArbitratorForUserLocaleWarning();
|
||||
if (ArbitratorSelection.isNewRuleActivated()) {
|
||||
openTakeOffer(offer);
|
||||
} else {
|
||||
List<NodeAddress> arbitratorNodeAddresses = offer.getArbitratorNodeAddresses();
|
||||
List<String> arbitratorLanguages = arbitratorManager.getArbitratorLanguages(arbitratorNodeAddresses);
|
||||
if (!arbitratorLanguages.isEmpty()) {
|
||||
if (arbitratorLanguages.stream()
|
||||
.noneMatch(languages -> languages.equals(preferences.getUserLanguage()))) {
|
||||
showNoArbitratorForUserLocaleWarning();
|
||||
}
|
||||
openTakeOffer(offer);
|
||||
} else {
|
||||
// No need to translate that as this should only be a very temporary issue after 0.9 release.
|
||||
String message = "There is no arbitrator available matching the offer's " +
|
||||
"supported arbitrators list. That might happen if the arbitrators of the offer have " +
|
||||
"revoked and the maker has not updated to version 0.9.";
|
||||
log.warn(message + " offer.getArbitratorNodeAddresses()={}", arbitratorNodeAddresses);
|
||||
new Popup<>().warning(message)
|
||||
.closeButtonText(Res.get("shared.ok"))
|
||||
.show();
|
||||
}
|
||||
}
|
||||
openTakeOffer(offer);
|
||||
} else {
|
||||
log.error("You have already a \"Take offer\" tab open.");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user