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

[DRAFT] Create new getstatus API method #4502

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 11 additions & 10 deletions core/src/main/java/bisq/core/api/CoreApi.java
Expand Up @@ -50,18 +50,21 @@ public class CoreApi {
private final CoreDisputeAgentsService coreDisputeAgentsService;
private final CoreOffersService coreOffersService;
private final CorePaymentAccountsService paymentAccountsService;
private final CorePingService corePingService;
private final CoreWalletsService walletsService;
private final TradeStatisticsManager tradeStatisticsManager;

@Inject
public CoreApi(CoreDisputeAgentsService coreDisputeAgentsService,
CoreOffersService coreOffersService,
CorePaymentAccountsService paymentAccountsService,
CorePingService corePingService,
CoreWalletsService walletsService,
TradeStatisticsManager tradeStatisticsManager) {
this.coreDisputeAgentsService = coreDisputeAgentsService;
this.coreOffersService = coreOffersService;
this.paymentAccountsService = paymentAccountsService;
this.corePingService = corePingService;
this.walletsService = walletsService;
this.tradeStatisticsManager = tradeStatisticsManager;
}
Expand All @@ -79,6 +82,14 @@ public void registerDisputeAgent(String disputeAgentType, String registrationKey
coreDisputeAgentsService.registerDisputeAgent(disputeAgentType, registrationKey);
}

///////////////////////////////////////////////////////////////////////////////////////////
// Ping
///////////////////////////////////////////////////////////////////////////////////////////

public int ping() {
return corePingService.ping();
}

///////////////////////////////////////////////////////////////////////////////////////////
// Offers
///////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -190,14 +201,4 @@ public List<TradeStatistics2> getTradeStatistics() {
public int getNumConfirmationsForMostRecentTransaction(String addressString) {
return walletsService.getNumConfirmationsForMostRecentTransaction(addressString);
}

@SuppressWarnings("SameReturnValue")
public int ping() {
// Many operations require an available, non-null wallet balance, and it is
// assumed the service is ready to accept any request if the wallet balance is
// available. If the balance is not available for any reason, an
// IllegalStateException will be thrown by the wallets service.
walletsService.getAvailableBalance();
return 1;
}
}
63 changes: 63 additions & 0 deletions core/src/main/java/bisq/core/api/CorePingService.java
@@ -0,0 +1,63 @@
package bisq.core.api;

import bisq.core.btc.Balances;
import bisq.core.btc.wallet.WalletsManager;
import bisq.core.dao.node.BsqNode;
import bisq.core.dao.node.BsqNodeProvider;
import bisq.core.dao.state.DaoStateService;

import bisq.network.p2p.P2PService;

import javax.inject.Inject;

import lombok.extern.slf4j.Slf4j;

@Slf4j
class CorePingService {

private final BsqNode bsqNode;
private final DaoStateService daoStateService;
private final P2PService p2PService;
private final WalletsManager walletsManager;
private final Balances balances;

@Inject
public CorePingService(BsqNodeProvider bsqNodeProvider,
DaoStateService daoStateService,
P2PService p2PService,
WalletsManager walletsManager,
Balances balances) {
this.bsqNode = bsqNodeProvider.getBsqNode();
this.p2PService = p2PService;
this.daoStateService = daoStateService;
this.walletsManager = walletsManager;
this.balances = balances;
}

@SuppressWarnings("SameReturnValue")
public int ping() {
// A successful ping informs the client and other API methods that the server is
// ready to perform complex functions beyond accepting gRPC calls. If the checks
// below pass, return a pong (1), else an exception with a message explaining the
// failure.
if (!bsqNode.isP2pNetworkReady())
throw new IllegalStateException("p2p network is not yet ready");

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

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

if (p2PService.getNumConnectedPeers().get() < 4)
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");

return 1;
}
}
5 changes: 4 additions & 1 deletion core/src/main/java/bisq/core/dao/node/BsqNode.java
Expand Up @@ -147,6 +147,10 @@ public void addListeners() {
// API
///////////////////////////////////////////////////////////////////////////////////////////

public boolean isP2pNetworkReady() {
return this.p2pNetworkReady;
}

public void setErrorMessageHandler(@SuppressWarnings("NullableProblems") Consumer<String> errorMessageHandler) {
this.errorMessageHandler = errorMessageHandler;
}
Expand All @@ -159,7 +163,6 @@ public void shutDown() {
exportJsonFilesService.shutDown();
}


///////////////////////////////////////////////////////////////////////////////////////////
// Protected
///////////////////////////////////////////////////////////////////////////////////////////
Expand Down