mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 07:07:43 +01:00
Add extra checks to avoid duplicated offers (#1246)
This commit is contained in:
parent
e84cf66f47
commit
c4c4c0662b
1 changed files with 18 additions and 13 deletions
|
@ -54,11 +54,20 @@ public class OfferBook {
|
|||
@Override
|
||||
public void onAdded(Offer offer) {
|
||||
OfferBookListItem offerBookListItem = new OfferBookListItem(offer);
|
||||
if (!isOfferWithIdInList(offer)) {
|
||||
// We don't use the contains method as the equals method in Offer takes state and errorMessage into account.
|
||||
// If we have an offer with same ID we remove it and add the new offer as it might have a changed state.
|
||||
Optional<OfferBookListItem> candidateToRemove = offerBookListItems.stream()
|
||||
.filter(item -> item.getOffer().getId().equals(offer.getId()))
|
||||
.findAny();
|
||||
if (candidateToRemove.isPresent()) {
|
||||
log.info("We had an old offer in the list with the same Offer ID. Might be that the state or errorMessage was different. " +
|
||||
"old offerBookListItem={}, new offerBookListItem={}", candidateToRemove.get(), offerBookListItem);
|
||||
offerBookListItems.remove(candidateToRemove.get());
|
||||
}
|
||||
|
||||
offerBookListItems.add(offerBookListItem);
|
||||
Log.logIfStressTests("OfferPayload added: No. of offers = " + offerBookListItems.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemoved(Offer offer) {
|
||||
|
@ -67,17 +76,15 @@ public class OfferBook {
|
|||
|
||||
// clean up possible references in openOfferManager
|
||||
tradeManager.onOfferRemovedFromRemoteOfferBook(offer);
|
||||
Optional<OfferBookListItem> candidate = offerBookListItems.stream()
|
||||
// We don't use the contains method as the equals method in Offer takes state and errorMessage into account.
|
||||
Optional<OfferBookListItem> candidateToRemove = offerBookListItems.stream()
|
||||
.filter(item -> item.getOffer().getId().equals(offer.getId()))
|
||||
.findAny();
|
||||
if (candidate.isPresent()) {
|
||||
OfferBookListItem item = candidate.get();
|
||||
if (offerBookListItems.contains(item)) {
|
||||
offerBookListItems.remove(item);
|
||||
if (candidateToRemove.isPresent()) {
|
||||
offerBookListItems.remove(candidateToRemove.get());
|
||||
Log.logIfStressTests("OfferPayload removed: No. of offers = " + offerBookListItems.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -91,8 +98,6 @@ public class OfferBook {
|
|||
}
|
||||
|
||||
public void fillOfferBookListItems() {
|
||||
log.debug("fillOfferBookListItems");
|
||||
|
||||
try {
|
||||
// setAll causes sometimes an UnsupportedOperationException
|
||||
// Investigate why....
|
||||
|
|
Loading…
Add table
Reference in a new issue