Skip to content

Commit

Permalink
Merge pull request #7012 from jmacxx/api_get_dao_status
Browse files Browse the repository at this point in the history
Add API call to get DAO status
  • Loading branch information
alejandrogarcia83 authored Feb 25, 2024
2 parents 29c4999 + 0eb50d4 commit c86d965
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 6 deletions.
10 changes: 10 additions & 0 deletions cli/src/main/java/bisq/cli/CliMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ public static void run(String[] args) {
out.println(network);
return;
}
case getdaostatus: {
if (new SimpleMethodOptionParser(args).parse().isForHelp()) {
out.println(client.getMethodHelp(method));
return;
}
out.println(client.getDaoStatus());
return;
}
case getbalance: {
var opts = new GetBalanceOptionParser(args).parse();
if (opts.isForHelp()) {
Expand Down Expand Up @@ -866,6 +874,8 @@ private static void printHelp(OptionParser parser, @SuppressWarnings("SameParame
stream.println();
stream.format(rowFormat, getnetwork.name(), "", "Get BTC network: mainnet, testnet3, or regtest");
stream.println();
stream.format(rowFormat, getdaostatus.name(), "", "Get DAO synchronized status: true or false");
stream.println();
stream.format(rowFormat, getbalance.name(), "[--currency-code=<bsq|btc>]", "Get server wallet balances");
stream.println();
stream.format(rowFormat, getaddressbalance.name(), "--address=<btc-address>", "Get server wallet address balance");
Expand Down
4 changes: 4 additions & 0 deletions cli/src/main/java/bisq/cli/GrpcClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public String getNetwork() {
return walletsServiceRequest.getNetwork();
}

public boolean getDaoStatus() {
return walletsServiceRequest.getDaoStatus();
}

public BalancesInfo getBalances() {
return walletsServiceRequest.getBalances();
}
Expand Down
3 changes: 2 additions & 1 deletion cli/src/main/java/bisq/cli/Method.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@ public enum Method {
unlockwallet,
unsettxfeerate,
withdrawfunds,
stop
stop,
getdaostatus
}
6 changes: 6 additions & 0 deletions cli/src/main/java/bisq/cli/request/WalletsServiceRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import bisq.proto.grpc.BtcBalanceInfo;
import bisq.proto.grpc.GetAddressBalanceRequest;
import bisq.proto.grpc.GetBalancesRequest;
import bisq.proto.grpc.GetDaoStatusRequest;
import bisq.proto.grpc.GetFundingAddressesRequest;
import bisq.proto.grpc.GetNetworkRequest;
import bisq.proto.grpc.GetTransactionRequest;
Expand Down Expand Up @@ -61,6 +62,11 @@ public String getNetwork() {
return grpcStubs.walletsService.getNetwork(request).getNetwork();
}

public boolean getDaoStatus() {
var request = GetDaoStatusRequest.newBuilder().build();
return grpcStubs.walletsService.getDaoStatus(request).getIsDaoStateReadyAndInSync();
}

public BalancesInfo getBalances() {
return getBalances("");
}
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/bisq/core/api/CoreApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ public String getNetworkName() {
return walletsService.getNetworkName();
}

public boolean isDaoStateReadyAndInSync() {
return walletsService.isDaoStateReadyAndInSync();
}

public BalancesInfo getBalances(String currencyCode) {
return walletsService.getBalances(currencyCode);
}
Expand Down
13 changes: 8 additions & 5 deletions core/src/main/java/bisq/core/api/CoreWalletsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.btc.wallet.TxBroadcaster;
import bisq.core.btc.wallet.WalletsManager;
import bisq.core.dao.DaoFacade;
import bisq.core.provider.fee.FeeService;
import bisq.core.user.Preferences;
import bisq.core.util.FormattingUtils;
Expand All @@ -48,7 +49,6 @@

import bisq.common.Timer;
import bisq.common.UserThread;
import bisq.common.handlers.ResultHandler;
import bisq.common.util.SingleThreadExecutorUtils;

import org.bitcoinj.core.Address;
Expand All @@ -68,10 +68,7 @@
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;

import org.bouncycastle.crypto.params.KeyParameter;

Expand All @@ -81,7 +78,6 @@
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -109,6 +105,7 @@ class CoreWalletsService {
private final BtcWalletService btcWalletService;
private final CoinFormatter btcFormatter;
private final FeeService feeService;
private final DaoFacade daoFacade;
private final Preferences preferences;

@Nullable
Expand All @@ -130,6 +127,7 @@ public CoreWalletsService(AppStartupState appStartupState,
BtcWalletService btcWalletService,
@Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter btcFormatter,
FeeService feeService,
DaoFacade daoFacade,
Preferences preferences) {
this.appStartupState = appStartupState;
this.coreContext = coreContext;
Expand All @@ -141,6 +139,7 @@ public CoreWalletsService(AppStartupState appStartupState,
this.btcWalletService = btcWalletService;
this.btcFormatter = btcFormatter;
this.feeService = feeService;
this.daoFacade = daoFacade;
this.preferences = preferences;
}

Expand All @@ -166,6 +165,10 @@ String getNetworkName() {
}
}

boolean isDaoStateReadyAndInSync() {
return daoFacade.isDaoStateReadyAndInSync();
}

BalancesInfo getBalances(String currencyCode) {
verifyWalletCurrencyCodeIsValid(currencyCode);
verifyWalletsAreAvailable();
Expand Down
23 changes: 23 additions & 0 deletions core/src/main/resources/help/getdaostatus-help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
getdaostatus

NAME
----
getdaostatus - get DAO status

SYNOPSIS
--------
getdaostatus

DESCRIPTION
-----------
Returns the operating status of the Bisq DAO:
true - DAO is ready and in sync
false - DAO is not ready

At startup the status will return false until the DAO has completed synchronizing.
Trading operations should not be performed when the status is false.
While running, the status can be used to determine if DAO is in sync with the seed nodes.

EXAMPLES
--------
$ ./bisq-cli --password=xyz --port=9998 getdaostatus
16 changes: 16 additions & 0 deletions daemon/src/main/java/bisq/daemon/grpc/GrpcWalletsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import bisq.proto.grpc.GetFundingAddressesRequest;
import bisq.proto.grpc.GetNetworkReply;
import bisq.proto.grpc.GetNetworkRequest;
import bisq.proto.grpc.GetDaoStatusReply;
import bisq.proto.grpc.GetDaoStatusRequest;
import bisq.proto.grpc.GetTransactionReply;
import bisq.proto.grpc.GetTransactionRequest;
import bisq.proto.grpc.GetTransactionsReply;
Expand Down Expand Up @@ -114,6 +116,19 @@ public void getNetwork(GetNetworkRequest req, StreamObserver<GetNetworkReply> re
}
}

@Override
public void getDaoStatus(GetDaoStatusRequest req, StreamObserver<GetDaoStatusReply> responseObserver) {
try {
var reply = GetDaoStatusReply.newBuilder()
.setIsDaoStateReadyAndInSync(coreApi.isDaoStateReadyAndInSync())
.build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
} catch (Throwable cause) {
exceptionHandler.handleException(log, cause, responseObserver);
}
}

@Override
public void getBalances(GetBalancesRequest req, StreamObserver<GetBalancesReply> responseObserver) {
try {
Expand Down Expand Up @@ -403,6 +418,7 @@ final Optional<ServerInterceptor> rateMeteringInterceptor() {
.or(() -> Optional.of(CallRateMeteringInterceptor.valueOf(
new HashMap<>() {{
put(getGetNetworkMethod().getFullMethodName(), new GrpcCallRateMeter(1, SECONDS));
put(getGetDaoStatusMethod().getFullMethodName(), new GrpcCallRateMeter(1, SECONDS));
put(getGetBalancesMethod().getFullMethodName(), new GrpcCallRateMeter(1, SECONDS));
put(getGetAddressBalanceMethod().getFullMethodName(), new GrpcCallRateMeter(1, SECONDS));
put(getGetFundingAddressesMethod().getFullMethodName(), new GrpcCallRateMeter(1, SECONDS));
Expand Down
10 changes: 10 additions & 0 deletions proto/src/main/proto/grpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,9 @@ service Wallets {
// Get the name of the BTC / BSQ network (mainnet, testnet3, or regtest).
rpc GetNetwork (GetNetworkRequest) returns (GetNetworkReply) {
}
// Get status of the DAO.
rpc GetDaoStatus (GetDaoStatusRequest) returns (GetDaoStatusReply) {
}
// Get the Bisq wallet's current BSQ and BTC balances.
rpc GetBalances (GetBalancesRequest) returns (GetBalancesReply) {
}
Expand Down Expand Up @@ -795,6 +798,13 @@ message GetNetworkReply {
string network = 1; // The BTC network name (mainnet, testnet3, or regtest).
}

message GetDaoStatusRequest {
}

message GetDaoStatusReply {
bool is_dao_state_ready_and_in_sync = 1;
}

message GetBalancesRequest {
string currency_code = 1; // The Bisq wallet currency (BSQ or BTC) for the balances request.
}
Expand Down

0 comments on commit c86d965

Please sign in to comment.