Skip to content

Commit

Permalink
Merge pull request #4479 from chimp1984/improve-xmr-proof-p2pNetworkA…
Browse files Browse the repository at this point in the history
…ndWalletReady-handling

Improve handling of p2pNetworkAndWalletReady
  • Loading branch information
sqrrm authored Sep 6, 2020
2 parents 7389bf8 + 6162e6d commit d152f88
Showing 1 changed file with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public class XmrTxProofService implements AssetTxProofService {
private Map<String, ChangeListener<Trade.State>> tradeStateListenerMap = new HashMap<>();
private ChangeListener<Number> btcPeersListener, btcBlockListener;
private BootstrapListener bootstrapListener;
private MonadicBinding<Boolean> p2pNetworkAndWalletReady;
private ChangeListener<Boolean> p2pNetworkAndWalletReadyListener;


///////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -122,18 +124,26 @@ public void onAllServicesInitialized() {
// As we might trigger the payout tx we want to be sure that we are well connected to the Bitcoin network.
// onAllServicesInitialized is called once we have received the initial data but we want to have our
// hidden service published and upDatedDataResponse received before we start.
MonadicBinding<Boolean> p2pNetworkAndWalletReady = EasyBind.combine(isP2pBootstrapped(), hasSufficientBtcPeers(), isBtcBlockDownloadComplete(),
(isP2pBootstrapped, hasSufficientBtcPeers, isBtcBlockDownloadComplete) -> {
log.info("isP2pBootstrapped={}, hasSufficientBtcPeers={} isBtcBlockDownloadComplete={}",
isP2pBootstrapped, hasSufficientBtcPeers, isBtcBlockDownloadComplete);
return isP2pBootstrapped && hasSufficientBtcPeers && isBtcBlockDownloadComplete;
});

p2pNetworkAndWalletReady.subscribe((observable, oldValue, newValue) -> {
if (newValue) {
onP2pNetworkAndWalletReady();
}
});
BooleanProperty isP2pBootstrapped = isP2pBootstrapped();
BooleanProperty hasSufficientBtcPeers = hasSufficientBtcPeers();
BooleanProperty isBtcBlockDownloadComplete = isBtcBlockDownloadComplete();
if (isP2pBootstrapped.get() && hasSufficientBtcPeers.get() && isBtcBlockDownloadComplete.get()) {
onP2pNetworkAndWalletReady();
} else {
p2pNetworkAndWalletReady = EasyBind.combine(isP2pBootstrapped, hasSufficientBtcPeers, isBtcBlockDownloadComplete,
(bootstrapped, sufficientPeers, downloadComplete) -> {
log.info("isP2pBootstrapped={}, hasSufficientBtcPeers={} isBtcBlockDownloadComplete={}",
bootstrapped, sufficientPeers, downloadComplete);
return bootstrapped && sufficientPeers && downloadComplete;
});

p2pNetworkAndWalletReadyListener = (observable, oldValue, newValue) -> {
if (newValue) {
onP2pNetworkAndWalletReady();
}
};
p2pNetworkAndWalletReady.subscribe(p2pNetworkAndWalletReadyListener);
}
}

@Override
Expand All @@ -148,6 +158,12 @@ public void shutDown() {
///////////////////////////////////////////////////////////////////////////////////////////

private void onP2pNetworkAndWalletReady() {
if (p2pNetworkAndWalletReady != null) {
p2pNetworkAndWalletReady.removeListener(p2pNetworkAndWalletReadyListener);
p2pNetworkAndWalletReady = null;
p2pNetworkAndWalletReadyListener = null;
}

if (!preferences.findAutoConfirmSettings("XMR").isPresent()) {
log.error("AutoConfirmSettings is not present");
}
Expand Down

0 comments on commit d152f88

Please sign in to comment.