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.Offer;
|
||||||
import bisq.core.offer.messages.OfferAvailabilityResponse;
|
import bisq.core.offer.messages.OfferAvailabilityResponse;
|
||||||
|
import bisq.core.user.User;
|
||||||
|
|
||||||
import bisq.network.p2p.NodeAddress;
|
import bisq.network.p2p.NodeAddress;
|
||||||
import bisq.network.p2p.P2PService;
|
import bisq.network.p2p.P2PService;
|
||||||
@ -38,7 +39,8 @@ public class OfferAvailabilityModel implements Model {
|
|||||||
private final PubKeyRing pubKeyRing; // takers PubKey (my pubkey)
|
private final PubKeyRing pubKeyRing; // takers PubKey (my pubkey)
|
||||||
@Getter
|
@Getter
|
||||||
private final P2PService p2PService;
|
private final P2PService p2PService;
|
||||||
|
@Getter
|
||||||
|
final private User user;
|
||||||
private NodeAddress peerNodeAddress; // maker
|
private NodeAddress peerNodeAddress; // maker
|
||||||
private OfferAvailabilityResponse message;
|
private OfferAvailabilityResponse message;
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -48,10 +50,12 @@ public class OfferAvailabilityModel implements Model {
|
|||||||
|
|
||||||
public OfferAvailabilityModel(Offer offer,
|
public OfferAvailabilityModel(Offer offer,
|
||||||
PubKeyRing pubKeyRing,
|
PubKeyRing pubKeyRing,
|
||||||
P2PService p2PService) {
|
P2PService p2PService,
|
||||||
|
User user) {
|
||||||
this.offer = offer;
|
this.offer = offer;
|
||||||
this.pubKeyRing = pubKeyRing;
|
this.pubKeyRing = pubKeyRing;
|
||||||
this.p2PService = p2PService;
|
this.p2PService = p2PService;
|
||||||
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NodeAddress getPeerNodeAddress() {
|
public NodeAddress getPeerNodeAddress() {
|
||||||
|
@ -22,12 +22,20 @@ import bisq.core.offer.Offer;
|
|||||||
import bisq.core.offer.availability.ArbitratorSelection;
|
import bisq.core.offer.availability.ArbitratorSelection;
|
||||||
import bisq.core.offer.availability.OfferAvailabilityModel;
|
import bisq.core.offer.availability.OfferAvailabilityModel;
|
||||||
import bisq.core.offer.messages.OfferAvailabilityResponse;
|
import bisq.core.offer.messages.OfferAvailabilityResponse;
|
||||||
|
import bisq.core.trade.protocol.ArbitratorSelectionRule;
|
||||||
|
|
||||||
import bisq.network.p2p.NodeAddress;
|
import bisq.network.p2p.NodeAddress;
|
||||||
|
|
||||||
import bisq.common.taskrunner.Task;
|
import bisq.common.taskrunner.Task;
|
||||||
import bisq.common.taskrunner.TaskRunner;
|
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 class ProcessOfferAvailabilityResponse extends Task<OfferAvailabilityModel> {
|
||||||
public ProcessOfferAvailabilityResponse(TaskRunner taskHandler, OfferAvailabilityModel model) {
|
public ProcessOfferAvailabilityResponse(TaskRunner taskHandler, OfferAvailabilityModel model) {
|
||||||
super(taskHandler, model);
|
super(taskHandler, model);
|
||||||
@ -35,29 +43,44 @@ public class ProcessOfferAvailabilityResponse extends Task<OfferAvailabilityMode
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void run() {
|
protected void run() {
|
||||||
|
Offer offer = model.getOffer();
|
||||||
try {
|
try {
|
||||||
runInterceptHook();
|
runInterceptHook();
|
||||||
OfferAvailabilityResponse offerAvailabilityResponse = model.getMessage();
|
OfferAvailabilityResponse offerAvailabilityResponse = model.getMessage();
|
||||||
|
|
||||||
if (model.getOffer().getState() != Offer.State.REMOVED) {
|
if (offer.getState() != Offer.State.REMOVED) {
|
||||||
if (offerAvailabilityResponse.getAvailabilityResult() == AvailabilityResult.AVAILABLE) {
|
if (offerAvailabilityResponse.getAvailabilityResult() == AvailabilityResult.AVAILABLE) {
|
||||||
model.getOffer().setState(Offer.State.AVAILABLE);
|
offer.setState(Offer.State.AVAILABLE);
|
||||||
if (ArbitratorSelection.isNewRuleActivated()) {
|
if (ArbitratorSelection.isNewRuleActivated()) {
|
||||||
NodeAddress selectedArbitrator = offerAvailabilityResponse.getArbitrator();
|
NodeAddress selectedArbitrator = offerAvailabilityResponse.getArbitrator();
|
||||||
if (selectedArbitrator == null)
|
if (selectedArbitrator == null) {
|
||||||
failed("You cannot take that offer because the offer maker is running an incompatible version.");
|
log.debug("Maker is on old version and does not send the selected arbitrator in the offerAvailabilityResponse. " +
|
||||||
else
|
"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);
|
model.setSelectedArbitrator(selectedArbitrator);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
model.getOffer().setState(Offer.State.NOT_AVAILABLE);
|
offer.setState(Offer.State.NOT_AVAILABLE);
|
||||||
failed("Take offer attempt rejected because of: " + offerAvailabilityResponse.getAvailabilityResult());
|
failed("Take offer attempt rejected because of: " + offerAvailabilityResponse.getAvailabilityResult());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
complete();
|
complete();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
model.getOffer().setErrorMessage("An error occurred.\n" +
|
offer.setErrorMessage("An error occurred.\n" +
|
||||||
"Error message:\n"
|
"Error message:\n"
|
||||||
+ t.getMessage());
|
+ t.getMessage());
|
||||||
|
|
||||||
|
@ -473,7 +473,8 @@ public class TradeManager implements PersistedDataHost {
|
|||||||
return new OfferAvailabilityModel(
|
return new OfferAvailabilityModel(
|
||||||
offer,
|
offer,
|
||||||
keyRing.getPubKeyRing(),
|
keyRing.getPubKeyRing(),
|
||||||
p2PService);
|
p2PService,
|
||||||
|
user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,8 +35,11 @@ import bisq.core.locale.Res;
|
|||||||
import bisq.core.locale.TradeCurrency;
|
import bisq.core.locale.TradeCurrency;
|
||||||
import bisq.core.offer.Offer;
|
import bisq.core.offer.Offer;
|
||||||
import bisq.core.offer.OfferPayload;
|
import bisq.core.offer.OfferPayload;
|
||||||
|
import bisq.core.offer.availability.ArbitratorSelection;
|
||||||
import bisq.core.user.Preferences;
|
import bisq.core.user.Preferences;
|
||||||
|
|
||||||
|
import bisq.network.p2p.NodeAddress;
|
||||||
|
|
||||||
import javafx.scene.control.Tab;
|
import javafx.scene.control.Tab;
|
||||||
import javafx.scene.control.TabPane;
|
import javafx.scene.control.TabPane;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
@ -164,7 +167,8 @@ public abstract class OfferView extends ActivatableView<TabPane, Void> {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreateOffer(TradeCurrency tradeCurrency) {
|
public void onCreateOffer(TradeCurrency tradeCurrency) {
|
||||||
if (!createOfferViewOpen) {
|
if (!createOfferViewOpen) {
|
||||||
if (!arbitratorManager.isArbitratorAvailableForLanguage(preferences.getUserLanguage())) {
|
boolean arbitratorAvailableForLanguage = arbitratorManager.isArbitratorAvailableForLanguage(preferences.getUserLanguage());
|
||||||
|
if (!arbitratorAvailableForLanguage) {
|
||||||
showNoArbitratorForUserLocaleWarning();
|
showNoArbitratorForUserLocaleWarning();
|
||||||
}
|
}
|
||||||
openCreateOffer(tradeCurrency);
|
openCreateOffer(tradeCurrency);
|
||||||
@ -177,11 +181,28 @@ public abstract class OfferView extends ActivatableView<TabPane, Void> {
|
|||||||
@Override
|
@Override
|
||||||
public void onTakeOffer(Offer offer) {
|
public void onTakeOffer(Offer offer) {
|
||||||
if (!takeOfferViewOpen) {
|
if (!takeOfferViewOpen) {
|
||||||
if (!arbitratorManager.getArbitratorLanguages(offer.getArbitratorNodeAddresses()).stream()
|
if (ArbitratorSelection.isNewRuleActivated()) {
|
||||||
.anyMatch(languages -> languages.equals(preferences.getUserLanguage()))) {
|
openTakeOffer(offer);
|
||||||
showNoArbitratorForUserLocaleWarning();
|
} 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 {
|
} else {
|
||||||
log.error("You have already a \"Take offer\" tab open.");
|
log.error("You have already a \"Take offer\" tab open.");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user