Skip to content

Commit

Permalink
Merge pull request #5191 from jmacxx/fix_TriggerPriceService_bootstrap
Browse files Browse the repository at this point in the history
Fix startup error: "You must have bootstrapped before adding data to the P2P network"
  • Loading branch information
ripcurlx authored Feb 15, 2021
2 parents 31b7292 + d82a61d commit 43ac2c9
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion core/src/main/java/bisq/core/offer/TriggerPriceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import bisq.core.provider.price.MarketPrice;
import bisq.core.provider.price.PriceFeedService;

import bisq.network.p2p.BootstrapListener;
import bisq.network.p2p.P2PService;

import bisq.common.util.MathUtils;

import org.bitcoinj.utils.Fiat;
Expand All @@ -47,17 +50,34 @@
@Slf4j
@Singleton
public class TriggerPriceService {
private final P2PService p2PService;
private final OpenOfferManager openOfferManager;
private final PriceFeedService priceFeedService;
private final Map<String, Set<OpenOffer>> openOffersByCurrency = new HashMap<>();

@Inject
public TriggerPriceService(OpenOfferManager openOfferManager, PriceFeedService priceFeedService) {
public TriggerPriceService(P2PService p2PService,
OpenOfferManager openOfferManager,
PriceFeedService priceFeedService) {
this.p2PService = p2PService;
this.openOfferManager = openOfferManager;
this.priceFeedService = priceFeedService;
}

public void onAllServicesInitialized() {
if (p2PService.isBootstrapped()) {
onBootstrapComplete();
} else {
p2PService.addP2PServiceListener(new BootstrapListener() {
@Override
public void onUpdatedDataReceived() {
onBootstrapComplete();
}
});
}
}

private void onBootstrapComplete() {
openOfferManager.getObservableList().addListener((ListChangeListener<OpenOffer>) c -> {
c.next();
if (c.wasAdded()) {
Expand Down

0 comments on commit 43ac2c9

Please sign in to comment.