Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give core api a simple way to verify init status #4534

Merged
merged 1 commit into from
Sep 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 60 additions & 0 deletions core/src/main/java/bisq/core/api/StatusCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package bisq.core.api;

import bisq.core.btc.Balances;
import bisq.core.btc.setup.WalletsSetup;
import bisq.core.btc.wallet.WalletsManager;
import bisq.core.dao.state.DaoStateService;

import bisq.network.p2p.P2PService;

import bisq.common.config.Config;

import javax.inject.Inject;
import javax.inject.Singleton;

import lombok.extern.slf4j.Slf4j;

@Singleton
@Slf4j
class StatusCheck {

private final Config config;
private final P2PService p2PService;
private final DaoStateService daoStateService;
private final WalletsSetup walletsSetup;
private final WalletsManager walletsManager;
private final Balances balances;

@Inject
public StatusCheck(Config config,
P2PService p2PService,
DaoStateService daoStateService,
WalletsSetup walletsSetup,
WalletsManager walletsManager,
Balances balances) {
this.config = config;
this.p2PService = p2PService;
this.daoStateService = daoStateService;
this.walletsSetup = walletsSetup;
this.walletsManager = walletsManager;
this.balances = balances;
}

public void verifyCanTrade() {
if (!p2PService.isBootstrapped())
throw new IllegalStateException("p2p service is not yet bootstrapped");

if (!daoStateService.isParseBlockChainComplete())
throw new IllegalStateException("dao block chain sync is not yet complete");

if (config.baseCurrencyNetwork.isMainnet()
&& p2PService.getNumConnectedPeers().get() < walletsSetup.getMinBroadcastConnections())
throw new IllegalStateException("not enough connected peers");

if (!walletsManager.areWalletsAvailable())
throw new IllegalStateException("wallet is not yet available");

if (balances.getAvailableBalance().get() == null)
throw new IllegalStateException("balance is not yet available");
}
}